Frictional Games Forum (read-only)
Transferring Items from Different Maps - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Transferring Items from Different Maps (/thread-9741.html)



Transferring Items from Different Maps - TimmayIsHawt - 08-13-2011

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


RE: Transferring Items from Different Maps - Tanshaydar - 08-14-2011

If you pick something in one map, it will automatically transfer to another map in your inventory.


RE: Transferring Items from Different Maps - TimmayIsHawt - 08-14-2011

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.


RE: Transferring Items from Different Maps - Kyle - 08-14-2011

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.


RE: Transferring Items from Different Maps - TimmayIsHawt - 08-14-2011

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.


RE: Transferring Items from Different Maps - Kyle - 08-14-2011

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


RE: Transferring Items from Different Maps - TimmayIsHawt - 08-14-2011

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.


RE: Transferring Items from Different Maps - Kyle - 08-14-2011

(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


RE: Transferring Items from Different Maps - Nathannnnr93 - 08-14-2011

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?


RE: Transferring Items from Different Maps - TimmayIsHawt - 08-15-2011

Okay, thanks guys! It worked! Smile