Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Check if a player is inside a script area?
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#1
Check if a player is inside a script area?

I have a small script area and I have an "int bank" set to 0 and I want it to be 1 when the player is inside the area and go back to 0 when the player leaves.

How would I do this?

Thanks in advance.

Current - Castle Darkuan
Other - F*cked Map
03-06-2012, 03:29 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#2
RE: Check if a player is inside a script area?

Could be wrong, haven't done any messing with variables in HPS yet, but here we go...

void OnStart()
{
SetLocalVarInt("bank", 0);
AddEntityCollideCallback("player", "scriptarea", "function", [delete?], 1);
AddEntityCollideCallback("player", "scriptarea", "function", [delete?], -1);
}

void function(string &in asParent, string &in asChild, int alState)
{
if (bank == 0)
{ bank = 1; }
else if (bank == 1)
{ bank = 0; }
}

Not sure if you need to have the int name in "" if your referencing it like I have in the 'if' there, but basically when you enter the area the function runs, if it finds the int is 0 it sets it to one. Once the player leave the area the function will run again and if its at 1 it will be set back to 0. You probably dont want those collide callbacks to delete so put false where ive said 'delete?', but I dont know what your trying to do with this so, adapt as required.

Let me know if you get any issues
03-06-2012, 04:47 PM
Find
Unearthlybrutal Offline
Posting Freak

Posts: 775
Threads: 12
Joined: May 2011
Reputation: 26
#3
RE: Check if a player is inside a script area?

Spoiler below!
void OnStart()
{
SetLocalVarInt("bank", 0);
AddEntityCollideCallback("player", "scriptarea", "function", false, 1);
AddEntityCollideCallback("player", "scriptarea", "function", false, -1);
}

void function(string &in asParent, string &in asChild, int alState)
{
if (GetLocalVarInt("bank") == 0)
{
SetLocalVarInt("bank", 1);
}
if (GetLocalVarInt("bank") == 1)
{
SetLocalVarInt("bank ", 0);
}
}

Or:
Spoiler below!

void OnStart()
{
SetLocalVarInt("bank", 0);
AddEntityCollideCallback("player", "scriptarea", "function", false, 1);
AddEntityCollideCallback("player", "scriptarea", "function", false, -1);
}

void function(string &in asParent, string &in asChild, int alState)
{
if (GetLocalVarInt("bank") == 0)
{
SetLocalVarInt("bank", 1);
}
else

SetLocalVarInt("bank ", 0);

}


When Life No Longer Exists
Full-conversion mod
(This post was last modified: 03-06-2012, 04:55 PM by Unearthlybrutal.)
03-06-2012, 04:54 PM
Website Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#4
RE: Check if a player is inside a script area?

(03-06-2012, 04:54 PM)Unearthlybrutal Wrote:
Spoiler below!
void OnStart()
{
SetLocalVarInt("bank", 0);
AddEntityCollideCallback("player", "scriptarea", "function", false, 1);
AddEntityCollideCallback("player", "scriptarea", "function", false, -1);
}

void function(string &in asParent, string &in asChild, int alState)
{
if (GetLocalVarInt("bank") == 0)
{
SetLocalVarInt("bank", 1);
}
if (GetLocalVarInt("bank") == 1)
{
SetLocalVarInt("bank ", 0);
}
}

Or:
Spoiler below!

void OnStart()
{
SetLocalVarInt("bank", 0);
AddEntityCollideCallback("player", "scriptarea", "function", false, 1);
AddEntityCollideCallback("player", "scriptarea", "function", false, -1);
}

void function(string &in asParent, string &in asChild, int alState)
{
if (GetLocalVarInt("bank") == 0)
{
SetLocalVarInt("bank", 1);
}
else

SetLocalVarInt("bank ", 0);
}

So, you need to use SetLocalVarInt(name, val) every time you need to change the value of a variable? I was hoping it was enough like javascript that you could just set it by referencing the name and giving it a value. My apologies for poor practise OP!

03-06-2012, 05:45 PM
Find
Unearthlybrutal Offline
Posting Freak

Posts: 775
Threads: 12
Joined: May 2011
Reputation: 26
#5
RE: Check if a player is inside a script area?

You can also use:

AddLocalVarInt("name", val);

For example if "val" is 1, it adds 1 to the variable.
It can also be -1, so it takes 1 away from the variable.

When Life No Longer Exists
Full-conversion mod
(This post was last modified: 03-06-2012, 07:31 PM by Unearthlybrutal.)
03-06-2012, 07:31 PM
Website Find




Users browsing this thread: 2 Guest(s)