Hallo com ich habe ein Tank system eingefügt aber es funktioniert nicht richtig ?
ich will den Tank speichern funktioniert aber nicht ???
Das Laden des Tankes funktioniert aber das Speichern nicht aber wieso ? könnte mir jemand helfen ?
und wann sollte ich am besten den Tank in der Datenbank updaten ?
new tank[2000];
//Tacho enum
enum T_EC{
Text:Name,
Text:Zustand,
Text:Speed,
Text:besitz,
Text:ptank,
_switch
}
enum carEnum{
id_x,
model,
besitzer,
Float:c_x,
Float:c_y,
Float:c_z,
Float:c_r,
db_id,
pctank,
ckz
}
Tacho[i][ptank] = TextDrawCreate(503.000000, 385.000000, "Tank");
TextDrawBackgroundColor(Tacho[i][ptank], 255);
TextDrawFont(Tacho[i][ptank], 1);
TextDrawLetterSize(Tacho[i][ptank], 0.400000, 1.000000);
TextDrawColor(Tacho[i][ptank], -1);
TextDrawSetOutline(Tacho[i][ptank], 0);
TextDrawSetProportional(Tacho[i][ptank], 1);
TextDrawSetShadow(Tacho[i][ptank], 1);
TextDrawUseBox(Tacho[i][ptank], 1);
TextDrawBoxColor(Tacho[i][ptank], 136);
TextDrawTextSize(Tacho[i][ptank], 631.000000, 0.000000);
TextDrawSetSelectable(Tacho[i][ptank], 0);
for(new i=0; i<sizeof(tank); i++)
{
tank[i]=100;
}
for(new i = 0; i<MAX_PLAYERS; i++)
{
TextDrawHideForPlayer(i,Tacho[i][Name]);
TextDrawHideForPlayer(i,Tacho[i][Zustand]);
TextDrawHideForPlayer(i,Tacho[i][Speed]);
TextDrawHideForPlayer(i,Tacho[i][besitz]);
TextDrawHideForPlayer(i,Tacho[i][ptank]);
TextDrawDestroy(Tacho[i][Name]);
TextDrawDestroy(Tacho[i][Zustand]);
TextDrawDestroy(Tacho[i][Speed]);
TextDrawDestroy(Tacho[i][besitz]);
TextDrawDestroy(Tacho[i][ptank]);
}
new tanktimer = 0;
public sekunde()
{
new string[128];
tanktimer++;
if(tanktimer == 1/*30*/)
{
tanktimer = 0;
//Tank reduzieren
for(new i=1; i<sizeof(tank); i++)
{
if(!hatAutoMotor(i))continue;
if(!isMotorOn(i))continue;
tank[i]--;
if(tank[i]>0)continue;
stopMotor(i);
}
}
new getFormat[6];gettime(getFormat[0],getFormat[1],getFormat[2]),getdate(getFormat[3],getFormat[4],getFormat[5]);
format(string,128,"%02d:%02d:%02d",getFormat[0],getFormat[1], getFormat[2]);
TextDrawSetString(uhrzeitLabel,string),TextDrawShowForAll(uhrzeitLabel);
format(string,128,"%02d.%02d.%d",getFormat[5],getFormat[4],getFormat[3]);
return TextDrawSetString(datumLabel,string),TextDrawShowForAll(datumLabel);
}
//OnPlayerDisconnect
for(new i=0; i<sizeof(cInfo); i++)
{
if(cInfo[i][id_x]==0) continue;
if(cInfo[i][besitzer]!=sInfo[playerid][db_id])continue;
new query[256];
format(query,sizeof(query),"UPDATE autos SET tank='%i' WHERE id='%i'",tank[i],cInfo[i][db_id]);
mysql_function_query(dbhandle,query,false,"","");
DestroyVehicle(cInfo[i][id_x]);
cInfo[i][id_x]=0;
}
public OnPlayerCarsLoad(playerid)
{
new num_fields,num_rows;
cache_get_data(num_rows,num_fields,dbhandle);
if(!num_rows)return 1;
for(new i=0; i<num_rows; i++)
{
new id=getFreeCarID();
cInfo[id][model]=cache_get_field_content_int(i,"model",dbhandle);
cInfo[id][besitzer]=cache_get_field_content_int(i,"besitzer",dbhandle);
cInfo[id][c_x]=cache_get_field_content_float(i,"x",dbhandle);
cInfo[id][c_y]=cache_get_field_content_float(i,"y",dbhandle);
cInfo[id][c_z]=cache_get_field_content_float(i,"z",dbhandle);
cInfo[id][c_r]=cache_get_field_content_float(i,"r",dbhandle);
cInfo[id][pctank]=cache_get_field_content_int(i,"tank",dbhandle);
cache_get_field_content(i,"Kennzeichen",cInfo[id][ckz],dbhandle,20);
cInfo[id][db_id]=cache_get_field_content_int(i,"id",dbhandle);
cInfo[id][id_x]=CreateVehicle(cInfo[id][model],cInfo[id][c_x],cInfo[id][c_y],cInfo[id][c_z],cInfo[id][c_r],-1,-1,-1);
SetVehicleNumberPlate(cInfo[id][id_x],cInfo[id][ckz]);
tank[cInfo[id][id_x]] = (cInfo[id][pctank]);
}
return 1;
}
public TachoUpdate()
{
new string[128];
for(new i = 0; i<MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i))continue;
if(!IsPlayerInAnyVehicle(i))continue;
new veh = GetPlayerVehicleID(i),str[64],Float:hp,speed = GetVehicleSpeed(veh);
new vehicleid;
formatEx(str,"Speed: %d KM/H", speed);
TextDrawSetString(Tacho[i][Speed],str);
GetVehicleHealth(veh, hp);
hp = floatmul(floatdiv(100,750),(hp-250));
if(hp<=0.0){hp=0.0;}
formatEx(str,"Zustand: %.0f",hp);
TextDrawSetString(Tacho[i][Zustand],str);
formatEx(str,"%s", VehicleFriendlyNames[GetVehicleModel(veh)-400]), TextDrawSetString(Tacho[i][Name],str);
TextDrawSetString(Tacho[i][besitz],str);
formatEx(str,"%s", GetAutoBesitzer(i,vehicleid),TextDrawSetString(Tacho[i][besitz],str));
new vID = GetPlayerVehicleID(i);
format(string,sizeof(string),"Tank: %i Liter",tank[vID]);
TextDrawSetString(Tacho[i][ptank],string);
}
return 1;
}