OnPlayerUpdate is not the best place for textdraws, A timer of 200 - 300 ms should be fine for this situation.
You could detect when player enters vehicle with OnPlayerStateChange and saving that in boolean or integer, and setting textdraw on/ off with it, then, use custom timer to update the speed. |
Well, as once ****** said, we're not magicians and we can't guess your code.
|
forward UpdateCok(playerid); public UpdateCok(playerid) { if(!IsPlayerInAnyVehicle(playerid) || PlayerCok[playerid] == 0 || IsABike(GetPlayerVehicleID(playerid)) || GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return HideCok(playerid); new PlayerVehicleSpeed[MAX_PLAYERS]; PlayerVehicleSpeed[playerid] = GetVehicleSpeed(playerid); new string[200]; new tacche[350]; new x = PlayerVehicleSpeed[playerid]; if(RetroMarcia[playerid] == 1) { TextDrawSetString(CokMarcia[playerid],"R"); } else { TextDrawSetString(CokMarcia[playerid],"1"); } TextDrawHideForPlayer(playerid,CokNumero[playerid]); TextDrawHideForPlayer(playerid,CokTacche[playerid]); if(PlayerVehicleSpeed[playerid] >= 0 && PlayerVehicleSpeed[playerid] <= 9) { format(string,sizeof(string),"00%d",PlayerVehicleSpeed[playerid]); } if(PlayerVehicleSpeed[playerid] >= 10 && PlayerVehicleSpeed[playerid] <= 99) { format(string,sizeof(string),"0%d",PlayerVehicleSpeed[playerid]); } if(PlayerVehicleSpeed[playerid] >= 100) { format(string,sizeof(string),"%d",PlayerVehicleSpeed[playerid]); } if(x <= 1) { format(tacche,sizeof(tacche),"llllllllllllllllllllll"); } else if(x > 1 && x < 11) { format(tacche,sizeof(tacche),"~g~l~w~lllllllllllllllllllll"); } else if(x > 11 && x < 21) { format(tacche,sizeof(tacche),"~g~ll~w~llllllllllllllllllll"); } else if(x > 21 && x < 31) { format(tacche,sizeof(tacche),"~g~lll~w~lllllllllllllllllll"); } else if(x > 31 && x < 41) { format(tacche,sizeof(tacche),"~g~llll~w~llllllllllllllllll"); } else if(x > 41 && x < 51) { format(tacche,sizeof(tacche),"~g~lllll~w~lllllllllllllllll"); } else if(x > 51 && x < 61) { format(tacche,sizeof(tacche),"~g~llllll~w~llllllllllllllll"); } else if(x > 61 && x < 71) { format(tacche,sizeof(tacche),"~g~llllllll~w~llllllllllllll"); } else if(x > 71 && x < 81) { format(tacche,sizeof(tacche),"~g~lllllllll~w~lllllllllllll"); } else if(x > 81 && x < 91) { format(tacche,sizeof(tacche),"~g~llllllllll~w~llllllllllll"); } else if(x > 101 && x < 111) { format(tacche,sizeof(tacche),"~g~lllllllllll~w~lllllllllll"); } else if(x > 111 && x < 121) { format(tacche,sizeof(tacche),"~g~llllllllllll~w~llllllllll"); } else if(x > 121 && x < 131) { format(tacche,sizeof(tacche),"~g~lllllllllllll~w~lllllllll"); } else if(x > 131 && x < 141) { format(tacche,sizeof(tacche),"~g~llllllllllllll~w~llllllll"); } else if(x > 141 && x < 151) { format(tacche,sizeof(tacche),"~g~lllllllllllllll~w~lllllll"); } else if(x > 151 && x < 161) { format(tacche,sizeof(tacche),"~g~lllllllllllllllll~w~lllll"); } else if(x > 161 && x < 171) { format(tacche,sizeof(tacche),"~g~llllllllllllllllll~w~llll"); } else if(x > 181 && x < 191) { format(tacche,sizeof(tacche),"~g~lllllllllllllllllll~w~lll"); } else if(x > 191 && x < 195) { format(tacche,sizeof(tacche),"~g~llllllllllllllllllll~w~ll"); } else if(x > 195 && x < 196) { format(tacche,sizeof(tacche),"~g~lllllllllllllllllllll~w~l"); } else if(x > 196) { format(tacche,sizeof(tacche),"~g~llllllllllllllllllllll"); } TextDrawSetString(CokTacche[playerid],tacche); TextDrawSetString(CokNumero[playerid],string); TextDrawShowForPlayer(playerid,CokNumero[playerid]); TextDrawShowForPlayer(playerid,CokTacche[playerid]); return 1; public OnPlayerStateChange(playerid, newstate, oldstate) { if(newstate == PLAYER_STATE_DRIVER) { if(!IsABike(vehicleid) && CarShop[playerid] == 0) { PlayerCok[playerid] = 1; ShowCok(playerid); CokTimer[playerid] = SetTimerEx("UpdateCok", 300, true, "i", playerid); } } }