SA-MP Forums Archive
detecting a players position - 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: detecting a players position (/showthread.php?tid=341263)



detecting a players position - Marco_Valentine - 10.05.2012

Ok, basically i want to know how i would go about detecting if a player is standing on the ground. (rather than mid air jumping or falling from a building)


Re: detecting a players position - Marco_Valentine - 10.05.2012

or at least an idea of how i could do this. Anyone? I thought anims.. but there are a lot of anims for standing


Re: detecting a players position - Grimrandomer - 10.05.2012

I guess use onplayerupdate, save their last position with SetPVarFloat


Код:
stock Float:Distance3D(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, bool:sqrt = false) {
	x1 -= x2;
	x1 *= x1;
	y1 -= y2;
	y1 *= y1;
	z1 -= z2;
	z1 *= z1;
	x1 += y1;
	x1 += z1;
	return sqrt ? floatsqroot(x1) : x1;
}

public OnPlayerUpdate(playerid)
{
    new Float:Cx,Float:Cy,Float:Cz;
    GetPlayerPos(playerid,Cx,Cy,Cz);

    if (Distance3D(GetPVarFloat(playerid,"xpos"),GetPVarFloat(playerid,"ypos"),GetPVarFloat(playerid,"zpos"),Cx,Cy,Cz)>0.01) {
         SetPVarInt(playerid, "moving", 1);
    }
    else {
         SetPVarInt(playerid, "moving", 0);
    }
    SetPVarFloat(playerid,"xpos",Cx); 
    SetPVarFloat(playerid,"ypos",Cy);
    SetPVarFloat(playerid,"zpos",Cz);
return 1;
}
Then to use it:

Код:
if (GetPVarInt(playerid, "moving")==1) {
 //... Do somthing
}
That >0.01 may need tweeking