new showspeedo[MAX_PLAYERS], Text:Speedometer[MAX_PLAYERS];
foreach(new i : Player)
{
if(IsPlayerConnected(i))
{
Speedometer[i] = TextDrawCreate(300.0, 437.0, "KM/H: 0");
TextDrawFont(Speedometer[i], 1);
TextDrawSetOutline(Speedometer[i], 1);
TextDrawSetShadow(Speedometer[i], 0);
}
}
CMD:speedo(playerid, params[])
{
#pragma unused params
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must be in vehicle to use this command!");
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_RED, "Only driver can use this command!");
if(showspeedo[playerid] == 0)
{
TextDrawShowForPlayer(playerid, Speedometer[playerid]);
showspeedo[playerid] = 1;
SendClientMessage(playerid, COLOR_GREEN, "^ Speedometer ON!");
}
else if(showspeedo[playerid] == 1)
{
TextDrawHideForPlayer(playerid, Speedometer[playerid]);
showspeedo[playerid] = 0;
SendClientMessage(playerid, COLOR_RED, "^ Speedometer OFF!");
}
return 1;
}
if(showspeedo[playerid] == 1)
{
if(oldstate == PLAYER_STATE_DRIVER)
{
if(newstate == PLAYER_STATE_ONFOOT)
{
TextDrawHideForPlayer(playerid, Speedometer[playerid]);
showspeedo[playerid] = 0;
}
}
}
if(showspeedo[playerid] == 1 && IsPlayerInAnyVehicle(playerid))
{
new SpeedString[24];
format(SpeedString, sizeof(SpeedString), "~g~KM/H: ~r~%d", GetVehicleSpeed(GetPlayerVehicleID(playerid)));
TextDrawShowForPlayer(playerid, Speedometer[playerid]);
TextDrawSetString(Speedometer[playerid], SpeedString);
}
The textdraw variable also needs to be prefixed with the Text: tag and should be initialized with the value Text:INVALID_TEXT_DRAW. If you omit the initialization, the textdraw may conflict with others as you add more textdraws. |
new Text:MyTextDraw = Text:INVALID_TEXT_DRAW; //Global textdraw new PlayerText:MyTextDraw = PlayerText:INVALID_TEXT_DRAW; //Per player textdraw