02.02.2014, 19:00
pawn Код:
// Somewhere in your code
LoadPlayerCars(PlayerData[playerid][SQL_ID]);
stock LoadPlayerCars(ID)
{
new Query[128];
mysql_format(1, Query, sizeof(Query), "SELECT * FROM `cars` WHERE `ID` = '%d'", ID);
mysql_tquery(1, Query, "OnPlayerCarsLoaded", ""); // we won't pass any other variables to the callback
}
forward OnPlayerCarsLoaded();
public OnPlayerCarsLoaded()
{
// Get the amount of rows (cameras)
new Rows = cache_get_row_count(1);
// If there are any rows loaded, load data and create the cars
if (Rows >= 1)
{
// Loop through all rows
for (new idx; idx < Rows; idx++)
{
// Load the data
cache_get_field_content(idx, "Owner", Playercar[idx][owner], 1, 24);
cache_get_field_content(idx, "Plate", Playercar[idx][plate], 1, 16);
Playercar[idx][spawnx] = cache_get_field_content_float(idx, "X", 1);
Playercar[idx][spawny] = cache_get_field_content_float(idx, "Y", 1);
Playercar[idx][spawnz] = cache_get_field_content_float(idx, "Z", 1);
Playercar[idx][spawnr] = cache_get_field_content_float(idx, "Angle", 1);
Playercar[idx][modelid] = cache_get_field_content_int(idx, "Model", 1);
Playercar[idx][c1] = cache_get_field_content_int(idx, "Color1", 1);
Playercar[idx][c2] = cache_get_field_content_int(idx, "Color2", 1);
Playercar[idx][price] = cache_get_field_content_int(idx, "Price", 1);
Playercar[idx][car] = CreateVehicle(Playercar[idx][modelid], Playercar[idx][spawnx], Playercar[idx][spawny], Playercar[idx][spawnz], Playercar[idx][spawnr], Playercar[idx][c1], Playercar[idx][c2], 60);
}
}
printf("[mysql] Succesful. Fetched %i rows from the database.", Rows); //
return 1;
}
I assume your columns have these names:
- ID
- Owner
- Plate
- X
- Y
- Z
- Angle
- Model
- Color1
- Color2
- Price
Adjust them accordingly.