Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having problems with key unlocking a door scripting.
ieatbrainz Offline
Junior Member

Posts: 2
Threads: 1
Joined: Jun 2012
Reputation: 0
#1
Having problems with key unlocking a door scripting.

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 Smile
06-10-2012, 02:46 AM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#2
RE: Having problems with key unlocking a door scripting.

Your callback is incorrect.

void KeyOnDoor(string &in asItem, string &in asEntity)

Should be:

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
06-10-2012, 04:16 AM
Find
SilentStriker Offline
Posting Freak

Posts: 950
Threads: 26
Joined: Jul 2011
Reputation: 43
#3
RE: Having problems with key unlocking a door scripting.

The best way to make that function is like this:

PHP Code: (Select All)
void OnStart()
{
AddUseItemCallback("""KeyOne""manny""UsedKeyOnDoor"true);

}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
SetSwingDoorLocked(asEntityfalsetrue);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);


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: (Select All)
void OnStart()
{
AddUseItemCallback("""KeyOne""manny""UsedKeyOnDoor"true);
AddUseItemCallback("""KeyTwo""Manny2""UsedKeyOnDoor"true);
}

void UsedKeyOnDoor(string &in asItemstring &in asEntity)
{
SetSwingDoorLocked(asEntityfalsetrue);
PlaySoundAtEntity("""unlock_door"asEntity0false);
RemoveItem(asItem);


The above code is an example on how you can reuse the code. You can have 2 UseItemCallbacks and both works without any problems Smile

(This post was last modified: 06-10-2012, 09:17 AM by SilentStriker.)
06-10-2012, 09:16 AM
Find
ieatbrainz Offline
Junior Member

Posts: 2
Threads: 1
Joined: Jun 2012
Reputation: 0
#4
RE: Having problems with key unlocking a door scripting.

(06-10-2012, 04:16 AM)Statyk Wrote: Your callback is incorrect.

void KeyOnDoor(string &in asItem, string &in asEntity)

Should be:

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
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 Sad
06-10-2012, 12:54 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#5
RE: Having problems with key unlocking a door scripting.

(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 work Sad
Sounds like you have something labelled incorrectly somewhere then.
06-10-2012, 03:58 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#6
RE: Having problems with key unlocking a door scripting.

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 Wink


Manny = I guess this is the door. Also needs same names, you know Wink


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 Wink
I hope you understood this

Trying is the first step to success.
(This post was last modified: 06-10-2012, 04:32 PM by FlawlessHappiness.)
06-10-2012, 04:30 PM
Find




Users browsing this thread: 1 Guest(s)