Frictional Games Forum (read-only)
[SCRIPT] Check if a player is inside a script area? - 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] Check if a player is inside a script area? (/thread-13810.html)



Check if a player is inside a script area? - Shadowfied - 03-06-2012

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.



RE: Check if a player is inside a script area? - Adrianis - 03-06-2012

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



RE: Check if a player is inside a script area? - Unearthlybrutal - 03-06-2012

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);

}




RE: Check if a player is inside a script area? - Adrianis - 03-06-2012

(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!




RE: Check if a player is inside a script area? - Unearthlybrutal - 03-06-2012

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.