SA-MP Forums Archive
IsPlayerInRangeOfPoint not working. - 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: IsPlayerInRangeOfPoint not working. (/showthread.php?tid=557894)



IsPlayerInRangeOfPoint not working. - Aerotactics - 15.01.2015

I'm trying to create a simple timer that checks to see if the player is within range, and if so, burns them. However the timer isn't working. After debugging, I found out the issue is with the IsPlayerInRangeOfPoint line, but can't figure how to fix it.

Or could the issue be the double loop? I was simply trying to save space.
pawn Код:
public FireBurn()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            for(new j=0; j<MAX_FIRES; j++)
            {
                if(IsValidDynamicObject(fire[j]))
                {
                    new Float:x, Float:y, Float:z;
                    GetDynamicObjectPos(fire[j], x, y, z);
                    if(IsPlayerInRangeOfPoint(i, 1, x, y, z))
                    {
                        new Float:health;
                        GetPlayerHealth(i, health);
                        SetPlayerHealth(i, (health - 5));
                        SendClientMessage(i, -1, "burning...");
                    }
                }
                else continue;
            }
        }
        else continue;
    }
    return 1;
}



Re: IsPlayerInRangeOfPoint not working. - Michael B - 15.01.2015

Hello!

My server developer suggests you to change:

pawn Код:
if(IsPlayerInRangeOfPoint(i, 1, x, y, z))
with

pawn Код:
if(IsPlayerInRangeOfPoint(i, 1.0, x, y, z))



Re: IsPlayerInRangeOfPoint not working. - Aerotactics - 15.01.2015

No luck, but rep for effort, thank you.


Re: IsPlayerInRangeOfPoint not working. - mahdi499 - 15.01.2015

I am his Developer, I'll try to help , Can you show me how your timer is defined and how it is called?


Re: IsPlayerInRangeOfPoint not working. - Schneider - 15.01.2015

I know from experience that Get(Dynamic)ObjectPos does not always work on certain objects, especially when they move. Get(Dynamic)ObjectPos returns the position where it was created, not the actual position after it moved.

Try to debug these coords and see if they are actually close together.

pawn Код:
Float:x, Float:y, Float:z, Float:px, Float:py, Float:pz;
GetDynamicObjectPos(fire[j], x, y, z);
GetPlayerPos(i, px, py, pz);
printf("Objectpos: %.2f, %.2f, %.2f \n Playerpos: %.2f, %.2f, %.2f", x, y, z, px, py, pz);
printf("Distance: %.2f", floatsqroot(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));



Re: IsPlayerInRangeOfPoint not working. - Aerotactics - 15.01.2015

Quote:
Originally Posted by Schneider
Посмотреть сообщение
I know from experience that Get(Dynamic)ObjectPos does not always work on certain objects, especially when they move. Get(Dynamic)ObjectPos returns the position where it was created, not the actual position after it moved.

Try to debug these coords and see if they are actually close together.

pawn Код:
Float:x, Float:y, Float:z, Float:px, Float:py, Float:pz;
GetDynamicObjectPos(fire[j], x, y, z);
GetPlayerPos(i, px, py, pz);
printf("Objectpos: %.2f, %.2f, %.2f \n Playerpos: %.2f, %.2f, %.2f", x, y, z, px, py, pz);
printf("Distance: %.2f", floatsqroot(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));
You called it, the Z returned on the fire object was > 2 from the original placement coords. Will adjust accordingly, +rep.