detecting a players position
#3

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
Reply


Messages In This Thread
detecting a players position - by Marco_Valentine - 10.05.2012, 06:02
Re: detecting a players position - by Marco_Valentine - 10.05.2012, 06:08
Re: detecting a players position - by Grimrandomer - 10.05.2012, 06:20

Forum Jump:


Users browsing this thread: 2 Guest(s)