Advertisement
Guest User

Untitled

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