hunchbackproduction
Junior Member
Posts: 36
Threads: 13
Joined: Jul 2013
Reputation:
0
|
Repeating Functions SOLVED
Alright, I have code right now that unlocks the "castle_1" when I use a "key_study_1" on the area "DoorLock_1" (which is on the door handle, to simulate the key going into the lock, not just clicking on the door xD). Is there a way I can modify the code so that I can use this same function anytime I want to open a door on the level in a similar fashion ? As right now it will only unlock "castle_1" ofc.
void UnlockingDoor(string &in key_study_1, string &in DoorLock_1)
{
SetPlayerRunSpeedMul(0);
SetPlayerMoveSpeedMul(0.2);
SetPlayerLookSpeedMul(0.3);
AddTimer("", 2.0f, "Unlocked");
SetSwingDoorLocked("castle_1", false, true);
}
void Unlocked(string &in asTimer)
{
PlaySoundAtEntity("", "unlock_door", "castle_1", 0, false);
SetPlayerRunSpeedMul(1);
SetPlayerMoveSpeedMul(1);
SetPlayerLookSpeedMul(1);
}
void OnEnter()
{
AddUseItemCallback("", "key_study_1", "DoorLock_1", "UnlockingDoor", true);
}
I imagine it is possible if I was using the key directly on the door itself, but I want to know is it possible the way I have it setup! Thanks
Scripting level is over 9000!
|
|
04-14-2014, 03:02 PM |
|
Neelke
Senior Member
Posts: 668
Threads: 82
Joined: Apr 2013
Reputation:
26
|
RE: Repeating Functions
Do you mean like this?
void UnlockingDoor(string &in asEntity, string &in asItem)
{
if(asEntity == "castle_1"){
SetPlayerRunSpeedMul(0);
SetPlayerMoveSpeedMul(0.2);
SetPlayerLookSpeedMul(0.3);
AddTimer("", 2.0f, "Unlocked");
SetSwingDoorLocked("castle_1", false, true);
}else if(asEntity == "ANOTHERDOOR"){
//Do this instead
}
}
Changed key_study_1 and DoorLock_1 to asEntity and asItem so this is possible.
Derp.
(This post was last modified: 04-14-2014, 03:30 PM by Neelke.)
|
|
04-14-2014, 03:30 PM |
|
Mudbill
Muderator
Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation:
179
|
RE: Repeating Functions
There are ways of doing such, by simply using the asEntity parameter. Kinda like what Neelke said, but more flexible. Try this:
void OnEnter() { AddUseItemCallback("", "key_study_1", "AreaLock", "UnlockingDoor", true); }
void UnlockingDoor(string &in asEntity, string &in asItem) { SetPlayerRunSpeedMul(0); SetPlayerMoveSpeedMul(0.2); SetPlayerLookSpeedMul(0.3);
AddTimer(asEntity + "_door", 2.0f, "Unlocked"); SetSwingDoorLocked(asEntity + "_door", false, true); }
void Unlocked(string &in asTimer) { PlaySoundAtEntity("", "unlock_door", asTimer, 0, false); SetPlayerRunSpeedMul(1); SetPlayerMoveSpeedMul(1); SetPlayerLookSpeedMul(1); }
As you can see, I edited your callback to be used on an area named AreaLock. You can name it for example AreaLock_1, but the door NEEDS to have the same name but including _door at the end. For for example your area is named AreaLock, the door the area is located on must be named AreaLock_door. This is because the code will use the name of the area but add the _door extension to it, then trigger the script on the matching entity.
(This post was last modified: 04-14-2014, 05:15 PM by Mudbill.)
|
|
04-14-2014, 05:14 PM |
|
hunchbackproduction
Junior Member
Posts: 36
Threads: 13
Joined: Jul 2013
Reputation:
0
|
RE: Repeating Functions
Thanks alot guys Makes sense and is working ^ Gonna save me lots of lines
Scripting level is over 9000!
|
|
04-15-2014, 10:35 AM |
|
|