Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function:Vehicle_load()
- {
- new
- Float:pos[4],
- color[2],
- string[128],
- id,
- model,
- bool:vehicle_spawned = false,
- bool:delete_vehicle[MAX_VEHICLES_SERVER] = false,
- vehicleid,
- vCount = 0,
- clan,
- Cache:result;
- result = mysql_query(mysql, "SELECT * FROM "MYSQL_VEHICLE_TABLE" WHERE `Spawned` = '1' ORDER BY Job DESC");
- if(cache_num_rows())
- {
- for(new i, count_nb = cache_get_row_count(); i < count_nb ; 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");
- clan = cache_get_field_content_int(i, "Clan");
- vehicleid = AddStaticVehicleEx(model, pos[0], pos[1], pos[2], pos[3], color[0], color[1], -1);
- if(vehicleid != INVALID_VEHICLE_ID)
- {
- Vehicle_infos[vehicleid][v_Model] = model;
- Vehicle_infos[vehicleid][v_Color1] = color[0];
- Vehicle_infos[vehicleid][v_Color2] = color[1];
- Vehicle_infos[vehicleid][v_Clan] = clan;
- Vehicle_infos[vehicleid][v_PosX] = pos[0];
- Vehicle_infos[vehicleid][v_PosY] = pos[1];
- Vehicle_infos[vehicleid][v_PosZ] = pos[2];
- Vehicle_infos[vehicleid][v_PosA] = pos[3];
- Vehicle_infos[vehicleid][v_Sql_Id] = cache_get_field_content_int(i, "id");
- Vehicle_infos[vehicleid][v_Price] = cache_get_field_content_int(i, "Price");
- Vehicle_infos[vehicleid][v_Locked] = cache_get_field_content_int(i, "Locked");
- Vehicle_infos[vehicleid][v_Mod][0] = cache_get_field_content_int(i, "Mod1");
- Vehicle_infos[vehicleid][v_Mod][1] = cache_get_field_content_int(i, "Mod2");
- Vehicle_infos[vehicleid][v_Mod][2] = cache_get_field_content_int(i, "Mod3");
- Vehicle_infos[vehicleid][v_Mod][3] = cache_get_field_content_int(i, "Mod4");
- Vehicle_infos[vehicleid][v_Mod][4] = cache_get_field_content_int(i, "Mod5");
- Vehicle_infos[vehicleid][v_Mod][5] = cache_get_field_content_int(i, "Mod6");
- Vehicle_infos[vehicleid][v_Mod][6] = cache_get_field_content_int(i, "Mod7");
- Vehicle_infos[vehicleid][v_Mod][7] = cache_get_field_content_int(i, "Mod8");
- Vehicle_infos[vehicleid][v_Mod][8] = cache_get_field_content_int(i, "Mod9");
- Vehicle_infos[vehicleid][v_Mod][9] = cache_get_field_content_int(i, "Mod10");
- Vehicle_infos[vehicleid][v_Mod][10] = cache_get_field_content_int(i, "Mod11");
- Vehicle_infos[vehicleid][v_Mod][11] = cache_get_field_content_int(i, "Mod12");
- Vehicle_infos[vehicleid][v_Mod][12] = cache_get_field_content_int(i, "Mod13");
- Vehicle_infos[vehicleid][v_Paintjob] = cache_get_field_content_int(i, "Paintjob");
- Vehicle_infos[vehicleid][v_Owner] = cache_get_field_content_int(i, "Owner");
- // Str
- cache_get_field_content(i, "Owner_Name", Vehicle_infos[vehicleid][v_Owner_Name], mysql, 24);
- cache_get_field_content(i, "Plate", Vehicle_infos[vehicleid][v_Plate], mysql, MAX_VEHICLE_PLATE);
- ChangeVehiclePaintjob(vehicleid, Vehicle_infos[vehicleid][v_Paintjob]);
- SetVehicleNumberPlate(vehicleid, Vehicle_infos[vehicleid][v_Plate]);
- SetVehicleHealth(vehicleid, 1000.0);
- Loop(comp, 13)
- AddVehicleComponent(vehicleid, Vehicle_infos[vehicleid][v_Mod][comp]);
- Vehicle_infos[vehicleid][v_Park] = gettime();
- Iter_Add(Vehicles, vehicleid);
- new engine, lights, alarm, doors, bonnet, boot, objective;
- GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
- SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, Vehicle_infos[vehicleid][v_Locked], bonnet, boot, objective);
- Vehicle_params(vehicleid);
- new query[128];
- mysql_format(mysql, query, sizeof(query), "UPDATE "MYSQL_VEHICLE_TABLE" SET `Spawned` = '1' WHERE `id` = '%d' LIMIT 1", Vehicle_infos[vehicleid][v_Sql_Id]);
- mysql_tquery(mysql, query);
- query[0] = EOS;
- }
- else
- {
- printf("[vehicle_load] La limite de véhicules sur le serveur (%d) a été atteinte.", MAX_VEHICLES);
- break;
- }
- }
- }
- cache_delete(result);
- // 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_query(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_query(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)
- {
- new query[128];
- mysql_format(mysql, query, sizeof(query), "UPDATE "MYSQL_VEHICLE_TABLE" SET `Spawned` = '0' WHERE `id` = '%d' LIMIT 1", id);
- mysql_tquery(mysql, query);
- query[0] = EOS;
- }
- }
- }
- 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 table users).", vCount);
- printf("Chargement de %d véhicules depuis "MYSQL_VEHICLE_TABLE".", Iter_Count(Vehicles));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement