Frictional Games Forum (read-only)
[SCRIPT] Repeating Functions SOLVED - 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: [SCRIPT] Repeating Functions SOLVED (/thread-25076.html)



Repeating Functions SOLVED - hunchbackproduction - 04-14-2014

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


RE: Repeating Functions - Neelke - 04-14-2014

Do you mean like this?

Code:
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.


RE: Repeating Functions - Mudbill - 04-14-2014

There are ways of doing such, by simply using the asEntity parameter. Kinda like what Neelke said, but more flexible. Try this:

PHP Code:
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.


RE: Repeating Functions - hunchbackproduction - 04-15-2014

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