Shadowfied
Senior Member
Posts: 261
Threads: 34
Joined: Jul 2010
Reputation:
5
|
One script for multiple similar functions
In my custom story there's a place where you get a key which can, or will be able to open a lot of doors. I know there are ways to make a script like this one from White Night, used for the light switches:
void Lamp_Switcher(string &in asEntity, int alState)
{
if( alState == -1)
SetLampLit("swithcher_1_"+StringSub(asEntity,10,11), false, true);
if( alState == 1)
SetLampLit("swithcher_1_"+StringSub(asEntity,10,11), true, true);
}
I have about 10 doors called "cell_1" and up, can I somehow make a similar script so that I don't have to make individual parts of script for each door?
Thanks in advance.
|
|
02-13-2012, 09:40 AM |
|
flamez3
Posting Freak
Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation:
57
|
RE: One script for multiple similar functions
AsEntity and asItem are how to do it.
Example:
void OnStart()
{
AddUseItemCallback("", "key_tomb_1", "prison_1", "door1", true);
AddUseItemCallback("", "key_tomb_2", "prison_2", "door1", true);
AddUseItemCallback("", "key_tomb_3", "prison_3", "door1", true);
AddUseItemCallback("", "key_tomb_4", "prison_4", "door1", true);
}
void door1(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0.0f, false);
RemoveItem(asItem);
}
|
|
02-13-2012, 09:45 AM |
|
Shadowfied
Senior Member
Posts: 261
Threads: 34
Joined: Jul 2010
Reputation:
5
|
RE: One script for multiple similar functions
(02-13-2012, 09:45 AM)flamez3 Wrote: AsEntity and asItem are how to do it.
Example:
void OnStart()
{
AddUseItemCallback("", "key_tomb_1", "prison_1", "door1", true);
AddUseItemCallback("", "key_tomb_2", "prison_2", "door1", true);
AddUseItemCallback("", "key_tomb_3", "prison_3", "door1", true);
AddUseItemCallback("", "key_tomb_4", "prison_4", "door1", true);
}
void door1(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0.0f, false);
RemoveItem(asItem);
} Ah! Thanks! Flamez to the rescue once again ;]
|
|
02-13-2012, 09:47 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: One script for multiple similar functions
flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity.
|
|
02-13-2012, 08:49 PM |
|
flamez3
Posting Freak
Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation:
57
|
RE: One script for multiple similar functions
(02-13-2012, 08:49 PM)Your Computer Wrote: flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity.
|
|
02-14-2012, 03:01 AM |
|
Shadowfied
Senior Member
Posts: 261
Threads: 34
Joined: Jul 2010
Reputation:
5
|
RE: One script for multiple similar functions
(02-13-2012, 08:49 PM)Your Computer Wrote: flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity. Yeah I noticed. Thanks though.
|
|
02-14-2012, 11:03 AM |
|
Ninami
Member
Posts: 59
Threads: 6
Joined: Feb 2012
Reputation:
2
|
RE: One script for multiple similar functions
Would be nice if people could put "SOLVED" in the title when it's solved
|
|
02-15-2012, 06:11 AM |
|
|