Frictional Games Forum (read-only)
scripting: check if treasure chest is open - 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: scripting: check if treasure chest is open (/thread-7006.html)



scripting: check if treasure chest is open - palistov - 03-23-2011

Hey all, I'm trying to make an area collide function which only activates if a treasure chest is open. I've tried a few things, but I'm still pretty new to scripting. Thanks for any advice you may have!


RE: scripting: check if treasure chest is open - Pandemoneus - 03-23-2011

I am not going to give you explicit code now, rather a layout.
Note that I didn't test this and it might not work.

1. Create a script area above the chest, let's call it ChestScriptArea.
2. Add an entity collide callback using the ChestScriptArea and the chest itself in your OnStart and use 0 as last value, let's call the callback ChestState.
3. In the ChestState function, make an if-clause with if (alState == 1) and set your LocalVarInt (which I call ChestOpen now) to 1. Create another if-clause with if (alState == -1) and set ChestOpen to something different than 1.
4. Now add another entity collide callback using your original script area and set the boolean to false (so it doesn't get removed when you enter the area).
5. In that new callback function, check if (GetLocalVarInt("ChestOpen") == 1), then your amazing stuff happens and don't forget to the orginial script area to inactive, so it won't trigger again.


RE: scripting: check if treasure chest is open - palistov - 03-23-2011

Yeah I've tried that, but not with the if statements. I'll give that a go. I think I can piece it together but if I can't I'll come back for help Smile Thanks Pandemoneus.
Oh yes I see my previous problem. The script area I put above the chest was far too small, so the chest door ended up leaving the script area as it was opened. My previous code had a if(GetEntitiesCollide("chest", "chestcollide")) clause, so nothing happened! Thank you!
It now works perfectly, thanks so much!


RE: scripting: check if treasure chest is open - Samuelblitz - 03-25-2011

I am sorry for asking in this thread, but i figured since this thread is exactly what i'm trying to do, i shouldn't make a new topic.
I am trying to make it so when the player walks into a room, they walk into an area (door_close_trigger) that will close the door behind them IF they left it open.

under OnStart i have these two:

"AddEntityCollideCallback("storage_door1", "monster_scare3", "DoorState", true, 0);
AddEntityCollideCallback("Player", "door_close_trigger", "CloseDoor", true, 1);"

later in the script i have:

"void DoorState(string &in asParent, string &in asChild, int alState)
{
if (alState == 1)
{
SetLocalVarInt("DoorOpen", 1);
}
if (alState == -1)
{
SetLocalVarInt("DoorOpen", 0);
}
}"

and then:

"void CloseDoor(string &in asParent , string &in asChild , int alState)
{
if(GetLocalVarInt("DoorOpen") == 1)
{
SetSwingDoorLocked("storage_door1", true, true);
GiveSanityDamage(15.0f, true);
PlaySoundAtEntity("", "lock_door.snt", "monster_scare3", 0.0f, false);
PlaySoundAtEntity("", "react_breath.snt", "Player", 0.0f, false);
}
if(GetLocalVarInt("DoorOpen") == 0)
{
AddDebugMessage("Door is closed! Smile", false);
}
}
"

When i test this in-game i always get the debug message "Door is closed! Smile" even if it is obviously open, help would be very much appreciated.


RE: scripting: check if treasure chest is open - Pandemoneus - 03-25-2011

For doors you should just use
Code:
if (GetSwingDoorClosed(string &asName) == false) //door NOT closed
{
...do something...
}

[edit]
Or if you don't want anything to happen when the door is almost closed:

Code:
/**
* -1 = angle is close to 0, 1=angle is 70% or higher of max, 0=inbetween -1 and 1.
*/
if (GetSwingDoorState(string &asName) != -1)
{
...do something...
}



RE: scripting: check if treasure chest is open - jens - 03-25-2011

Add a debug message to DoorState and make sure the door and that area actually interacts so that the variable changes.

You also want to set AddEntityCollideCallback("storage_door1", "monster_scare3", "DoorState", true, 0);

to false

AddEntityCollideCallback("storage_door1", "monster_scare3", "DoorState", false, 0);

as the player could open and close the door several times and you want to keep checking that for each, with true it auto disabled after the first collision.


RE: scripting: check if treasure chest is open - Samuelblitz - 03-25-2011

(03-25-2011, 05:23 PM)Pandemoneus Wrote: For doors you should just use
Code:
if (GetSwingDoorClosed(string &asName) == false) //door NOT closed
{
...do something...
}

[edit]
Or if you don't want anything to happen when the door is almost closed:

Code:
/**
* -1 = angle is close to 0, 1=angle is 70% or higher of max, 0=inbetween -1 and 1.
*/
if (GetSwingDoorState(string &asName) != -1)
{
...do something...
}

Thank you so much! That completely slipped my mind, haha.
It worked perfectly, thank you