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



2 keys script - Kainzor - 12-06-2011

hey im havin some problem with doin 2 keys script i know im doin somthing wrong but this is the first key script that worked fine
---------

void OnStart()
{
AddUseItemCallback("", "bedroomkey_1", "mansion_1", "UsedKeyOnDoor", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("bedroomkey_1");
------
but where do i put the 2nd key script and how do i script it..... any info can help me
thank you for reading this


RE: 2 keys script - flamez3 - 12-06-2011

Im assuming that you want 2 keys to make a door unlocked? If so:

PHP Code:
void OnStart()
{
    
SetLocalVarInt("Var1"0);
    
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor1"true);
    
AddUseItemCallback("""bedroomkey_2""mansion_1""UsedKeyOnDoor2"true);
}

void UsedKeyOnDoor1(string &in asItemstring &in asEntity)
{
RemoveItem("bedroomkey_1");
AddLocalVarInt("Var1"1);void func_on();}
[
align=-webkit-auto]void UsedKeyOnDoor2(string &in asItemstring &in asEntity)
{
RemoveItem("bedroomkey_1");

AddLocalVarInt("Var1"1);
void func_on();
}


void func_on()
{
if(
GetLocalVarInt("Var1") == 2)
{
SetSwingDoorLocked("mansion_1"falsetrue);
PlaySoundAtEntity("""unlock_door""mansion_1"0false);

}



If you need me to explain what that script is and why it works just ask ^^


RE: 2 keys script - Kainzor - 12-06-2011

no i mean....not same door.... how do you script with 1 key ea door by havin 2 keys like.... i got mansion_1 and mansion_2, i got key_1 and key_2, i know how to script the first key but there's always and error whn i do the 2nd 1 ..... i know my scripting must be wrong but i cant find it.... so i deleted it and tried have help on this website


RE: 2 keys script - flamez3 - 12-06-2011

(12-06-2011, 04:33 PM)Kainzor Wrote: no i mean....not same door.... how do you script with 1 key ea door by havin 2 keys like.... i got mansion_1 and mansion_2, i got key_1 and key_2, i know how to script the first key but there's always and error whn i do the 2nd 1 ..... i know my scripting must be wrong but i cant find it.... so i deleted it and tried have help on this website
Okay do this:

PHP Code:
void OnStart()
{
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor1"true);
AddUseItemCallback("""bedroomkey_2""mansion_2""UsedKeyOnDoor2"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
SetSwingDoorLocked("mansion_1"falsetrue);
PlaySoundAtEntity("""unlock_door""mansion_1"0false);
RemoveItem("bedroomkey_1");
}

void UsedKeyOnDoor2(string &in asItemstring &in asEntity)
{
SetSwingDoorLocked("mansion_2"falsetrue);
PlaySoundAtEntity("""unlock_door""mansion_1"0false);
RemoveItem("bedroomkey_2");



Also rename the doors and keys to the right names. And you can always post your script int the forums to get some insight on how to correct the problem. :3


RE: 2 keys script - Kainzor - 12-06-2011

alright

that worked thanks alot Big Grin



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

It'd be more efficient if you had one function deal with all swing doors:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor"true);
    
AddUseItemCallback("""bedroomkey_2""mansion_2""UsedKeyOnDoor"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);




RE: 2 keys script - flamez3 - 12-06-2011

(12-06-2011, 05:24 PM)Your Computer Wrote: It'd be more efficient if you had one function deal with all swing doors:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor"true);
    
AddUseItemCallback("""bedroomkey_2""mansion_2""UsedKeyOnDoor"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);

Wow, didn't know about that, thanks.


RE: 2 keys script - Dobbydoo - 12-07-2011

(12-06-2011, 05:24 PM)Your Computer Wrote: It'd be more efficient if you had one function deal with all swing doors:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor"true);
    
AddUseItemCallback("""bedroomkey_2""mansion_2""UsedKeyOnDoor"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);

But wouldn't that just make both doors unlock when using one key? :S




RE: 2 keys script - flamez3 - 12-07-2011

(12-07-2011, 03:23 PM)Dobbydoo Wrote:
(12-06-2011, 05:24 PM)Your Computer Wrote: It'd be more efficient if you had one function deal with all swing doors:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor"true);
    
AddUseItemCallback("""bedroomkey_2""mansion_2""UsedKeyOnDoor"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);

But wouldn't that just make both doors unlock when using one key? :S
The asEntity makes it so whichever entity it's linked in the void OnStart block will be the one being unlocked.


RE: 2 keys script - Dobbydoo - 12-07-2011

(12-07-2011, 03:25 PM)flamez3 Wrote:
(12-07-2011, 03:23 PM)Dobbydoo Wrote:
(12-06-2011, 05:24 PM)Your Computer Wrote: It'd be more efficient if you had one function deal with all swing doors:

PHP Code:
void OnStart()
{
    
AddUseItemCallback("""bedroomkey_1""mansion_1""UsedKeyOnDoor"true);
    
AddUseItemCallback("""bedroomkey_2""mansion_2""UsedKeyOnDoor"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
    
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);

But wouldn't that just make both doors unlock when using one key? :S
The asEntity makes it so whichever entity it's linked in the void OnStart block will be the one being unlocked.
Oh, of course! Stupid me *facepalm*