Timer wird unter OnGameModeInit gestartet:
SetTimer("Speedometer",500,1);
Hier mein Speedopublic:
public Speedometer()
{
for(new i;i<MAX_PLAYERS;i++) {
if(!IsPlayerNPC(i)) {
if(IsPlayerConnected(i) && GetPVarInt(i,"Eingeloggt") == 1) {
if(IsPlayerInAnyVehicle(i) && GetPlayerVehicleSeat(i) == 0) {
new Float:CarHealth,chealth,string[512],string1[128],kmh,modelid,veh,Float:Distance;
veh=GetPlayerVehicleID(i);
modelid=GetVehicleModel(veh);
GetVehicleHealth(veh,CarHealth);
CarHealth = CarHealth - 250;
CarHealth = CarHealth /10;
CarHealth = CarHealth /75;
CarHealth = CarHealth *100;
chealth=floatround(CarHealth,floatround_floor);
kmh=GetPlayerSpeed(i, true);
if(Motor[veh] == false && Licht[veh] == false) {
PlayerTextDrawSetString(i, Tacho1[i],"~r~Motor ~r~Licht");
} else if(Motor[veh] == true && Licht[veh] == false) {
PlayerTextDrawSetString(i, Tacho1[i],"~g~Motor ~r~Licht");
} else if(Motor[veh] == true && Licht[veh] == true) {
PlayerTextDrawSetString(i, Tacho1[i],"~g~Motor ~g~Licht");
} else if(Motor[veh] == false && Licht[veh] == true) {
PlayerTextDrawSetString(i, Tacho1[i],"~r~Motor ~g~Licht");
}
GetVehiclePos(veh,pNewKM[0][i],pNewKM[1][i],pNewKM[2][i]);
printf("%f | %f | %f | %f | %f | %f |",pNewKM[0][i],pNewKM[1][i],pNewKM[2][i],pOldKM[0][i],pOldKM[1][i],pOldKM[2][i]);
new Distance=floatround(floatsqroot( ((pNewKM[0][i]-pOldKM[0][i])*(pNewKM[0][i]-pOldKM[0][i])) +((pNewKM[1][i]-pOldKM[1][i])*(pNewKM[1][i]-pOldKM[1][i])) + ((pNewKM[2][i]-pOldKM[2][i])*(pNewKM[2][i]-pOldKM[2][i])) ));
printf("distance = %d", Distance);
KM[veh] += Distance;
printf("KM[veh] = %d", KM[veh]);
pOldKM[0][i] = pNewKM[0][i];
pOldKM[1][i] = pNewKM[1][i];
pOldKM[2][i] = pNewKM[2][i];
format(string,sizeof string,"%d KM",KM[veh]);
TextDrawSetString(KManzeige[veh],string);
switch(Tank[veh]/(MaxTank[(modelid)-400]/10))
{
case 10: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I I I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 9: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I I I I I I ~r~I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 8: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I I I I I ~r~I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 7: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I I I I ~r~I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 6: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I I I ~r~I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 5: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I I ~r~I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 4: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I I ~r~I I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 3: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I I ~r~I I I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 2: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I I ~r~I I I I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 1: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~g~I ~r~I I I I I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
case 0: format(string,sizeof string,"Geschwingidkeit: %d km/h~n~Tankinhalt: ~r~I I I I I I I I I I ~w~(%d/%dL)~n~Zustand: %d%%~n~Fahrzeug: %s",kmh,Tank[veh],MaxTank[(modelid)-400],chealth,PlayerVehicle[modelid - 400]);
}
PlayerTextDrawSetString(i, Tacho0[i], string);
} else {
TextDrawHideForPlayer(i, TachoBox);
PlayerTextDrawHide(i, Tacho0[i]);
PlayerTextDrawHide(i, Tacho1[i]);
TextDrawHideForPlayer(i, KManzeige[GetPVarInt(i,"LastVeh")]);
}
}
}
}
return 1;
}
Und OnPlayerStateChange:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
new str[512],veh;
veh=GetPlayerVehicleID(playerid);
GetVehiclePos(veh,pOldKM[0][playerid],pOldKM[1][playerid],pOldKM[2][playerid]);
format(str,sizeof str,"Um den Motor des Fahrzeuges zu starten halte ~k~~VEHICLE_HANDBRAKE~ und ~k~~CONVERSATION_NO~ gedrückt!");
SendClientMessage(playerid,COLOR_WHITE,str);
TextDrawShowForPlayer(playerid, TachoBox);
TextDrawShowForPlayer(playerid, KManzeige[veh]);
PlayerTextDrawShow(playerid, Tacho0[playerid]);
PlayerTextDrawShow(playerid, Tacho1[playerid]);
SetPVarInt(playerid,"LastVeh",veh);
}
return 1;
}
Dann teste mal o.o