10.07.2012, 08:08
So,I am making a speed system for vehicles,but the problem is that when I enter a car the speed bar doesn't shoow up,here's the code:
Sp,that's all?Can anyone tell me why isn't working?Please help me asap.Thanks in advance.
pawn Код:
forward UpdateSpeed(playerid);
new uSpeed;
new Text:vSpeed;
stock GetPlayerSpeed(playerid, bool:kmh = true)
{
new
Float:xx,
Float:yy,
Float:zz,
Float:pSpeed;
if(IsPlayerInAnyVehicle(playerid))
{
GetVehicleVelocity(GetPlayerVehicleID(playerid),xx,yy,zz);
}
else
{
GetPlayerVelocity(playerid,xx,yy,zz);
}
pSpeed = floatsqroot((xx * xx) + (yy * yy) + (zz * zz));
return kmh ? floatround((pSpeed * 195.12)) : floatround((pSpeed * 136.66667));
}//WARNING:This works for vehicle also,event if the name of the function is not relevant :P
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
new vString[128];
format(vString,sizeof(vString),"Speed:%d",GetPlayerSpeed(playerid));
new Float:x,Float:y;
vSpeed = TextDrawCreate(x,y,vString);
TextDrawAlignment(vSpeed,3);
TextDrawColor(vSpeed,COLOR_WHITE);
TextDrawFont(vSpeed,0);
TextDrawShowForPlayer(playerid,vSpeed);
uSpeed = SetTimer("UpdateSpeed",1000,true);
if(oldstate == PLAYER_STATE_DRIVER&&newstate==PLAYER_STATE_ONFOOT)
{
TextDrawDestroy(vSpeed);
KillTimer(uSpeed);
}
}
return 1;
}
public UpdateSpeed(playerid)
{
new vString[128];
format(vString,sizeof(vString),"Speed:%d",GetPlayerSpeed(playerid));
new Float:x,Float:y;
vSpeed = TextDrawCreate(x,y,vString);
TextDrawAlignment(vSpeed,3);
TextDrawColor(vSpeed,COLOR_WHITE);
TextDrawFont(vSpeed,0);
TextDrawShowForPlayer(playerid,vSpeed);
return 1;
}