Speichern:
SaveVehicle(i)
{
if(i < 0 || i >= sizeof(VehInfo)) return 1;
new query[512];
mysql_format(handle, query, sizeof(query), "UPDATE Auto SET ModellID = '%d', Fraktion = '%d', PosX = '%f', PosY = '%f', PosZ = '%f', PosR = '%f', Abgeschleppt = '%d', inADAC = '%d', Name = '%e', Grund = '%e', Preis = '%d', ",
VehInfo[i][ModellID], VehInfo[i][Fraktion], VehInfo[i][PosX], VehInfo[i][PosY],VehInfo[i][PosZ],VehInfo[i][PosR],VehInfo[i][Abgeschleppt],VehInfo[i][inADAC],VehInfo[i][Named],VehInfo[i][Grund],VehInfo[i][Preis]);
mysql_format(handle, query, sizeof(query), "%sNewX = '%f', NewY = '%f', NewZ = '%f', NewR = '%f', Farbe1 = '%d', Farbe2 = '%d', Sirene = '%d', eSirene = '%d' WHERE ID = '%d'",query,
VehInfo[i][NewX],VehInfo[i][NewY],VehInfo[i][NewZ],VehInfo[i][NewR],VehInfo[i][Farbe1],VehInfo[i][Farbe2],VehInfo[i][Sirene],VehInfo[i][eSirene],i);
mysql_tquery(handle, query);
printf("query: %s", query);
return 1;
}
SaveVehicles()
{
for(new i=0; i < sizeof(VehInfo); i++) SaveVehicle(i);
return 1;
}
Laden:
forward LoadVehicles();
public LoadVehicles()
{
mysql_tquery(handle, "SELECT * FROM Auto", "LoadVehicles_Data", "");
return 1;
}
forward LoadVehicles_Data();
public LoadVehicles_Data()
{
new query[512], missing, str[64], rows, id;
rows = cache_num_rows();
for(new i=0; i < sizeof(FrakAutos); i++)
{
if(i < rows) id = cache_get_field_content_int(i-missing, "ID");
else id = -1;
if(id != i)
{
mysql_format(handle, query, sizeof(query), "INSERT INTO Auto (ID, ModellID, PosX, PosY, PosZ, PosR, Farbe1, Farbe2, Fraktion, Sirene, eSirene) VALUES ('%d', '%d', '%f', '%f', '%f', '%f', '%d', '%d', '%d', '%d', '%d')", i,
FrakAutos[i][ModellID],FrakAutos[i][PosX],FrakAutos[i][PosY],FrakAutos[i][PosZ],FrakAutos[i][PosR],FrakAutos[i][Farbe1],FrakAutos[i][Farbe2],FrakAutos[i][Fraktionp], FrakAutos[i][Sirene]);
mysql_tquery(handle, query);
VehInfo[i][ModellID] = FrakAutos[i][ModellID];
VehInfo[i][Fraktion] = FrakAutos[i][Fraktionp];
VehInfo[i][PosX] = FrakAutos[i][PosX];
VehInfo[i][PosY] = FrakAutos[i][PosY];
VehInfo[i][PosZ] = FrakAutos[i][PosZ];
VehInfo[i][PosR] = FrakAutos[i][PosR];
VehInfo[i][Farbe1] = FrakAutos[i][Farbe1];
VehInfo[i][Farbe2] = FrakAutos[i][Farbe2];
missing++;
}
else
{
VehInfo[i][ModellID] = cache_get_field_content_int(i-missing, "ModellID");
VehInfo[i][Fraktion] = cache_get_field_content_int(i-missing, "Fraktion");
VehInfo[i][PosX] = cache_get_field_content_float(i-missing, "PosX");
VehInfo[i][PosY] = cache_get_field_content_float(i-missing, "PosY");
VehInfo[i][PosZ] = cache_get_field_content_float(i-missing, "PosZ");
VehInfo[i][PosR] = cache_get_field_content_float(i-missing, "PosR");
VehInfo[i][Abgeschleppt] = cache_get_field_content_int(i-missing, "Abgeschleppt");
VehInfo[i][inADAC] = cache_get_field_content_int(i-missing, "inADAC");
VehInfo[i][Preis] = cache_get_field_content_int(i-missing, "Preis");
cache_get_field_content(i-missing, "Grund", str);
format(VehInfo[i][Grund], 64, str);
cache_get_field_content(i-missing, "Name", str);
format(VehInfo[i][Named], 64, str);
VehInfo[i][NewX] = cache_get_field_content_float(i-missing, "NewX");
VehInfo[i][NewY] = cache_get_field_content_float(i-missing, "NewY");
VehInfo[i][NewZ] = cache_get_field_content_float(i-missing, "NewZ");
VehInfo[i][NewR] = cache_get_field_content_float(i-missing, "NewR");
VehInfo[i][Farbe1] = cache_get_field_content_int(i-missing, "Farbe1");
VehInfo[i][Farbe2] = cache_get_field_content_int(i-missing, "Farbe2");
VehInfo[i][Sirene] = cache_get_field_content_int(i-missing, "Sirene");
VehInfo[i][eSirene] = cache_get_field_content_int(i-missing, "eSirene");
}
if(VehInfo[i][Abgeschleppt] == 1)
{
VehInfo[i][veh_ID] = CreateVehicle(VehInfo[i][ModellID], VehInfo[i][NewX], VehInfo[i][NewY], VehInfo[i][NewZ], VehInfo[i][NewR], VehInfo[i][Farbe1], VehInfo[i][Farbe2],-1, VehInfo[i][Sirene]);
}
else
{
VehInfo[i][veh_ID] = CreateVehicle(VehInfo[i][ModellID], VehInfo[i][PosX], VehInfo[i][PosY], VehInfo[i][PosZ], VehInfo[i][PosR], VehInfo[i][Farbe1], VehInfo[i][Farbe2],-1,VehInfo[i][Sirene]);
}
}
return 1;
}