12.06.2011, 16:08
Alright I had made a speedo. When in game is says Speed: 0 m/h. I cant get it to update the speed. Heres the code.
In OnGameModeInit
In OnGameModeInit
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
Speedo = TextDrawCreate(506.000000,351.000000,"_");
SetTimer("Speedometer",1000,true);
}
pawn Код:
forward Speedometer(playerid);
public Speedometer(playerid)
{
new Float:VehVelocity[3];
new State = GetPlayerState(playerid);
if(State == PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid))
{
#define MULTIPLY_SPEED 4
GetPlayerVelocity(playerid, VehVelocity[0], VehVelocity[1], VehVelocity[2]);
new Float:speed = floatsqroot(VehVelocity[0] * VehVelocity[0] + VehVelocity[1] * VehVelocity[1] + VehVelocity[2] * VehVelocity[2]);
new Sspeed[15], string[200];
if( speed == 0) {
format(Sspeed,sizeof(Sspeed),"~G~%dm/h",(floatround(speed)*MULTIPLY_SPEED));
} else if( speed >= 1 && speed <= 65 ){
format(Sspeed,sizeof(Sspeed),"~G~%dm/h",(floatround(speed)*MULTIPLY_SPEED));
} else if( speed >= 66 && speed <= 120 ){
format(Sspeed,sizeof(Sspeed),"~Y~%dm/h",(floatround(speed)*MULTIPLY_SPEED));
} else {
format(Sspeed,sizeof(Sspeed),"~R~%dm/h",(floatround(speed)*MULTIPLY_SPEED));
}
format(string,sizeof(string),"Speed: %s", Sspeed);
TextDrawSetString(Speedo, string);
TextDrawShowForPlayer(playerid, Speedo);
}
else
{
//TextDrawHideForPlayer(playerid, Speedo[playerid]);
}
return true;
}