Frictional Games Forum (read-only)
2 keys - 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: 2 keys (/thread-11796.html)



2 keys - aqfitz622 - 12-12-2011

I have come to the stunning realization that i suck at scripting. i am using two keys here. but one isn't working
the 1st AddUseItemCallback is not working right because it will not unlock the door



void OnStart()

{
AddUseItemCallback("", "doorway", "mansion_4", "FUNCTION", true);
AddUseItemCallback("", "floortwokey", "mansion_9", "UsedKeyOnDoor", true);
}

void FUNCTION(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_4", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_4", 0, false);
RemoveItem("doorkey");
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_9", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_9", 0, false);
RemoveItem("floortwokey");
}


void OnEnter()
{

}

void OnLeave()
{



RE: 2 keys - Statyk - 12-12-2011

Took a bit to realize, but once I re-read your key isn't working on the door, something is up with the AddUseItemCallback:

//___________________
void OnStart()

{
AddUseItemCallback("", "doorway", "mansion_4", "FUNCTION", true);
AddUseItemCallback("", "floortwokey", "mansion_9", "UsedKeyOnDoor", true);
}

void FUNCTION(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_4", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_4", 0, false);
RemoveItem("doorkey");
}

//_________________________

Turns out you have the wrong name of the key in the AddUseItemCallback. I believe it should be "doorkey", NOT "doorway".



RE: 2 keys - aqfitz622 - 12-12-2011

thanks for the help man i appreciate it.


RE: 2 keys - Your Computer - 12-12-2011

It'd be a lot simpler if the parameter variables were used.


RE: 2 keys - Statyk - 12-12-2011

(12-12-2011, 05:33 AM)Your Computer Wrote: It'd be a lot simpler if the parameter variables were used.

What do you mean?



RE: 2 keys - nemesis567 - 12-12-2011

I think what My Computer means is the following:

PHP Code:
void OnStart()
 
 {
 
AddUseItemCallback("""doorway""mansion_4""useItemOnDoor"true);
 
AddUseItemCallback("""floortwokey""mansion_9""UsedKeyOnDoor"true);
 }
 
 
void useItemOnDoor(string &in asItemstring &in asEntity)//and for ffs, start using decent names. Doing otherwise is a bad programming technique.
 
{
 
SetSwingDoorLocked(asEntityfalsetrue);
 
PlaySoundAtEntity("""unlock_door"asEntity0false);
 
RemoveItem(asItem);
 } 



RE: 2 keys - Your Computer - 12-13-2011

(12-12-2011, 10:05 PM)nemesis567 Wrote: I think what My Computer means is the following:

Half way there. Both use-item callbacks should use the same function since they carry the same purpose.

PHP Code:
void OnStart()
 {
 
AddUseItemCallback("""doorway""mansion_4""useItemOnDoor"true);
 
AddUseItemCallback("""floortwokey""mansion_9""useItemOnDoor"true);
 } 



RE: 2 keys - nemesis567 - 12-13-2011

Good point My Computer.

I sometimes find it more efficient to use callbacks. Something like having a specific function for AddUseItemCallback, for example OnItemUsed and then use a switch statement. It's best to keep track of how is it called and when and you can use partial names to compare with a predefined name like door or something like that which allows for quite some more flexibility.



RE: 2 keys - irockpeople1 - 01-01-2012

Im also having this problum. My hps is this
////////////////////////////
// Run first time starting map
void OnStart()
{
AddUseItemCallback("", "key_1", "mansion_1", "KeyOnDoor", true);
AddUseItemCallback("", "key_2", "mansion_2", "Door", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("key_1");
}
void Door(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_2", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_2", 0, false);
RemoveItem("key_2");
}
////////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}
Also when i try to have a custom name all it says for them are "Picked up"
but when I only have one key, it works fine.