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
Script Help Picking up a Lantern and unlocking a door
Hyperoom Offline
Junior Member

Posts: 5
Threads: 1
Joined: May 2017
Reputation: 0
#3
RE: Picking up a Lantern and unlocking a door

(06-20-2017, 08:50 PM)FlawlessHappiness Wrote: If you want a function to call when the player picks up an entity, the easiest thing to do is to call a function when the player interacts with the entity.

To do this you need to assign an InteractCallback function to the entity. You do this with by using the function

PHP Code: (Select All)
SetEntityPlayerInteractCallback(stringasNamestringasCallbackbool abRemoveOnInteraction);

asName internal name
asCallback 
- function to call
abRemoveOnInteraction 
determines whether the callback should be removed when the player interacts with the entity 

This function needs to be placed in the OnStart function of your code.

Now remember that asName, asCallback and abRemoveOnInteraction all need to be replaced with actual values.

For example if you, in the level editor, had an entity called "lantern_1" and, in your script, a function called "PickLanternUnlockDoor" you would write:

PHP Code: (Select All)
SetEntityPlayerInteractCallback("lantern_1""PickLanternUnlockDoor"true); 

(The 'true' written at the end means that this callback is removed after being called once. To not have this happen the 'true' would have to be 'false' instead)

Now you call the function "PickLanternUnlockDoor" when the player picks up the lantern, so all you need to do is write the function itself.

PHP Code: (Select All)
void PickLanternUnlockDoor(string &in asEntity)
{
    
SetSwingDoorLocked("door_name"falsetrue);


*Note that the '(string &in asEntity)' is like this because we are using an InteractCallback. It doesn't have to be exactly like this, but to avoid confusion keep it like this in the beginning.

**Note that "door_name" is the name of the door, and this has to be the name of your door in the level editor as well.

Alright!
The final script would look something like this:

PHP Code: (Select All)
void OnStart()
{
    
SetEntityPlayerInteractCallback("lantern_1""PickLanternUnlockDoor"true);
}

void PickLanternUnlockDoor(string &in asEntity)
{
    
SetSwingDoorLocked("door_name"falsetrue);

yay it doesnt work
06-21-2017, 08:51 AM
Find


Messages In This Thread
RE: Picking up a Lantern and unlocking a door - by Hyperoom - 06-21-2017, 08:51 AM



Users browsing this thread: 1 Guest(s)