Frictional Games Forum (read-only)

Full Version: Transferring Items from Different Maps
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, I don't really understand how to transfer items to other scripts or maps. Can someone explain how I could do this? Huh
If you pick something in one map, it will automatically transfer to another map in your inventory.
No like, what I want to do is have the item from a different map (say it was a key.) Make it able to unlock a door from the map you're in. Pretty much using an item from a different map to make it do something (anything) on another.
I think you're confused, or I am.

A key is an item, items can be carried around through whichever maps and used for whichever thing you want it to be used for. There's nothing complicated to it. Worse case, you can just use a global variable to check if the player has the item or not. I don't really know what you are trying to get out of this, but I'm sure it was answered before.
Lol, I think I'm confused. I'm still a beginner at scripting. I wanted to know how I could make it so that if I use a key from a different map, it'll be able to unlock a door from another map.
You find a key in a map, for the sake of examples. The key's name is "Key01" and the map's name is "Map01". The map where you use the key will be called "Map02". So the player picks up the item "Key01" in "Map01", and then goes to "Map02" where the locked door is. Let's call this locked door, "LockedDoor01". Then you add an AddUseItemCallback command function followed by another function that unlocks the door with that key. It's quite simple, no crazy stuff involved. Smile

Code:
void OnStart()
{
     AddUseItemCallback("", "Key01", "LockedDoor01", "Func01", false);
}
void Func01(string &in asItem, string &in asEntity)
{
     SetSwingDoorLocked(asEntity, false, true);
     PlaySoundAtEntity("", "unlock_door.snt", asEntity, 0, false);
     RemoveItem(asItem);
}

But if it doesn't work, then it'll require some more scripting that involves global variables to check if the player picks up the key so then the item can properly be removed when leaving the level, and then recieving a new one once they enter another level. Tongue
if it doesn't work, how will I be able to do it then? I'm still confused about global variables and how it works, so I really don't know how I should start if it doesn't work out.
(08-14-2011, 09:07 PM)TimmayIsHawt Wrote: [ -> ]if it doesn't work, how will I be able to do it then? I'm still confused about global variables and how it works, so I really don't know how I should start if it doesn't work out.

A global variable can be used across your whole custom story. There is a file called "global.hps" which is a file that is created in your custom story's "maps" folder or where you put all your scripts and maps for your custom story. In that file that you make, that's called "global.hps", you can setup global variables that can check something throught your maps. In this case it will be "Key01", for the sake of examples. This is what the "global.hps" file will look like when including a global variable called, "KeyCheck01":

Code:
void OnGameStart()
{
     SetGlobalVarInt("KeyCheck01", 0);
}

So now, corresponding to the example I previously posted, in "Map01.hps" you could add this in your script:

Code:
void OnStart()
{
     SetEntityPlayerInteractCallback("Key01", "Func01", true);
}
void Func01(string &in asEntity)
{
     SetGlobalVariableInt("KeyCheck01", 1);
}
void OnEnter()
{
     if (GetGlobalVarInt("KeyCheck01") == 1)
     {
          GiveItem(string& asName, string& asType, string& asSubTypeName, string& asImageName, float afAmount);
     }
}
void OnLeave()
{
     if (GeGlobalVarInt("KeyCheck01") == 1)
     {
          RemoveItem("Key01");
     }
}

Then in the script file called "Map02.hps", have this:

Code:
void OnEnter()
{
     if (GetGlobalVarInt("KeyCheck01") == 1)
     {
          GiveItem(string& asName, string& asType, string& asSubTypeName, string& asImageName, float afAmount);
     }
}
void OnLeave()
{
     if (GeGlobalVarInt("KeyCheck01") == 1)
     {
          RemoveItem("Key01");
     }
}

Then still in the "Map02.hps" script file, you'll have to add this line of code into the function where the key gets used and removed when it unlocks the door:

Code:
SetGlobalVarInt("KeyCheck01", 0);


Where I had this, I don't know exactly what the key is, so I just copy and pasted it out of the wiki, which does require for you to fill it out with the correct information about the key.

GiveItem(string& asName, string& asType, string& asSubTypeName, string& asImageName, float afAmount);

I hope this helps! Smile
Do you mean use the key on an entity (object) in one map, then it unlocks a door on a different map, so you wont be carrying the key to that door?
Okay, thanks guys! It worked! Smile