Creezi un timer in care verifici daca jucatorul este intr-un vehicul. Daca este ii afisezi textdraw-ul tau pentru kilometraj, iar cand iese din masina il ascunzi.
Spre exemplu:
timer OneSecondTimer[1000]()
{
new query[256];
foreach(new playerid : Player)
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) != PLAYER_STATE_ONFOOT)
{
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective)
format(query, 50, aVehicleNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
PlayerTextDrawSetString(playerid, TachoPTD[playerid][0], query);
PlayerTextDrawShow(playerid, TachoPTD[playerid][0]);
format(query, 50, "SPEED:_%d_KM/H", Carspeed(playerid));
PlayerTextDrawSetString(playerid, TachoPTD[playerid][1], query);
PlayerTextDrawShow(playerid, TachoPTD[playerid][1]);
format(query, 50, "FUEL:_%d_L", VehFuel[GetPlayerVehicleID(playerid)]);
PlayerTextDrawSetString(playerid, TachoPTD[playerid][2], query);
PlayerTextDrawShow(playerid, TachoPTD[playerid][2]);
format(query, 50, "%s", (doors < 1) ? ("~g~UNLOCKED") : ("~r~LOCKED"));
PlayerTextDrawSetString(playerid, TachoPTD[playerid][3], query);
PlayerTextDrawShow(playerid, TachoPTD[playerid][3]);
}
}
return 1;
}
Avem un timer de o secunda (ysi_timer) in care verific din toti jucatorii care este in vehicul. Daca jucatorul este intr-unul, atunci ii iau datele despre vehicul si i le afisez in textdraw-uri.
Cand iese jucatorul din vehicul ii ascund textdraw-urile:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
switch(newstate)
{
case PLAYER_STATE_ONFOOT: for(new i = 0; i < 4; i++) PlayerTextDrawHide(playerid, TachoPTD[playerid][i]);
}
return 1;
}
De asemenea, te poti folosi de functia asta pentru a-i lua viteza jucatorului:
Carspeed(playerid)
{
new Float:Speed[3];
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Speed[0],Speed[1],Speed[2]);
else GetPlayerVelocity(playerid, Speed[0], Speed[1], Speed[2]);
return floatround(1.61*floatsqroot(floatpower(floatabs(Speed[0]), 2.0) + floatpower(floatabs(Speed[1]), 2.0) + floatpower(floatabs(Speed[2]), 2.0)) * 99.38);
}