Frictional Games Forum (read-only)

Full Version: Locked doors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I am very new with HPL editor and im working on my first custom story. I have no real coding experience but it's gone quite good so far. The problem I have right now is that i first made a locked door and managed to create a key that opens it. Now I've made a new locked door with a key that's suppose to open it. The thing is that when i unlock my first door the second one also unlocks. I can still use my second key on my second unlocked door. I've put the door on locked in the editor so I don't know what the problem is Sad

Here is the code for the doors.


{
AddUseItemCallback("", "key1", "bedroomdoor1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "key2", "bedroomdoor2", "UsedKeyOnDoor", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("bedroomdoor1", false, true);
PlaySoundAtEntity("", "unlock_door", "bedroomdoor1", 0, false);
RemoveItem("key1");

SetSwingDoorLocked("bedroomdoor2", false, true);
PlaySoundAtEntity("", "unlock_door", "bedroomdoor2", 0, false);
RemoveItem("key2");

}
I'm not so good with code but from my assumption you've put both unlock statements in the same method. So any time someone unlocks bedroomdoor1 or 2, both doors are called to be unlocked. Try making another method for each door. Otherwise if all doors are under this same function, then every door in your level will have the same problem.

Something like this:
void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("bedroomdoor2", false, true);
PlaySoundAtEntity("", "unlock_door", "bedroomdoor2", 0, false);
RemoveItem("key2");

}


I'm not so great with scripting so this could be the wrong way to do it but this is how I assume it's done properly - If not i'm sure someone will correct me soon =) GL
Try using

SetSwingDoorLocked(asEntity, false, true);
RemoveItem(asItem);

Those never failed me. Of course, it only works if you do what Chap1400 said.
Chap1400 is right!

You see:

This line calls the function UsedKeyOnDoor:
AddUseItemCallback("", "key1", "bedroomdoor1", "UsedKeyOnDoor", true);



Which is here:
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("bedroomdoor1", false, true);
PlaySoundAtEntity("", "unlock_door", "bedroomdoor1", 0, false);
RemoveItem("key1");

}


You'll have to make a new one, otherwise it will just link to the same function as the first one did.
results in: Key1 works on door1 but opens both door1 and door2
Hey thank you guys for the help Smile

As I said I'm very new when it comes to coding so I'm just experimenting my way through Tongue

Again thank you for the help!
Very good idea! Start by experiementing! Don't release anything before you know what you are working with Wink