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
scripting: check if treasure chest is open
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#1
scripting: check if treasure chest is open

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!
03-23-2011, 12:41 AM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#2
RE: scripting: check if treasure chest is open

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.

(This post was last modified: 03-23-2011, 01:10 AM by Pandemoneus.)
03-23-2011, 01:08 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#3
RE: scripting: check if treasure chest is open

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!
(This post was last modified: 03-23-2011, 01:22 AM by palistov.)
03-23-2011, 01:11 AM
Find
Samuelblitz Offline
Junior Member

Posts: 16
Threads: 4
Joined: Feb 2011
Reputation: 0
#4
RE: scripting: check if treasure chest is open

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.
03-25-2011, 05:10 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#5
RE: scripting: check if treasure chest is open

For doors you should just use
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:

/**
* -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...
}

(This post was last modified: 03-25-2011, 05:26 PM by Pandemoneus.)
03-25-2011, 05:23 PM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#6
RE: scripting: check if treasure chest is open

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.
03-25-2011, 05:32 PM
Website Find
Samuelblitz Offline
Junior Member

Posts: 16
Threads: 4
Joined: Feb 2011
Reputation: 0
#7
RE: scripting: check if treasure chest is open

(03-25-2011, 05:23 PM)Pandemoneus Wrote: For doors you should just use
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:

/**
* -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
03-25-2011, 05:38 PM
Find




Users browsing this thread: 3 Guest(s)