16.07.2012, 18:57
Hello. First time i tried with textdraw to make my own speedometer for vehicles. So the problem now i have is that when i enter to vehicle it shows speedometer, when i enter to vehicle with my other player, then for first player speedometer disappears, and for second player it will be visible. If second player exits vehicle, then first player can see speedometer again. Damn it really sucks.. My code:
And where could be the problem?
Code:
new Text:SpeedO[MAX_PLAYERS]; new Text:Box[MAX_PLAYERS]; new Text:DrawInfo[MAX_PLAYERS]; new Text:Kilometrazas new KmBonusTmr[MAX_PLAYERS]; new RodomDegalus[MAX_PLAYERS];[MAX_PLAYERS]; new SpeedOTmr[MAX_PLAYERS];
Code:
public OnPlayerStateChange(playerid, newstate, oldstate) { if(!IsPlayerInAnyVehicle(playerid)){ KillTimer(SpeedOTmr[playerid]); KillTimer(KmBonusTmr[playerid]); KillTimer(RodomDegalus[playerid]); TextDrawDestroy(DrawInfo[playerid]); TextDrawDestroy(Box[playerid]); TextDrawDestroy(SpeedO[playerid]); TextDrawDestroy(Kilometrazas[playerid]); }else{ if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER){ SpeedOTmr[playerid] = SetTimerEx("Speedometer", 50, 1, "i", playerid); KmBonusTmr[playerid] = SetTimerEx("KmBonusCheck", 50, 1, "i", playerid); RodomDegalus[playerid] = SetTimerEx("RodomDegaluss", 30000, 1, "i", playerid); } } return 1; }
Code:
forward Speedometer(playerid); public Speedometer(playerid) { new string[256], infoText[256], kilometrzDraw[256]; TextDrawDestroy(DrawInfo[playerid]); TextDrawDestroy(Box[playerid]); TextDrawDestroy(SpeedO[playerid]); TextDrawDestroy(Kilometrazas[playerid]); new vehicleid, Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, final_speed_int; vehicleid = GetPlayerVehicleID(playerid); GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z); final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*216.666667; // 136.666667 = kmph // 85.4166672= mph final_speed_int = floatround(final_speed,floatround_round); MasinosInfo[vehicleid][rida] += final_speed; if(final_speed_int >= 310){ new name[MAX_PLAYER_NAME], msg[256]; GetPlayerName(playerid, name, sizeof(name)); format(msg, sizeof(msg), "[Serveris]: %s buvo isspirtas! (Aptiktas speed hack)", name); SendClientMessageToAll(COLOR_YELLOW, msg); Kick(playerid); } if(GiveDrivingMoney[playerid] == false){ if(final_speed_int > 20){ GiveDrivingMoney[playerid] = true; new Intervalas; Intervalas = (300-final_speed_int); if(Intervalas < 50){ GiveDrivingMoneyTmr[playerid] = SetTimerEx("IncreaseMoney", 50*7, false, "i", playerid); }else{ GiveDrivingMoneyTmr[playerid] = SetTimerEx("IncreaseMoney", Intervalas*7, false, "i", playerid); } } } if(GiveDrivingLicense[playerid] == false){ if(final_speed_int > 20){ GiveDrivingLicense[playerid] = true; new Intervalas; Intervalas = (300-final_speed_int); if(Intervalas < 50){ GiveDrivingLicenseTmr[playerid] = SetTimerEx("IncreaseLicense", 50*14, false, "i", playerid); }else{ GiveDrivingLicenseTmr[playerid] = SetTimerEx("IncreaseLicense", Intervalas*14, false, "i", playerid); } } } format(string, sizeof(string), "%i Km/h", final_speed_int); SpeedO[playerid] = TextDrawCreate(475.0, 400.0, string); TextDrawFont(SpeedO[playerid], 2); TextDrawColor(SpeedO[playerid], COLOR_BLUE); TextDrawSetShadow(SpeedO[playerid], 0); TextDrawShowForPlayer(playerid, SpeedO[playerid]); format(kilometrzDraw, sizeof(kilometrzDraw), "Rida: %.2fKm", MasinosInfo[vehicleid][rida] / 100000); Kilometrazas[playerid] = TextDrawCreate(475.0, 415.0, kilometrzDraw); TextDrawFont(Kilometrazas[playerid], 2); TextDrawColor(Kilometrazas[playerid], COLOR_BLUE); TextDrawSetShadow(Kilometrazas[playerid], 0); TextDrawShowForPlayer(playerid, Kilometrazas[playerid]); Box[playerid] = TextDrawCreate(-5.0, 0.0, "I"); TextDrawUseBox(Box[playerid], 1); TextDrawShowForPlayer(playerid, Box[playerid]); format(infoText, sizeof(infoText), "Pinigai: %iLt || Licenzijos: %0.1f", PlayerInfo[playerid][Pinigai], PlayerInfo[playerid][Licenzijos]); DrawInfo[playerid] = TextDrawCreate(0.5, 0.5, infoText); TextDrawColor(DrawInfo[playerid], COLOR_YELLOW); TextDrawSetShadow(DrawInfo[playerid], 0); TextDrawFont(DrawInfo[playerid], 2); TextDrawShowForPlayer(playerid, DrawInfo[playerid]); return 1; }