Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hook OnGameModeInit()
- {
- mysql_format(MySQL, query, sizeof(query), "SELECT * FROM "MYSQL_VEHICLE_TABLE" WHERE `Spawned` = '1' ORDER BY Job DESC");
- mysql_tquery(MySQL, query, "VEHICLE_Load", "d", playerid);
- return 1;
- }
- function:VEHICLE_Load()
- {
- if(!cache_get_row_count()) return false;
- new
- str_[10],
- Float:pos[4],
- color[2],
- Cache:result,
- bool:delete_vehicle[MAX_VEHICLES_SERVER] = false,
- vCount = 0,
- model;
- for(new i, j = cache_get_row_count(); i < j ; i++)
- {
- model = cache_get_field_content_int(i, "Model");
- color[0] = cache_get_field_content_int(i, "Color1");
- color[1] = cache_get_field_content_int(i, "Color2");
- pos[0] = cache_get_field_content_float(i, "PosX");
- pos[1] = cache_get_field_content_float(i, "PosY");
- pos[2] = cache_get_field_content_float(i, "PosZ");
- pos[3] = cache_get_field_content_float(i, "PosA");
- Vehicle_infos[i][v_Model] = model;
- Vehicle_infos[i][v_Color1] = color[0];
- Vehicle_infos[i][v_Color2] = color[1];
- Vehicle_infos[i][v_Clan] = clan;
- Vehicle_infos[i][v_PosX] = pos[0];
- Vehicle_infos[i][v_PosY] = pos[1];
- Vehicle_infos[i][v_PosZ] = pos[2];
- Vehicle_infos[i][v_PosA] = pos[3];
- Vehicle_infos[i][v_Sql_Id] = cache_get_field_content_int(i, "id");
- Vehicle_infos[i][v_Locked] = cache_get_field_content_int(i, "Locked");
- Vehicle_infos[i][v_State] = cache_get_field_content_int(i, "Statut");
- Vehicle_infos[i][v_Mod][0] = cache_get_field_content_int(i, "Mod1");
- Vehicle_infos[i][v_Mod][1] = cache_get_field_content_int(i, "Mod2");
- Vehicle_infos[i][v_Mod][2] = cache_get_field_content_int(i, "Mod3");
- Vehicle_infos[i][v_Mod][3] = cache_get_field_content_int(i, "Mod4");
- Vehicle_infos[i][v_Mod][4] = cache_get_field_content_int(i, "Mod5");
- Vehicle_infos[i][v_Mod][5] = cache_get_field_content_int(i, "Mod6");
- Vehicle_infos[i][v_Mod][6] = cache_get_field_content_int(i, "Mod7");
- Vehicle_infos[i][v_Mod][7] = cache_get_field_content_int(i, "Mod8");
- Vehicle_infos[i][v_Mod][8] = cache_get_field_content_int(i, "Mod9");
- Vehicle_infos[i][v_Mod][9] = cache_get_field_content_int(i, "Mod10");
- Vehicle_infos[i][v_Mod][10] = cache_get_field_content_int(i, "Mod11");
- Vehicle_infos[i][v_Mod][11] = cache_get_field_content_int(i, "Mod12");
- Vehicle_infos[i][v_Mod][12] = cache_get_field_content_int(i, "Mod13");
- Vehicle_infos[i][v_Paintjob] = cache_get_field_content_int(i, "Paintjob");
- Vehicle_infos[i][v_Owner] = cache_get_field_content_int(i, "Owner");
- // Str
- cache_get_field_content(i, "Owner_Name", Vehicle_infos[i][v_Owner_Name], mysql, 24);
- cache_get_field_content(i, "Plate", Vehicle_infos[i][v_Plate], mysql, MAX_VEHICLE_PLATE);
- ChangeVehiclePaintjob(i, Vehicle_infos[vehicleid][v_Paintjob]);
- SetVehicleNumberPlate(i, Vehicle_infos[vehicleid][v_Plate]);
- SetVehicleHealth(i, 1000.0);
- Loop(comp, 13)
- {
- AddVehicleComponent(i, Vehicle_infos[i][v_Mod][comp]);
- }
- Vehicle_infos[i][v_Park] = gettime();
- Iter_Add(Vehicles, i);
- new engine, lights, alarm, doors, bonnet, boot, objective;
- GetVehicleParamsEx(i, engine, lights, alarm, doors, bonnet, boot, objective);
- SetVehicleParamsEx(i, engine, lights, alarm, Vehicle_infos[i][v_Locked], bonnet, boot, objective);
- Vehicle_params(i);
- mysql_format(mysql, string, sizeof(string),"UPDATE "MYSQL_VEHICLE_TABLE" SET `Spawned` = '1' WHERE `id` = '%d' LIMIT 1", Vehicle_infos[i][v_Sql_Id]);
- mysql_pquery(mysql, string);
- }
- // Vérification du propriétaire
- foreach(new vehid : Vehicles)
- {
- if(Vehicle_infos[vehid][v_Owner] != 0)
- {
- mysql_format(mysql, string, sizeof(string),"SELECT `username` FROM `users` WHERE `id` = '%d' LIMIT 1", Vehicle_infos[vehid][v_Owner]);
- result = mysql_tquery(mysql, string);
- if(!cache_num_rows()) {
- delete_vehicle[vehid] = true;
- vCount++;
- }
- cache_delete(result);
- }
- }
- Loop(vehid, MAX_VEHICLES_SERVER)
- {
- if(delete_vehicle[vehid])
- Vehicle_destroy(vehid);
- }
- // Véhicule non spawn sur le script
- result = mysql_tquery(mysql, "SELECT `id` FROM "MYSQL_VEHICLE_TABLE" WHERE `Spawned` = '1'");
- if(cache_num_rows())
- {
- for(new i, count_nb = cache_get_row_count(); i < count_nb ; i++)
- {
- id = cache_get_row_int(i, 0);
- vehicle_spawned = false;
- foreach(new vehid : Vehicles)
- {
- if( Vehicle_infos[ vehid ][v_Sql_Id] == id) {
- vehicle_spawned = true;
- break;
- }
- }
- if(!vehicle_spawned)
- {
- mysql_format(mysql, string, sizeof(string),"UPDATE "MYSQL_VEHICLE_TABLE" SET `Spawned` = '0' WHERE `id` = '%d' LIMIT 1", id);
- mysql_pquery(mysql, string);
- }
- }
- }
- cache_delete(result);
- if(vCount > 0)
- printf("[vehicle_delete] %d vehicule(s) on(t) été(s) détruit(s) (propriétaire non trouvé dans la BDD 'users').", vCount);
- printf("Vehicles: %d loaded", Iter_Count(Vehicles));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement