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 Checking if player is inside of a script area
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#4
RE: Checking if player is inside of a script area

(09-05-2016, 10:14 PM)Slanderous Wrote: That's what I used in my mod for barricades. Basically checks what's the state of the entity. 1 = means the entity is within the area, -1 = the entity is not within the area. Should work for anything.

PHP Code: (Select All)
AddEntityCollideCallback("""sth_1""BarricadeCheck"false0);

void BarricadeCheck(string &in asParentstring &in asChildint alState)
{
    if(
alState == -1)
    {
    
SetSwingDoorLocked("prison_12"falsefalse);
    }
    else if(
alState == 1)
    {
    
SetSwingDoorLocked("prison_12"truefalse);
    }


This only checks at the time of the collision.
If the player has been wandering around inside the area, (For example, inside a room), maybe you want to check whether the player is still inside the area after 60 seconds.

Darkfire gave the solution. What you want to do is set a variable to 1 when the player enters the area, and set it to -1 when the player leaves.

This way you just have to check what value the variable has.

PHP Code: (Select All)
void OnStart()
{
    
AddEntityCollideCallback("Player""Area_1""PlayerEnterArea_1"false0);
}

void PlayerEnterArea_1(string &in asParentstring &in asChildint alState)
{
    
SetLocalVarInt("PlayerEnterArea_1"alState);


Notice that I'm just setting the variable to alState. This is because alState is already either 1 or -1, so you won't have to worry about if-statements.

Trying is the first step to success.
(This post was last modified: 09-06-2016, 09:38 AM by FlawlessHappiness.)
09-06-2016, 09:33 AM
Find


Messages In This Thread
RE: Checking if player is inside of a script area - by FlawlessHappiness - 09-06-2016, 09:33 AM



Users browsing this thread: 1 Guest(s)