08.06.2015, 18:09
Send one query and retrieve the data with a loop. Also in cache_get_field_content, you need to specify the length of the enum-array.
PHP код:
LoadVehicles()
{
mysql_tquery(mysql, "SELECT * FROM Veicolo", "LoadingVehicles", "");
return 1;
}
forward LoadingVehicles();
public LoadingVehicles()
{
new rows = cache_get_row_count();
printf("Server: %d veicoli sono stati caricati!", rows);
for (new id; id != rows; ++id)
{
if (id >= sizeof (Veicolo)) break;
Veicolo[id][ID] = cache_get_field_content_int(id, "ID");
Veicolo[id][Creato] = cache_get_field_content_int(id, "Creato");
Veicolo[id][Modello] = cache_get_field_content_int(id, "Modello");
Veicolo[id][Costo] = cache_get_field_content_int(id, "Costo");
Veicolo[id][Creato] = cache_get_field_content_int(id, "Creato");
Veicolo[id][Colore_uno] = cache_get_field_content_int(id, "Colore_uno");
Veicolo[id][Colore_due] = cache_get_field_content_int(id, "Colore_due");
Veicolo[id][Chiuso] = cache_get_field_content_int(id, "Chiuso");
Veicolo[id][Motore] = cache_get_field_content_int(id, "Motore");
Veicolo[id][Fari] = cache_get_field_content_int(id, "Fari");
Veicolo[id][Bagagliaio] = cache_get_field_content_int(id, "Bagagliaio");
Veicolo[id][Cofano] = cache_get_field_content_int(id, "Cofano");
Veicolo[id][Carburante] = cache_get_field_content_int(id, "Carburante");
Veicolo[id][Acquistato] = cache_get_field_content_int(id, "Acquistato");
Veicolo[id][Distrutto] = cache_get_field_content_int(id, "Distrutto");
Veicolo[id][DiFazione] = cache_get_field_content_int(id, "Fazione");
Veicolo[id][Sirena] = cache_get_field_content_int(id, "Sirena");
Veicolo[id][LimiteCarburante] = cache_get_field_content_int(id, "LimiteCarburante");
Veicolo[id][vX] = cache_get_field_content_float(id, "Posizione_X");
Veicolo[id][vY] = cache_get_field_content_float(id, "Posizione_Y");
Veicolo[id][vZ] = cache_get_field_content_float(id, "Posizione_Z");
Veicolo[id][vA] = cache_get_field_content_float(id, "Posizione_A");
Veicolo[id][rX] = cache_get_field_content_float(id, "Respawn_X");
Veicolo[id][rY] = cache_get_field_content_float(id, "Respawn_Y");
Veicolo[id][rZ] = cache_get_field_content_float(id, "Respawn_Z");
Veicolo[id][rA] = cache_get_field_content_float(id, "Respawn_A");
Veicolo[id][vHP] = cache_get_field_content_float(id, "HP");
cache_get_field_content(id, "Proprietario", Veicolo[id][Proprietario], mysql, /* SIZE OF Proprietario HERE */);
if(Veicolo[id][Creato] == 1)
{
Veicolo[id][vO] = CreateVehicle(Veicolo[id][Modello], Veicolo[id][vX], Veicolo[id][vY], Veicolo[id][vZ], Veicolo[id][vA], Veicolo[id][Colore_uno], Veicolo[id][Colore_due], -1, Veicolo[id][Sirena]);
}
}
return 1;
}