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 Repeating Functions SOLVED
hunchbackproduction Offline
Junior Member

Posts: 36
Threads: 13
Joined: Jul 2013
Reputation: 0
#1
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!
(This post was last modified: 04-15-2014, 10:45 AM by hunchbackproduction.)
04-14-2014, 03:02 PM
Website Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#2
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
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
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:

PHP Code: (Select All)
void OnEnter()
{
    
AddUseItemCallback("""key_study_1""AreaLock""UnlockingDoor"true);
}

void UnlockingDoor(string &in asEntitystring &in asItem)
{
    
SetPlayerRunSpeedMul(0);
    
SetPlayerMoveSpeedMul(0.2);
    
SetPlayerLookSpeedMul(0.3);

    
AddTimer(asEntity "_door"2.0f"Unlocked");
    
SetSwingDoorLocked(asEntity "_door"falsetrue);
}

void Unlocked(string &in asTimer)
{
    
PlaySoundAtEntity("""unlock_door"asTimer0false);
    
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
Find
hunchbackproduction Offline
Junior Member

Posts: 36
Threads: 13
Joined: Jul 2013
Reputation: 0
#4
RE: Repeating Functions

Thanks alot guys Big Grin Makes sense and is working ^ Gonna save me lots of lines

Scripting level is over 9000!
04-15-2014, 10:35 AM
Website Find




Users browsing this thread: 1 Guest(s)