Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help One script for multiple similar functions
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#1
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.

Current - Castle Darkuan
Other - F*cked Map
02-13-2012, 09:40 AM
Find
flamez3 Offline
Posting Freak

Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation: 57
#2
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
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#3
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 ;]



Current - Castle Darkuan
Other - F*cked Map
02-13-2012, 09:47 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: One script for multiple similar functions

flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity.

Tutorials: From Noob to Pro
02-13-2012, 08:49 PM
Website Find
flamez3 Offline
Posting Freak

Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation: 57
#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.
Tongue

02-14-2012, 03:01 AM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#6
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.



Current - Castle Darkuan
Other - F*cked Map
02-14-2012, 11:03 AM
Find
Ninami Offline
Member

Posts: 59
Threads: 6
Joined: Feb 2012
Reputation: 2
#7
RE: One script for multiple similar functions

Would be nice if people could put "SOLVED" in the title when it's solved Tongue
02-15-2012, 06:11 AM
Find




Users browsing this thread: 1 Guest(s)