I'm having trouble making a key script as well.
The door I am trying to open is named "door_1".
The key is named "key_study" (I think. It's a key that is produced when you shatter a wine bottle, so there's no way to name it, but the option in the menu to have a key inside is named "key_study").
The thing is, when I pick up the key it says I've found the Machine Room Key, and when I try to use it on the door it says "Cannot be used this way!"
This is my code:
void OnStart()
{
AddUseItemCallback("useexit", "key_study", "door_1", "UseKey", true);
}
void UseKey(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
RemoveItem(asItem);
}
Any help?
EDIT: Also, I really don't know any code and simply copied this from earlier in the thread. It would be great if someone could explain what these commands do.
EDIT2: I tried doing this similarly with a key that was just sitting on a table and got it to work since I was able to name it, but I would still like an answer to my previous question if possible. Also, how do I code in a 2nd key? The thing is, there's a key in the desk door that opens the door to the room but I'm not sure how to code this in.
Thanks!
EDIT3: Got it all figured out