16.01.2010, 21:15
Something like this I guess
With that script, the variables pTravelDist[playerid][TRAVEL_ONFOOT] and pTravelDist[playerid][TRAVEL_DRIVER] will keep tracking of your distance traveled on foot and whilst driver, respectively.
EDIT* Note that those values are in meters.
pawn Код:
#define TRAVEL_TYPES 2
#define TRAVEL_ONFOOT 0
#define TRAVEL_DRIVER 1
#define INVALID_POS -10000.00
forward UpdateTravel();
new Float:pTravelDist[MAX_PLAYERS][TRAVEL_TYPES];
new Float:pOldPos[MAX_PLAYERS][3];
stock PlayerDistanceToPoint(playerid,Float:x,Float:y,Float:z)
{
new Float:px,Float:py,Float:pz;
GetPlayerPos(playerid,py,px,pz);
return floatsqroot( ( (x-px)*(x-px) ) + ( (y-py)*(y-py) ) + ( (z-pz)*(z-pz) ) );
}
public OnGameModeInit()
{
SetTimer("UpdateTravel",1000,1);
return 1;
}
public OnPlayerConnect(playerid)
{
pOldPos[playerid]={INVALID_POS,...};
return 1;
}
public OnPlayerSpawn(playerid)
{
pOldPos[playerid]={INVALID_POS,...};
return 1;
}
public UpdateTravel()
{
new Float:x,Float:y,Float:z;
for(new playerid;playerid<MAX_PLAYERS;playerid++) //Suggested to use foreach
{
if(!IsPlayerConnected(playerid))continue;
GetPlayerPos(playerid,x,y,z);
if(pOldDist[playerid][0]=INVALID_POS)
{
pOldDist[playerid][0]=x;
pOldDist[playerid][1]=y;
pOldDist[playerid][2]=z;
}else{
switch(GetPlayerState(playerid))
{
case PLAYER_STATE_ONFOOT: pTravelDist[playerid][TRAVEL_ONFOOT]+=PlayerDistanceToPoint(playerid,pOldDist[playerid][0],pOldDist[playerid][1],pOldDist[playerid][2]);
case PLAYER_STATE_DRIVER: pTravelDist[playerid][TRAVEL_DRIVER]+=PlayerDistanceToPoint(playerid,pOldDist[playerid][0],pOldDist[playerid][1],pOldDist[playerid][2]);
}
pOldDist[playerid][0]=x;
pOldDist[playerid][1]=y;
pOldDist[playerid][2]=z;
}
}
}
EDIT* Note that those values are in meters.