28.07.2012, 16:21
Hey there, I'm creating an all in one gamemode, with housesystem, admin system, login, etc,etc.
But as you can see in the next code, it's looping ALL the vehicles, even if it does not exists.
So how can I make it that it only loads the rows that are in there, and if he doesn't find any more, it stops?
But as you can see in the next code, it's looping ALL the vehicles, even if it does not exists.
So how can I make it that it only loads the rows that are in there, and if he doesn't find any more, it stops?
pawn Код:
// Loop all personal vehicles
stock LoopVehicles()
{
new query[500], savestring[200], Cars[128];
for(new vid = 1; vid < MAX_VEHICLES; vid++)
{
format(query, sizeof(query), "SELECT * FROM Vehicles WHERE vID='%i'", vid);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query, "|"))
{
mysql_fetch_field_row(savestring, "vID"); VehInfo[vid][vID] = strval(savestring);
format(VehInfo[vid][Owner], MAX_PLAYER_NAME, "%s", mysql_fetch_field_row(savestring, "Owner"));
//mysql_fetch_field_row(savestring, "Owner"); format(VehInfo[vid][Owner], 24, "%s",savestring);
mysql_fetch_field_row(savestring, "SpawnX"); VehInfo[vid][SpawnX] = strval(savestring);
mysql_fetch_field_row(savestring, "SpawnY"); VehInfo[vid][SpawnY] = strval(savestring);
mysql_fetch_field_row(savestring, "SpawnZ"); VehInfo[vid][SpawnZ] = strval(savestring);
mysql_fetch_field_row(savestring, "SpawnAngle"); VehInfo[vid][SpawnAngle] = strval(savestring);
mysql_fetch_field_row(savestring, "Model"); VehInfo[vid][Model] = strval(savestring);
mysql_fetch_field_row(savestring, "BelongsTo"); VehInfo[vid][BelongsToHouse] = strval(savestring);
mysql_fetch_field_row(savestring, "Price"); VehInfo[vid][Price] = strval(savestring);
mysql_fetch_field_row(savestring, "SellPrice"); VehInfo[vid][SellPrice] = strval(savestring);
mysql_fetch_field_row(savestring, "color1"); VehInfo[vid][color1] = strval(savestring);
mysql_fetch_field_row(savestring, "color2"); VehInfo[vid][color2] = strval(savestring);
}
mysql_free_result();
CreateVehicle(VehInfo[vid][Model], VehInfo[vid][SpawnX], VehInfo[vid][SpawnY], VehInfo[vid][SpawnZ], VehInfo[vid][SpawnAngle], VehInfo[vid][color1], VehInfo[vid][color2], 200);
format(Cars, sizeof(Cars), "{ff6600}%s owner:\n%s",GetVehicleFriendlyName(vid), VehInfo[vid][Owner]);
VehLabel[vid] = Create3DTextLabel(Cars, 0xFFFFFFFF, 0.0, 0.0, 0.0, 50.0, -1, 0);
Attach3DTextLabelToVehicle(VehLabel[vid], vid, 0.0, 0.0, 0.4);
}
return 1;
}