Calculate Speed of Vehicle
#2

You need a consistent timer, like a 1 second timer, to figure the exact speed.
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;
}
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.
Reply


Messages In This Thread
Calculate Speed of Vehicle - by clavador - 02.10.2009, 02:04
Re: Calculate Speed of Vehicle - by Joe Staff - 02.10.2009, 05:44
Re: Calculate Speed of Vehicle - by yezizhu - 02.10.2009, 08:48
Re: Calculate Speed of Vehicle - by Joe Staff - 02.10.2009, 16:38

Forum Jump:


Users browsing this thread: 1 Guest(s)