02.10.2009, 05:44
You need a consistent timer, like a 1 second timer, to figure the exact speed.
I believe then you could use GetPlayerMPH(playerid) and GetPlayerKMPH(playerid) in your script, or just use those formulas in your own script.
Quite frankly, this is off the top of my head and I've been out of the game for some time, so I could be wrong.
pawn Код:
forward UpdateSpeed()
new Float:pOldPos[MAX_PLAYERS][3];
new Float:pSpeed[MAX_PLAYERS];
Float:GetPlayerMPH(playerid)
{
return ((pSpeed[playerid]*3600)/1000)*1.609344;
}
Float:GetPlayerKMPH(playerid)
{
return (pSpeed[playerid]*3600)/1000;
}
public OnGameModeInit()
{
SetTimer("UpdateSpeed",1000,1);
}
public UpdateSpeed()
{
new Float:x,Float:y,Float:z;
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerPos(i,x,y,z);
pSpeed[i]=floatsqroot( ((x-pOldPos[i][0])*(x-pOldPos[i][0]))+((y-pOldPos[i][1])*(y-pOldPos[i][1]))+((z-pOldPos[i][2])*(z-pOldPos[i][2])) );
pOldPos[i][0]=x;
pOldPos[i][1]=y;
pOldPos[i][2]=z;
}
}
return;
}
Quite frankly, this is off the top of my head and I've been out of the game for some time, so I could be wrong.