Advertisement
Fanto66

Untitled

Jan 16th, 2021
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.14 KB | None | 0 0
  1. -- Store Vehicles
  2. ESX.RegisterServerCallback('esx_advancedgarage:storeVehicle', function (source, cb, vehicleProps)
  3.     local ownedCars = {}
  4.     local vehplate = vehicleProps.plate:match("^%s*(.-)%s*$")
  5.     local vehiclemodel = vehicleProps.model
  6.     local xPlayer = ESX.GetPlayerFromId(source)
  7.  
  8.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND @plate = plate', {
  9.         ['@owner'] = xPlayer.identifier,
  10.         ['@plate'] = vehicleProps.plate
  11.     }, function (result)
  12.         if result[1] ~= nil then
  13.             local originalvehprops = json.decode(result[1].vehicle)
  14.             if originalvehprops.model == vehiclemodel then
  15.                 MySQL.Async.execute('UPDATE owned_vehicles SET vehicle = @vehicle WHERE owner = @owner AND plate = @plate', {
  16.                     ['@owner'] = xPlayer.identifier,
  17.                     ['@vehicle'] = json.encode(vehicleProps),
  18.                     ['@plate'] = vehicleProps.plate
  19.                 }, function (rowsChanged)
  20.                     if rowsChanged == 0 then
  21.                         print(('esx_advancedgarage: %s attempted to store an vehicle they don\'t own!'):format(xPlayer.identifier))
  22.                     else
  23.                         --clear drugs from inventory
  24.                         MySQL.Async.fetchAll('SELECT * FROM trunk_inventory WHERE plate = @plate', {
  25.                             ['@plate'] = vehicleProps.plate
  26.                         }, function(result)
  27.                             --tprint(result)
  28.                             for k, v in pairs(result) do
  29.                                 local data = v.data
  30.                                 --print(type(data))
  31.                                 local inventory = json.decode(data)
  32.                                 --tprint(inventory)
  33.  
  34.                                 local items = inventory.coffre
  35.                                 local item2 = items
  36.                                 print("yo the type is "..type(items))
  37.  
  38.                                 for i = 1, #items, 1 do
  39.                                     print(items[i])
  40.                                     if items[i].name == 'opium' then
  41.                                         value = i
  42.                                         table.remove(item2, value)
  43.                                         print('opium detected')
  44.  
  45.                                     else
  46.                                         print("there was no opium")
  47.                                     end
  48.                                    
  49.                                 end
  50.                                 inventory.coffre = item2
  51.  
  52.                                 local dataT = json.encode(inventory)
  53.  
  54.                                 MySQL.Async.execute('UPDATE trunk_inventory SET data = @data WHERE plate = @plate', {
  55.                                     ['@data'] = dataT,
  56.                                     ['@plate'] = plate
  57.                                 }, function (rowsChanged)
  58.  
  59.  
  60.                                 end)
  61.                             end
  62.                         end)
  63.                     end
  64.                     cb(true)
  65.                 end)
  66.                
  67.             else
  68.                 if Config.KickPossibleCheaters == true then
  69.                     if Config.UseCustomKickMessage == true then
  70.                         print(('esx_advancedgarage: %s attempted to Cheat! Tried Storing: ' .. vehiclemodel .. '. Original Vehicle: ' .. originalvehprops.model):format(xPlayer.identifier))
  71.  
  72.                         DropPlayer(source, _U('custom_kick'))
  73.                         cb(false)
  74.                     else
  75.                         print(('esx_advancedgarage: %s attempted to Cheat! Tried Storing: ' .. vehiclemodel .. '. Original Vehicle: ' .. originalvehprops.model):format(xPlayer.identifier))
  76.  
  77.                         DropPlayer(source, 'You have been Kicked from the Server for Possible Garage Cheating!!!')
  78.                         cb(false)
  79.                     end
  80.                 else
  81.                     print(('esx_advancedgarage: %s attempted to Cheat! Tried Storing: ' .. vehiclemodel .. '. Original Vehicle: '.. originalvehprops.model):format(xPlayer.identifier))
  82.                     cb(false)
  83.                 end
  84.             end
  85.         else
  86.             print(('esx_advancedgarage: %s attempted to store an vehicle they don\'t own!'):format(xPlayer.identifier))
  87.             cb(false)
  88.         end
  89.     end)
  90. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement