Frictional Games Forum (read-only)
Door set to locked, but unlocked? - 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: Door set to locked, but unlocked? (/thread-9533.html)



Door set to locked, but unlocked? - Asaratha - 08-01-2011

Hey, guys!

So, in my custom story I have a door set to "locked" and you must grab a key and you know, use it to unlock it.

Keys name = key_2
Doors name = keydoor_2

Code:
void OnStart()

{
AddUseItemCallback("", "key_1", "keydoor_1", "KeyOnDoor", true);
AddUseItemCallback("", "hidden_key", "hidden_door", "KeyOnHiddenDoor", true);
SetEntityPlayerInteractCallback("key_2", "Spawn_Monster", true);
AddUseItemCallback("", "key_2", "keydoor_2", "KeyOnDoor", true);
AddEntityCollideCallback("Player", "PlayerCollide", "MonsterFunction", true, 1);
}
void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("keydoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "keydoor_1", 0, false);
    RemoveItem("key_1");
    SetSwingDoorLocked("keydoor_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "keydoor_2", 0, false);
    RemoveItem("key_2");
}
void Spawn_Monster(string &in entity)
{
    SetEntityActive("grunt", true);
    AddEnemyPatrolNode("grunt", "PathNodeArea_1", 2, "");
    AddEnemyPatrolNode("grunt", "PathNodeArea_2", 0, "");
    AddEnemyPatrolNode("grunt", "PathNodeArea_3", 4, "");
}

For some reason, the door is always unlocked and I just can't get it to stay locked.

Any ideas?


RE: Door set to locked, but unlocked? - Your Computer - 08-01-2011

Where did you tell the script to lock it?


RE: Door set to locked, but unlocked? - Asaratha - 08-01-2011

I didn't, it is set to locked in the level editor.


RE: Door set to locked, but unlocked? - Your Computer - 08-01-2011

(08-01-2011, 08:23 PM)Asaratha Wrote: I didn't, it is set to locked in the level editor.

I know that, but it seems i should have checked your code for more than syntax and function parameter errors. The code logic seems to be wrong.

Code:
void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("keydoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "keydoor_1", 0, false);
    RemoveItem("key_1");
    SetSwingDoorLocked("keydoor_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "keydoor_2", 0, false);
    RemoveItem("key_2");
}

So you want both doors to open at the same time when opening either door?




RE: Door set to locked, but unlocked? - Asaratha - 08-01-2011

(08-01-2011, 08:41 PM)Your Computer Wrote:
(08-01-2011, 08:23 PM)Asaratha Wrote: I didn't, it is set to locked in the level editor.

I know that, but it seems i should have checked your code for more than syntax and function parameter errors. The code logic seems to be wrong.

Code:
void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("keydoor_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "keydoor_1", 0, false);
    RemoveItem("key_1");
    SetSwingDoorLocked("keydoor_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "keydoor_2", 0, false);
    RemoveItem("key_2");
}

So you want both doors to open at the same time when opening either door?

No. It worked before I added the monster if I recall correctly. Both doors are locked, you find the key near the beginning and open the first door. That room leads you to another room with 2 doors, you go through the first (unlocked) door. You get to a destroyed room and you pick up a key that opens the next one in the other room. It also sets up a monster. When you get back to the room, you use the key to unlock the door leading to a kitchen.

BUT, for some reason, the kitchen door (door2) is always unlocked.



RE: Door set to locked, but unlocked? - Your Computer - 08-01-2011

(08-01-2011, 09:00 PM)Asaratha Wrote: No. It worked before I added the monster if I recall correctly. Both doors are locked, you find the key near the beginning and open the first door. That room leads you to another room with 2 doors, you go through the first (unlocked) door. You get to a destroyed room and you pick up a key that opens the next one in the other room. It also sets up a monster. When you get back to the room, you use the key to unlock the door leading to a kitchen.

BUT, for some reason, the kitchen door (door2) is always unlocked.
So nowhere in the code you posted is the kitchen door referenced? If so, then try not relying on the level editor and do so in the script. If not, then add conditional statements to your KeyOnDoor function. Also, for future reference, you may want to be more specific with naming your variables; that is, "key_#" and "keydoor_#" is too vague.