Frictional Games Forum (read-only)
[SCRIPT] Picking up a Lantern and unlocking a door - 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: [SCRIPT] Picking up a Lantern and unlocking a door (/thread-53779.html)



Picking up a Lantern and unlocking a door - Hyperoom - 06-20-2017

I really need help scripting a sequence that unlocks a door when player picks up a lantern. I already tried this code from 2010 but I just managed to close the thread:

Code:
void PickLanternUnlockDoor(string &in EntityName, string &in Type)
{
if(Type == "OnPickup") {
SetSwingDoorLocked("door_name", false, true);
}
}
I also have steam version that help at all.


RE: Picking up a Lantern and unlocking a door - FlawlessHappiness - 06-20-2017

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:
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:
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:
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:
void OnStart()
{
    
SetEntityPlayerInteractCallback("lantern_1""PickLanternUnlockDoor"true);
}

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




RE: Picking up a Lantern and unlocking a door - Hyperoom - 06-21-2017

(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:
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:
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:
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:
void OnStart()
{
    
SetEntityPlayerInteractCallback("lantern_1""PickLanternUnlockDoor"true);
}

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

yay it doesnt work


RE: Picking up a Lantern and unlocking a door - FlawlessHappiness - 06-21-2017

If it doesn't work, it will be very helpful if you post a picture of:

- Your full script file

- The door highlighted in the editor

- The lantern highlighted in the editor

Other things to make sure:
The .map file and the .hps file MUST be named the same thing.
e.g. "level1.map" and "level1.hps"

The .map and .hps files MUST be placed in the same /maps folder in your custom story.


RE: Picking up a Lantern and unlocking a door - Hyperoom - 06-21-2017

Map and script fiules can be found here: https://www.mediafire.com/folder/r2gaee9rkzpat/maps Tell me all mistakes in script/map and also red door crashes the game since I haven't created a map which it leads to.


RE: Picking up a Lantern and unlocking a door - FlawlessHappiness - 06-21-2017

Ah yes, I figured this was the problem.

There is a difference between a level door and a swing door.
In this case you want to unlock a level door, so you have to use

PHP Code:
SetLevelDoorLocked("level_hub_1"false); 



RE: Picking up a Lantern and unlocking a door - Hyperoom - 06-21-2017

Thank you so much! It's kinda ironic how I always wondered what that SwingDoor meant..


RE: Picking up a Lantern and unlocking a door - FlawlessHappiness - 06-21-2017

Hopefully it makes sense.

To clarify:
Swing door: A door that you can pull open and shut.
Level door: A door that you click and it takes you to a new level.