04.01.2012, 13:49
hi Im developping a mysql vehicles systeme but im blocked :
there is my code :
I want change value of enum vehicle but I dont know how can in have id of the vehicle in the database.
I test to do GetPlayerVehicleID(playerid); but when i delete one vehicle in database , it don`t going to work;
so i wanna know how can I have the vehicles id database,
and sorry for bad english
there is my code :
PHP код:
new PlayerInfo[MAX_PLAYERS][pInfoE];
enum vInfoE // You could really name this anything.. Foo, pop, vehicle, vehicles whatever you like.
{
id,
owner[25],
model,
price,
col[2],
secured,
Float:pos[4],
}
new VehicleInfo[MAX_VEHICLES][vInfoE];
PHP код:
CMD:vcreate(playerid, params[]) // Create vehicle command, not Tested.
{
new vmodel,vcol1,vcol2,Query[200];
if(sscanf(params, "iii", vmodel,vcol1,vcol2)) return SendClientMessage(playerid, COLOR_ADMIN, "Usage: /vreate [Model] [col1] [col2]");
new Float:pPOS[4];
GetPlayerPos(playerid, pPOS[0], pPOS[1], pPOS[2]);
GetPlayerFacingAngle(playerid , pPOS[3]);
format(Query, sizeof(Query), "INSERT INTO vehicles (owner, model, price, col1, col2, secured, x, y, z, a) VALUES ('%s', %d, %d, %d, %d, 0, %f, %f, %f, %f);",DEFAULT_VEHICLE_OWNER, vmodel, DEFAULT_SELL_PRICE, vcol1, vcol2, pPOS[0], pPOS[1], pPOS[2], pPOS[3]);
mysql_query(Query);
CreateVehicle(vmodel,pPOS[0],pPOS[1],pPOS[2],pPOS[3],vcol1,vcol2,10);
format(Query, sizeof(Query), "Created an %d at x: %f y: %f z: %f a: %f);",vmodel ,pPOS[0], pPOS[1], pPOS[2], pPOS[3]);
SendClientMessage(playerid, COLOR_ADMIN, Query);
return 1;
}
CMD:vreload(playerid, params[]) // Reload's Vehicles
{
for(new i; i < MAX_VEHICLES; i++)
{
if (IsVehicleConnected(i)) return DestroyVehicle(i);
else { break; }
}
LoadVehicles();
SendClientMessage(playerid, COLOR_ADMIN, "Vehicle's reloaded");
return 1;
}
PHP код:
stock LoadVehicles() // You might want to make this an public so you could call it on an timer.
{
new query[255];
for(new i = 1; i < MAX_VEHICLES; i++) // Makes an loop so all vehicles get loaded.
{
format(query, sizeof(query), "SELECT * FROM vehicles WHERE id= %d", i);
mysql_query(query); // Querys the "Query" Variable.
mysql_store_result(); // Stores the result from Query
if(mysql_num_rows() == 0){ continue; } // Checks if theres anyrow.
mysql_fetch_row_format(query, "|");
sscanf(query, "e<p<|>is[25]iiiffff>", VehicleInfo[i]);
new str[128];
format(str,sizeof(str),"veh %s",VehicleInfo[i][owner]);
print(str);
CreateVehicle(VehicleInfo[i][model],VehicleInfo[i][pos][0],VehicleInfo[i][pos][1],VehicleInfo[id][pos][2],VehicleInfo[i][pos][3],VehicleInfo[i][col][0],VehicleInfo[i][col][1], 10);
}
}
I test to do GetPlayerVehicleID(playerid); but when i delete one vehicle in database , it don`t going to work;
so i wanna know how can I have the vehicles id database,
and sorry for bad english