Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.87 KB | None | 0 0
  1. function:Vehicle_load()
  2. {
  3.     new
  4.         Float:pos[4],
  5.         color[2],
  6.         string[128],
  7.         id,
  8.         model,
  9.         bool:vehicle_spawned = false,
  10.         bool:delete_vehicle[MAX_VEHICLES_SERVER] = false,
  11.         vehicleid,
  12.         vCount = 0,
  13.         clan,
  14.         Cache:result;
  15.  
  16.     result = mysql_query(mysql, "SELECT * FROM "MYSQL_VEHICLE_TABLE" WHERE `Spawned` = '1' ORDER BY Job DESC");
  17.     if(cache_num_rows())
  18.     {
  19.         for(new i, count_nb = cache_get_row_count(); i < count_nb ; i++)
  20.         {
  21.             model = cache_get_field_content_int(i, "Model");
  22.             color[0] = cache_get_field_content_int(i, "Color1");
  23.             color[1] = cache_get_field_content_int(i, "Color2");
  24.             pos[0] = cache_get_field_content_float(i, "PosX");
  25.             pos[1] = cache_get_field_content_float(i, "PosY");
  26.             pos[2] = cache_get_field_content_float(i, "PosZ");
  27.             pos[3] = cache_get_field_content_float(i, "PosA");
  28.             clan =  cache_get_field_content_int(i, "Clan");
  29.  
  30.             vehicleid = AddStaticVehicleEx(model, pos[0], pos[1], pos[2], pos[3], color[0], color[1], -1);
  31.  
  32.             if(vehicleid != INVALID_VEHICLE_ID)
  33.             {
  34.                 Vehicle_infos[vehicleid][v_Model] = model;
  35.                 Vehicle_infos[vehicleid][v_Color1] = color[0];
  36.                 Vehicle_infos[vehicleid][v_Color2] = color[1];
  37.                 Vehicle_infos[vehicleid][v_Clan] = clan;
  38.                 Vehicle_infos[vehicleid][v_PosX] = pos[0];
  39.                 Vehicle_infos[vehicleid][v_PosY] = pos[1];
  40.                 Vehicle_infos[vehicleid][v_PosZ] = pos[2];
  41.                 Vehicle_infos[vehicleid][v_PosA] = pos[3];
  42.                 Vehicle_infos[vehicleid][v_Sql_Id] = cache_get_field_content_int(i, "id");
  43.                 Vehicle_infos[vehicleid][v_Price] = cache_get_field_content_int(i, "Price");
  44.                 Vehicle_infos[vehicleid][v_Locked] = cache_get_field_content_int(i, "Locked");
  45.                 Vehicle_infos[vehicleid][v_Mod][0] = cache_get_field_content_int(i, "Mod1");
  46.                 Vehicle_infos[vehicleid][v_Mod][1] = cache_get_field_content_int(i, "Mod2");
  47.                 Vehicle_infos[vehicleid][v_Mod][2] = cache_get_field_content_int(i, "Mod3");
  48.                 Vehicle_infos[vehicleid][v_Mod][3] = cache_get_field_content_int(i, "Mod4");
  49.                 Vehicle_infos[vehicleid][v_Mod][4] = cache_get_field_content_int(i, "Mod5");
  50.                 Vehicle_infos[vehicleid][v_Mod][5] = cache_get_field_content_int(i, "Mod6");
  51.                 Vehicle_infos[vehicleid][v_Mod][6] = cache_get_field_content_int(i, "Mod7");
  52.                 Vehicle_infos[vehicleid][v_Mod][7] = cache_get_field_content_int(i, "Mod8");
  53.                 Vehicle_infos[vehicleid][v_Mod][8] = cache_get_field_content_int(i, "Mod9");
  54.                 Vehicle_infos[vehicleid][v_Mod][9] = cache_get_field_content_int(i, "Mod10");
  55.                 Vehicle_infos[vehicleid][v_Mod][10] = cache_get_field_content_int(i, "Mod11");
  56.                 Vehicle_infos[vehicleid][v_Mod][11] = cache_get_field_content_int(i, "Mod12");
  57.                 Vehicle_infos[vehicleid][v_Mod][12] = cache_get_field_content_int(i, "Mod13");
  58.                 Vehicle_infos[vehicleid][v_Paintjob] = cache_get_field_content_int(i, "Paintjob");
  59.                 Vehicle_infos[vehicleid][v_Owner] = cache_get_field_content_int(i, "Owner");
  60.                 // Str
  61.                 cache_get_field_content(i, "Owner_Name", Vehicle_infos[vehicleid][v_Owner_Name], mysql, 24);
  62.                 cache_get_field_content(i, "Plate", Vehicle_infos[vehicleid][v_Plate], mysql, MAX_VEHICLE_PLATE);
  63.  
  64.                 ChangeVehiclePaintjob(vehicleid, Vehicle_infos[vehicleid][v_Paintjob]);
  65.                 SetVehicleNumberPlate(vehicleid, Vehicle_infos[vehicleid][v_Plate]);
  66.                 SetVehicleHealth(vehicleid, 1000.0);
  67.  
  68.                 Loop(comp, 13)
  69.                     AddVehicleComponent(vehicleid, Vehicle_infos[vehicleid][v_Mod][comp]);
  70.  
  71.                 Vehicle_infos[vehicleid][v_Park] = gettime();
  72.  
  73.                 Iter_Add(Vehicles, vehicleid);
  74.  
  75.                 new engine, lights, alarm, doors, bonnet, boot, objective;
  76.                 GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  77.                 SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, Vehicle_infos[vehicleid][v_Locked], bonnet, boot, objective);
  78.                 Vehicle_params(vehicleid);
  79.                
  80.                 new query[128];
  81.                 mysql_format(mysql, query, sizeof(query), "UPDATE "MYSQL_VEHICLE_TABLE" SET `Spawned` = '1' WHERE `id` = '%d' LIMIT 1", Vehicle_infos[vehicleid][v_Sql_Id]);
  82.                 mysql_tquery(mysql, query);
  83.                 query[0] = EOS;
  84.             }
  85.             else
  86.             {
  87.                 printf("[vehicle_load] La limite de véhicules sur le serveur (%d) a été atteinte.", MAX_VEHICLES);
  88.                 break;
  89.             }
  90.         }
  91.     }
  92.     cache_delete(result);
  93.  
  94.     // Vérification du propriétaire
  95.     foreach(new vehid : Vehicles)
  96.     {
  97.         if(Vehicle_infos[vehid][v_Owner] != 0)
  98.         {
  99.             mysql_format(mysql, string, sizeof(string),"SELECT `username` FROM `users` WHERE `id` = '%d' LIMIT 1", Vehicle_infos[vehid][v_Owner]);
  100.             result = mysql_query(mysql, string);
  101.  
  102.             if(!cache_num_rows()) {
  103.                 delete_vehicle[vehid] = true;
  104.                 vCount++;
  105.             }
  106.             cache_delete(result);
  107.         }
  108.     }
  109.     Loop(vehid, MAX_VEHICLES_SERVER)
  110.     {
  111.         if(delete_vehicle[vehid])
  112.             Vehicle_destroy(vehid);
  113.     }
  114.  
  115.     // Véhicule non spawn sur le script
  116.     result = mysql_query(mysql, "SELECT `id` FROM "MYSQL_VEHICLE_TABLE" WHERE `Spawned` = '1'");
  117.     if(cache_num_rows())
  118.     {
  119.         for(new i, count_nb = cache_get_row_count(); i < count_nb ; i++)
  120.         {
  121.             id = cache_get_row_int(i, 0);
  122.  
  123.             vehicle_spawned = false;
  124.             foreach(new vehid : Vehicles)
  125.             {
  126.                 if(Vehicle_infos[vehid][v_Sql_Id] == id) {
  127.                     vehicle_spawned = true;
  128.                     break;
  129.                 }
  130.             }
  131.             if(!vehicle_spawned)
  132.             {
  133.                 new query[128];
  134.                 mysql_format(mysql, query, sizeof(query), "UPDATE "MYSQL_VEHICLE_TABLE" SET `Spawned` = '0' WHERE `id` = '%d' LIMIT 1", id);
  135.                 mysql_tquery(mysql, query);
  136.                 query[0] = EOS;
  137.             }
  138.         }
  139.     }
  140.     cache_delete(result);
  141.  
  142.     if(vCount > 0)
  143.         printf("[vehicle_delete] %d vehicule(s) on(t) été(s) détruit(s) (propriétaire non trouvé dans la table users).", vCount);
  144.  
  145.     printf("Chargement de %d véhicules depuis "MYSQL_VEHICLE_TABLE".", Iter_Count(Vehicles));
  146.     return 1;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement