Having problems with key unlocking a door scripting. - 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: Having problems with key unlocking a door scripting. (/thread-16013.html) |
Having problems with key unlocking a door scripting. - ieatbrainz - 06-10-2012 I'm new to editing and I have done a few little scripting things on my map so far, but now I am attempting to bring a key into it. I've watched a fair few tutorials, gone through heaps of threads in attempt to find an answer.. I can get into the map, no fatal errors or anything, but the key doesn't actually work on the door. I have the names right for the key and the door. I have another item in my scripting, so if you can be awesome and look through my scripting to see where I went wrong it would mean a lot. //////////////////////////// // Run when entering map void OnStart() { AddEntityCollideCallback("Player", "RoomTwoArea", "CollideRoomTwo", true, 1); AddUseItemCallback("", "KeyOne", "manny", "UsedKeyOnDoor", true); } void CollideRoomTwo(string &in asParent, string &in asChild, int alState) { SetSwingDoorClosed("Mansion_1", true, true); StartPlayerLookAt("Mansion_1", 10.0f, 10.0f, ""); AddTimer("", 1, "stoplook"); } void stoplook(string &in asTimer) { StopPlayerLookAt(); GiveSanityDamage(5.0f, true); } void KeyOnDoor(string &in asItem, string &in asEntity) { SetSwingDoorLocked("manny", false, true); PlaySoundAtEntity("", "unlock_door", "manny", 0, false); RemoveItem("KeyOne"); } //////////////////////////// // Run when entering map void OnEnter() { } //////////////////////////// // Run when leaving map void OnLeave() { } I also have the key/door on a separate level, I'm not sure if this means I need to make a separate .hps file or not... Thanks heaps RE: Having problems with key unlocking a door scripting. - Statyk - 06-10-2012 Your callback is incorrect. void KeyOnDoor(string &in asItem, string &in asEntity) Should be: void UsedKeyOnDoor(string &in asItem, string &in asEntity) RE: Having problems with key unlocking a door scripting. - SilentStriker - 06-10-2012 The best way to make that function is like this: PHP Code: void OnStart() By writing the function like this will make that function be reusable without unlocking wrong door and removing a key you don't have. For Example: PHP Code: void OnStart() The above code is an example on how you can reuse the code. You can have 2 UseItemCallbacks and both works without any problems RE: Having problems with key unlocking a door scripting. - ieatbrainz - 06-10-2012 (06-10-2012, 04:16 AM)Statyk Wrote: Your callback is incorrect.I changed the function to UsedKeyOnDoor, but it still doesn't work, i try to use the key on the door and it doesn't work RE: Having problems with key unlocking a door scripting. - Statyk - 06-10-2012 (06-10-2012, 12:54 PM)ieatbrainz Wrote: I changed the function to UsedKeyOnDoor, but it still doesn't work, i try to use the key on the door and it doesn't workSounds like you have something labelled incorrectly somewhere then. RE: Having problems with key unlocking a door scripting. - FlawlessHappiness - 06-10-2012 This is the basic key script. { AddUseItemCallback("", "KeyOne", "manny", "UsedKeyOnDoor", true); } void UsedKeyOnDoor(string &in asItem, string &in asEntity) { SetSwingDoorLocked("manny", false, true); PlaySoundAtEntity("", "unlock_door", "manny", 0, false); RemoveItem("KeyOne"); } KeyOne = The key in your editor. It needs to have the exact same name as in your script. I guess your key is called KeyOne in both places Manny = I guess this is the door. Also needs same names, you know UsedKeyOnDoor = This is the function you call. A function is called when you write: void [Name of the function](something that specifies the function) The function-name you put in the void OnStart() and the function you call with 'void' also needs the same names. In your place: void UsedKeyOnDoor(string &in asItem, string &in asEntity) <- This specifies that you use an item on something (In this place, a door) The name could be anything else than UsedKeyOnDoor, as long as they both are the same. You see there is a lot that needs the same names, so i would just re-check all the names I hope you understood this
|