SA-MP Forums Archive
Multiple IsPlayerInRangeOfPoint - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multiple IsPlayerInRangeOfPoint (/showthread.php?tid=516311)



Multiple IsPlayerInRangeOfPoint - TheSimpleGuy - 30.05.2014

pawn Код:
//first gate
        if(IsPlayerInRangeOfPoint(playerid, 5.0, -363.6000100,932.7000100,12.2000000))
        {
                     SendClientMessage(playerid, -1, "lel!!!!!!!!!!!!!!!");
        }
        else
        {
                     SendClientMessage(playerid, -1, "le!!!!!!!!!!!!!!l");
        }
//second gate
        if(IsPlayerInRangeOfPoint(playerid, 5.0, -449.7998000,897.7998000,5.0000000))
        {
                     SendClientMessage(playerid, -1, "lel!!!!!");
        }
                else
                {
                     SendClientMessage(playerid, -1, "lel");
                }
I did put this on my OnPlayerUpdate, how do I check multiple IsPlayerInRangeOfPoint?
I can't do it on using the statement "else" on OnPlayerUpdate.


Re : Multiple IsPlayerInRangeOfPoint - S4t3K - 30.05.2014

Simply use a traditionnal "or" ("||")

PHP код:

if(IsPlayerInRangeOfPoint(playerid5.0, -363.6000100,932.7000100,12.2000000) || IsPlayerInRangeOfPoint(playerid5.0, -449.7998000,897.7998000,5.0000000)) return SCM(playerid, -1"you're in a 5.0 unities range of a gate !"); 
But for multiple checks, get prepared to a "input line too long (after subsitution)" error.


Re: Multiple IsPlayerInRangeOfPoint - Konstantinos - 30.05.2014

A global timer that loops through connected players (foreach) and checks if each player is in range will be much better than using OPU callback.

If you want to do the same thing when the player is in range of one of those:
pawn Код:
// an example:
if (IsPlayerInRangeOfPoint(playerid, range, x, y, z)
    || IsPlayerInRangeOfPoint(playerid, range, x, y, z)
    || IsPlayerInRangeOfPoint(playerid, range, x, y, z)
    || IsPlayerInRangeOfPoint(playerid, range, x, y, z)
    || IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}
If you want to check for different points and do different things:
pawn Код:
// an example:
if (IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}
else if (IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}
else if (IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}



Re: Multiple IsPlayerInRangeOfPoint - TheSimpleGuy - 30.05.2014

Okay, my point is like Konstantinos said, checking for different points and do different things. My thing is, I have multiple gates.
pawn Код:
if (IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}
else if (IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}
else if (IsPlayerInRangeOfPoint(playerid, range, x, y, z))
{
    // code..
}
Yes, I can do this, but the problem is, what if they're not in range anymore? How do I reclose them?


Re : Multiple IsPlayerInRangeOfPoint - S4t3K - 30.05.2014

Then check for the inverse condition no ?

When your public function is called again by the timer, simply check for the inverse condition.

For example, with your coordinates above,

PHP код:

new closed[MAX_GATES] = true;
if(
IsPlayerInRangeOfPoint(playerid5.0, -449.7998000,897.7998000,5.0000000) && closed[i]) { /* Open the gate */ }
else { 
/* Close the gate */ 
i stands for the gate id the player is near of.

It's not harder than this.


Re: Multiple IsPlayerInRangeOfPoint - TheSimpleGuy - 30.05.2014

What if it mixed up?


Re : Multiple IsPlayerInRangeOfPoint - S4t3K - 30.05.2014

Add a boolean variable whichs checks the tate of the door : opened or closed.

Then check it before moving the door object (I think you'll use Move(Dynamic)Object). If it's opened and the player is near of the door, return 1.
If it's not open but the player is near of the door, open it.
If it's open but the player isn't near of the door, close it.


Re: Multiple IsPlayerInRangeOfPoint - TheSimpleGuy - 30.05.2014

Sounds it'll work. Let me PM you if I have another problem.
Thanks,guys!