Advertisement
Jasit_Legandary

vehicleinfo

Aug 31st, 2021 (edited)
563
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <YSI_Coding\y_hooks>
  2. #include <YSI_Coding\y_timers>    
  3.  
  4. new CheckVehID[MAX_PLAYERS];
  5.  
  6. enum vinfo
  7. {
  8.     ID,
  9.     v_model,
  10.     Float:v_Pos[4],
  11.     v_color1,
  12.     v_color2,
  13.  
  14. }
  15. new VehicleInfo[MAX_VEHICLES_INFO][vinfo];
  16.  
  17. public OnGameModeInit(){
  18.  
  19.     mysql_tquery(g_SQL, "SELECT * FROM `vehicleinfo`", "Load_Vehicleinfo");
  20.     return 1;
  21. }
  22. forward Load_Vehicleinfo();
  23. public Load_Vehicleinfo()
  24. {
  25.     new rows = cache_num_rows();
  26.     new id,loaded;
  27.     if(rows)
  28.     {
  29.         while(loaded < rows)
  30.         {
  31.  
  32.             cache_get_value_name_int(loaded,"ID",id);
  33.             cache_get_value_name_int(loaded,"v_model",VehicleInfo[id][v_model]);
  34.  
  35.             cache_get_value_name_float(loaded,"v_Posx",VehicleInfo[id][v_Pos][0]);
  36.             cache_get_value_name_float(loaded,"v_Posy",VehicleInfo[id][v_Pos][1]);
  37.             cache_get_value_name_float(loaded,"v_Posz",VehicleInfo[id][v_Pos][2]);
  38.             cache_get_value_name_float(loaded,"v_Posa",VehicleInfo[id][v_Pos][3]);
  39.  
  40.             cache_get_value_name_int(loaded,"v_color1",VehicleInfo[id][v_color1]);
  41.             cache_get_value_name_int(loaded,"v_color2",VehicleInfo[id][v_color2]);
  42.  
  43.             VehicleInfo[id][ID] = CreateVehicle(VehicleInfo[id][v_model], VehicleInfo[id][v_Pos][0], VehicleInfo[id][v_Pos][1],VehicleInfo[id][v_Pos][2], VehicleInfo[id][v_Pos][3], VehicleInfo[id][v_color1], VehicleInfo[id][v_color2], 0);
  44.             if(!VehicleInfo[id][ID])
  45.             {
  46.                 VehicleInfo[id][ID] = true;
  47.             }
  48.             loaded ++;
  49.         }
  50.  
  51.     }
  52.     printf("[SERVER]: %i VehicleInfo were loaded from \"%s\" database...", rows, MYSQL_DATABASE);
  53. }
  54.  
  55.  
  56. CMD:savevehinfo(playerid, cmdtext[])
  57. {
  58.     new vehicleid = GetPlayerVehicleID(playerid);
  59.     if(Player[playerid][Admins] <= 0)
  60.         return SendClientMessage(playerid, YELLOW, "[!]: {F81414}คุณไม่ใช่แอดมิน");
  61.     new string[256];
  62.     if(IsPlayerConnected(playerid))
  63.     {
  64.         if(IsPlayerInAnyVehicle(playerid)){
  65.             new Float:X,Float:Y,Float:Z, Float:A;
  66.             GetVehiclePos(vehicleid, X, Y, Z);
  67.             GetVehicleZAngle(vehicleid, A);
  68.             for(new i = 1; i < MAX_VEHICLES_INFO; i++)
  69.             {
  70.                 if(!VehicleInfo[i][ID])
  71.                 {
  72.                     VehicleInfo[i][ID] = true;
  73.                     VehicleInfo[i][v_model] = GetVehicleModel(GetPlayerVehicleID(playerid));
  74.                     VehicleInfo[i][v_Pos][0] = X;
  75.                     VehicleInfo[i][v_Pos][1] = Y;
  76.                     VehicleInfo[i][v_Pos][2] = Z;
  77.                     VehicleInfo[i][v_Pos][3] = A;
  78.                     VehicleInfo[i][v_color1] = 1;
  79.                     VehicleInfo[i][v_color2] = 2;
  80.                     format(string, sizeof(string), "คุณได้ซื้อรถ (%d)",i);
  81.                     SendClientMessage(playerid, ORANGE, string);
  82.  
  83.  
  84.                     new query[256];
  85.                     mysql_format(g_SQL, query, sizeof(query), "INSERT INTO vehicleinfo (ID, v_model, v_Posx, v_Posy, v_Posz, v_Posa, v_color1, v_color2) VALUES (%d,%d, %f, %f, %f,%f,%d,%d)", i, VehicleInfo[i][v_model],
  86.                     VehicleInfo[i][v_Pos][0],
  87.                     VehicleInfo[i][v_Pos][1],
  88.                     VehicleInfo[i][v_Pos][2],
  89.                     VehicleInfo[i][v_Pos][3],
  90.                     VehicleInfo[i][v_color1],
  91.                     VehicleInfo[i][v_color2]);
  92.                     mysql_tquery(g_SQL, query);
  93.  
  94.                    
  95.                     DestroyVehicle(vehicleid);
  96.                     VehicleInfo[i][ID] =  CreateVehicle(VehicleInfo[i][v_model], VehicleInfo[i][v_Pos][0], VehicleInfo[i][v_Pos][1],VehicleInfo[i][v_Pos][2], VehicleInfo[i][v_Pos][3], 1, 1, 0);
  97.                     PutPlayerInVehicle(playerid, VehicleInfo[i][ID], 0);
  98.                     return 1;
  99.                 }
  100.             }
  101.         }
  102.         else SendClientMessage(playerid, YELLOW, "[!]: {F81414}คุณไม่ได้อยู่บนรถ");
  103.     }
  104.     return 1;
  105. }
  106.  
  107. CMD:dvehinfo(playerid, cmdtext[])
  108. {
  109.     if(Player[playerid][Admins] <= 0)
  110.         return SendClientMessage(playerid, YELLOW, "[!]: {F81414}คุณไม่ใช่แอดมิน");
  111.     for(new id = 0; id <MAX_VEHICLES_INFO; id++){
  112.         new vehicleid = GetPlayerVehicleID(playerid);
  113.         if(vehicleid == VehicleInfo[id][ID]){
  114.  
  115.             new carid;
  116.             carid = VehicleInfo[id][ID];
  117.             if(IsPlayerInVehicle(playerid,carid))
  118.             {
  119.                 DestroyVehicle(VehicleInfo[id][ID]);
  120.                 SendClientMessageEx(playerid, LIGHTBLUE, "delete Veh (%d)",id);
  121.                 new query[2000];
  122.                 mysql_format(g_SQL, query, sizeof(query), "DELETE FROM vehicleinfo WHERE ID=%d", id);
  123.                 mysql_tquery(g_SQL, query, "", "");
  124.                 VehicleInfo[id][ID] = false;
  125.                 TogglePlayerControllable(playerid, 1);
  126.                 return 1;
  127.             }
  128.         }
  129.     }
  130.     return 1;
  131. }
  132.  
  133. CMD:editvehinfo(playerid){
  134.  
  135.     new str[99];
  136.     for(new id = 0; id <MAX_VEHICLES_INFO; id++){
  137.         new vehicleid = GetPlayerVehicleID(playerid);
  138.         if(vehicleid == VehicleInfo[id][ID]){
  139.  
  140.             new carid;
  141.             carid = VehicleInfo[id][ID];
  142.             if(IsPlayerInVehicle(playerid,carid))
  143.             {
  144.                 CheckVehID[playerid] = id;
  145.                 format(str, 99, "VehicleInfoID %i", id);
  146.                 Dialog_Show(playerid, edit_vehinfo, DIALOG_STYLE_LIST, str, "เปลี่ยนสี\nเปลี่ยนพิกัด","OK","NO");
  147.             }
  148.         }
  149.     }
  150.     return 1;
  151. }
  152.  
  153. Dialog:edit_vehinfo(playerid, response, listitem, inputtext[]){
  154.  
  155.     new query[256];
  156.     if(!response) return 1;
  157.  
  158.     if(listitem == 0){
  159.         Dialog_Show(playerid, edit_colorinfo, DIALOG_STYLE_INPUT, "เปลี่ยนสี", "เปลี่ยนสี","OK","NO");
  160.     }
  161.     if(listitem == 1){
  162.         new vehicleid = GetPlayerVehicleID(playerid);
  163.         new Float:x,Float:y,Float:z,Float:a;
  164.         new id = CheckVehID[playerid];
  165.         GetVehiclePos(vehicleid, x, y, z);
  166.         GetVehicleZAngle(vehicleid, a);
  167.         mysql_format(g_SQL, query, sizeof(query), "UPDATE `vehicleinfo` SET `v_Posx` = '%f',`v_Posy` = '%f',`v_Posz` = '%f',`v_Posa` = '%f' WHERE `ID` = '%d'",x,y,z,a,id);
  168.         mysql_tquery(g_SQL, query);
  169.     }
  170.     return 1;
  171. }
  172.  
  173. Dialog:edit_colorinfo(playerid, response, listitem, inputtext[]){
  174.  
  175.     if(!response) return 1;
  176.     new tmp[256];
  177.     new idx = 0;
  178.     new vehcolor1, vehcolor2;
  179.     if(!response){
  180.         return 1;
  181.     }
  182.     tmp = strtok(inputtext, idx);
  183.     vehcolor1 = strval(tmp);
  184.     if(vehcolor1 < 0 || vehcolor1 >= 255)
  185.         return SendClientMessage(playerid,YELLOW,"[!]: {F81414}color1 รหัสสี 1 - 255!");
  186.    
  187.     tmp = strtok(inputtext, idx);
  188.     vehcolor2 = strval(tmp);
  189.     if(vehcolor2 < 0 || vehcolor2 >= 255)
  190.         return SendClientMessage(playerid,YELLOW,"[!]: {F81414}color2 รหัสสี 1 - 255!");
  191.  
  192.     new query[256];
  193.     new vehicleid = GetPlayerVehicleID(playerid);
  194.     new id = CheckVehID[playerid];
  195.     VehicleInfo[id][v_color1] = vehcolor1;
  196.     VehicleInfo[id][v_color2] = vehcolor2;
  197.     DestroyVehicle(vehicleid);
  198.     VehicleInfo[id][ID] =  CreateVehicle(VehicleInfo[id][v_model], VehicleInfo[id][v_Pos][0], VehicleInfo[id][v_Pos][1],VehicleInfo[id][v_Pos][2], VehicleInfo[id][v_Pos][3], vehcolor1, vehcolor2, 0);
  199.     mysql_format(g_SQL, query, sizeof(query), "UPDATE `vehicleinfo` SET `v_color1` = '%d',`v_color2` = '%d' WHERE `ID` = '%d'",vehcolor1,vehcolor2,id);
  200.     mysql_tquery(g_SQL, query);
  201.     return 1;
  202. }
Advertisement
RAW Paste Data Copied
Advertisement