Frictional Games Forum (read-only)

Full Version: Keys and Doors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello here is the thing, i want to have some keys to open some doors but i dont know how to make a script for, I dont know, 10 doors or something.If you guys can help i apreciated.

Smile
Don't even think of having 10 keys in one map, it kills the gameplay.
But i could still help you out just so you can understand the script. Tell me what you already know.
Can you open one door with a key or do you want the learn the whole script?
Yeah i watch a tutorial on how to use a key to open a door and this is the script:

////////////////////////////
//Run first time starting map
void OnStart()
{
AddUseItemCallback("", "key_1", "mansion_1", "UsedKeyOnDoor", true);
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("key_1");
}


I tried to copy everything exept run first time and voidOnstart and I got a ERROR.
Help me pls
So basically what you did was copy UsedKeyOnDoor.
This caused the script to have the same function 2 times, with the same name.
When you use the key on the door the script doesn't know which function to execute, which causes the error. But even if the script would work, it would open the same door with the same key all the time.
So what you have to do is:
Code:
////////////////////////////
//Run first time starting map
void OnStart()
{
AddUseItemCallback("", "key_1", "mansion_1", "UsedKeyOnDoor1", true);
AddUseItemCallback("", "key_2", "mansion_2", "UsedKeyOnDoor2", true);
}

void UsedKeyOnDoor1(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("key_1");
}


void UsedKeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_2", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_2", 0, false);
RemoveItem("key_2");
}
Now you have to create 2 keys, one called key_1 and the other key_2.
Create 2 mansion doors, called mansion_1 and mansion_2.
With key_1 you can open mansion_1 and with key_2 mansion_2.
Important: It has to be key_1 and not Key_1!
C++ is case-sensitive.
Man you are the best now i can finally make my custom story and i have anhoter question how can i add a description and a name to a key?
yeah i watch that but it didnt explain how to make for more doors and didnt show how to describe and name the keys.
And i want to describe and name the key.
Open your custom story folder, create a textfile called extra_english.lang and open it with a text editor.
Now insert this code:
Code:
<LANGUAGE>
<CATEGORY Name="Inventory">
    <Entry Name="ItemDesc_key_1">This key opens mansion_1</Entry>
    <Entry Name="ItemName_key_1">Key number one</Entry>
    <Entry Name="ItemDesc_key_2">This key opens mansion_2</Entry>
    <Entry Name="ItemName_key_2">Key number two</Entry>
</CATEGORY>
</LANGUAGE>
And change the description how you like.