Hallo,
habe jeweils ein Problem mit meiner Tank & Kilometerstand Funktion.
An meiner Tank Funktion wird die Tank-Menge der Privatfahrzeuge zwar in die Variable ausgelesen, aber im TextDraw ( Tacho ) wird mir ein leerer Tank gezeigt.
Sowie bei meinem /motor Befehl, man kann logischer Weise nämlich nur den Motor starten mit einem gefüllten Tank, jedoch steht auch dort, dass mein Tank leer wäre.
In der MySQL Spalte des Fahrzeugs steht jedoch 40, also 40 Liter im Tank.
Habe mir es auch schon printen lassen, dort steht auch in der Variable 40.
Jedoch tritt dieses Problem bei den Polizeifahrzeugen nicht auf, die separat geladen werden.
forward OnPlayerVehiclesLoad(playerid);
public OnPlayerVehiclesLoad(playerid)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
new rows;
rows = cache_num_rows();
for(new i=0; i < rows; i++)
{
VehicleInfo[i][v_Police] = bool:cache_get_field_content_int(i, "police", handle);
if(VehicleInfo[i][v_Police] == true)continue;
VehicleInfo[i][v_ID] = cache_get_field_content_int(i, "id", handle);
VehicleInfo[i][v_Besitzer] = cache_get_field_content_int(i, "besitzer", handle);
VehicleInfo[i][v_X] = cache_get_field_content_float(i, "x", handle), VehicleInfo[i][v_X] = VehicleInfo[i][v_KMX];
VehicleInfo[i][v_Y] = cache_get_field_content_float(i, "y", handle), VehicleInfo[i][v_Y] = VehicleInfo[i][v_KMY];
VehicleInfo[i][v_Z] = cache_get_field_content_float(i, "z", handle), VehicleInfo[i][v_Z] = VehicleInfo[i][v_KMZ];
VehicleInfo[i][v_R] = cache_get_field_content_float(i, "r", handle);
VehicleInfo[i][v_Health] = cache_get_field_content_float(i, "health", handle);
VehicleInfo[i][v_Tank] = cache_get_field_content_int(i, "liter", handle);
VehicleInfo[i][v_Sirene] = bool:cache_get_field_content_int(i, "siren", handle);
VehicleInfo[i][v_Model] = cache_get_field_content_int(i, "model", handle);
VehicleInfo[i][v_Farbe] = cache_get_field_content_int(i, "farbe", handle);
VehicleInfo[i][v_Farbe2] = cache_get_field_content_int(i, "farbe2", handle);
VehicleInfo[i][v_Kilometer] = cache_get_field_content_int(i, "kmstand", handle);
VehicleInfo[i][v_Bombe] = bool:cache_get_field_content_int(i, "bombe", handle);
VehicleInfo[i][v_WeelsKugelsicher] = bool:cache_get_field_content_int(i, "weelskugelsicher", handle);
VehicleInfo[i][v_Panzerglas] = bool:cache_get_field_content_int(i, "panzerglas", handle);
//printf("Health: %0.2f | Tank: %d | Sirene: %d | Farbe: %d | Farbe: %d | Kilometer: %d | Bombe: %d | Kugelsicher: %d | Panzerglas: %d",
//VehicleInfo[i][v_Health], VehicleInfo[i][v_Tank], VehicleInfo[i][v_Sirene], VehicleInfo[i][v_Farbe], VehicleInfo[i][v_Farbe2], VehicleInfo[i][v_Kilometer], VehicleInfo[i][v_Bombe], VehicleInfo[i][v_WeelsKugelsicher], VehicleInfo[i][v_Panzerglas]);
if(VehicleInfo[i][v_Model] >= 400 && VehicleInfo[i][v_Model] <= 611)
{
VehicleInfo[i][v_Objekt] = CreateVehicle(VehicleInfo[i][v_Model], VehicleInfo[i][v_X], VehicleInfo [i][v_Y], VehicleInfo[i][v_Z], VehicleInfo[i][v_R], VehicleInfo[i][v_Farbe], VehicleInfo[i][v_Farbe2], -1, VehicleInfo[i][v_Sirene]);
if(VehicleInfo[i][v_Health] > 250.99) SetVehicleHealth(VehicleInfo[i][v_Objekt], VehicleInfo[i][v_Health]);
else SetVehicleHealth(VehicleInfo[i][v_Objekt], 1000);
GetVehicleParamsEx(VehicleInfo[i][v_Objekt], engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(VehicleInfo[i][v_Objekt], engine, lights, alarm, 1, bonnet, boot, objective);
}
else printf("[FEHLER] Fahrzeug-Model %d existiert nicht (DB-ID: %d).", VehicleInfo[i][v_Model], i);
}
return 1;
}
Alles anzeigen
forward TachoTimer();
public TachoTimer()
{
for(new i=0; i < MAX_PLAYERS; i++)
{
new vID = GetPlayerVehicleID(i);
if(!IsPlayerConnected(i) || PlayerInfo[i][p_LoggedIn] != true)continue;
if(!IsPlayerInAnyVehicle(i))continue;
new tacho[256], Float:hp;
GetVehicleHealth(vID, hp);
VehicleInfo[vID][v_Kilometer] += e_GetDistance(vID);
format(tacho, sizeof(tacho), "%s~n~Geschwindigkeit: %dkm/h~n~Kilometerstand: %d.%dkm~n~Treibstoff: %dl~n~Schaden: %0.2f", VehicleNames[GetVehicleModel(vID)-400], GetPlayerSpeed(i), VehicleInfo[vID][v_Kilometer]/1000, VehicleInfo[vID][v_Kilometer]%1000, VehicleInfo[vID][v_Tank], hp);
PlayerTextDrawSetString(i, Tacho[i][0], tacho);
if(VehicleEngineOn(vID))PlayerTextDrawSetString(i, Tacho[i][2], "~g~Motor");
else PlayerTextDrawSetString(i, Tacho[i][2], "~w~Motor");
if(VehicleLightsOn(vID))PlayerTextDrawSetString(i, Tacho[i][3], "~g~Licht");
else PlayerTextDrawSetString(i, Tacho[i][3], "~w~Licht");
if(VehicleDoorLocked(vID))PlayerTextDrawSetString(i, Tacho[i][4], "~g~Tueren");
else PlayerTextDrawSetString(i, Tacho[i][4], "~w~Tueren");
GetVehiclePos(vID, VehicleInfo[vID][v_KMX], VehicleInfo[vID][v_KMY], VehicleInfo[vID][v_KMZ]);
}
return 1;
}
Alles anzeigen
Dann kommen wir mal zum zweiten Problem.
Hierbei wird erst gar nicht die Kilometer-Strecke gespeichert.
Aber im Tacho steht eine Strecke, und zwar die vom 0 Punkt bis zur Position des Fahrzeuges.
Wenn ihr versteht was ich meine.
forward SaveAllVehicles();
public SaveAllVehicles()
{
new query[256];
for(new i=0; i < MAX_VEHICLES; i++)
{
if(VehicleInfo[i][v_X] == 0.0 && VehicleInfo[i][v_Y] == 0.0 && VehicleInfo[i][v_Z] == 0.0)continue;
if(VehicleInfo[i][v_Model] >= 400 && VehicleInfo[i][v_Model] <= 611)
{
GetVehiclePos(VehicleInfo[i][v_Objekt], VehicleInfo[i][v_X], VehicleInfo[i][v_Y], VehicleInfo[i][v_Z]);
GetVehicleZAngle(VehicleInfo[i][v_Objekt], VehicleInfo[i][v_R]);
GetVehicleHealth(VehicleInfo[i][v_Objekt], VehicleInfo[i][v_Health]);
format(query, sizeof(query), "UPDATE fahrzeuge SET x=%f, y=%f, z=%f, r=%f, health=%f, model=%d, liter=%d, farbe=%d, farbe2=%d, bombe=%d, police=%d, weelskugelsicher=%d, panzerglas=%d, besitzer=%d, exp=%d, kmstand=%d WHERE id=%d",
VehicleInfo[i][v_X], VehicleInfo[i][v_Y], VehicleInfo[i][v_Z], VehicleInfo[i][v_R], VehicleInfo[i][v_Health], VehicleInfo[i][v_Model], VehicleInfo[i][v_Tank], VehicleInfo[i][v_Farbe], VehicleInfo[i][v_Farbe2],
VehicleInfo[i][v_Bombe], VehicleInfo[i][v_Police], VehicleInfo[i][v_WeelsKugelsicher], VehicleInfo[i][v_Panzerglas], VehicleInfo[i][v_Besitzer], VehicleInfo[i][v_EXP], VehicleInfo[i][v_Kilometer], VehicleInfo[i][v_ID]);
mysql_tquery(handle, query);
}
}
return 1;
}
Alles anzeigen
stock e_GetDistance(vehicleid)
{
new Float:x2, Float:y2, Float:z2, Float:value;
GetVehiclePos(vehicleid, x2, y2, z2);
value = floatsqroot(floatpower(floatabs(floatsub(x2, VehicleInfo[vehicleid][v_KMX])), 2)+floatpower(floatabs(floatsub(y2, VehicleInfo[vehicleid][v_KMY])), 2)+floatpower(floatabs(floatsub(z2, VehicleInfo[vehicleid][v_KMZ])), 2));
return floatround(value);
}
Das sollte alles notwendige sein.
Ich hoffe ihr könnt mir helfen.