Advertisement
Guest User

Server.lua

a guest
Jul 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.89 KB | None | 0 0
  1. ESX = nil
  2.  
  3. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  4.  
  5. -- Make sure all Vehicles are Stored on restart
  6. MySQL.ready(function()
  7.     ParkVehicles()
  8. end)
  9.  
  10. function ParkVehicles()
  11.     MySQL.Async.execute('UPDATE owned_vehicles SET `stored` = true WHERE `stored` = @stored', {
  12.         ['@stored'] = false
  13.     }, function(rowsChanged)
  14.         if rowsChanged > 0 then
  15.             print(('esx_advancedgarage: %s vehicle(s) have been stored!'):format(rowsChanged))
  16.         end
  17.     end)
  18. end
  19.  
  20. -- Get Owned Properties
  21. ESX.RegisterServerCallback('esx_advancedgarage:getOwnedProperties', function(source, cb)
  22.     local _source = source
  23.     local xPlayer = ESX.GetPlayerFromId(_source)
  24.     local properties = {}
  25.  
  26.     MySQL.Async.fetchAll('SELECT * FROM owned_properties WHERE owner = @owner', {
  27.         ['@owner'] = xPlayer.getIdentifier()
  28.     }, function(data)
  29.         for _,v in pairs(data) do
  30.             table.insert(properties, v.name)
  31.         end
  32.         cb(properties)
  33.     end)
  34. end)
  35.  
  36. -- Fetch Owned Aircrafts
  37. ESX.RegisterServerCallback('esx_advancedgarage:getOwnedAircrafts', function(source, cb)
  38.     local ownedAircrafts = {}
  39.  
  40.     if Config.DontShowPoundCarsInGarage == true then
  41.         MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job AND `stored` = @stored', {
  42.             ['@owner']  = GetPlayerIdentifiers(source)[1],
  43.             ['@Type']   = 'aircraft',
  44.             ['@job']    = '',
  45.             ['@stored'] = true
  46.         }, function(data)
  47.             for _,v in pairs(data) do
  48.                 local vehicle = json.decode(v.vehicle)
  49.                 table.insert(ownedAircrafts, {vehicle = vehicle, stored = v.stored, plate = v.plate})
  50.             end
  51.             cb(ownedAircrafts)
  52.         end)
  53.     else
  54.         MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job', {
  55.             ['@owner']  = GetPlayerIdentifiers(source)[1],
  56.             ['@Type']   = 'aircraft',
  57.             ['@job']    = ''
  58.         }, function(data)
  59.             for _,v in pairs(data) do
  60.                 local vehicle = json.decode(v.vehicle)
  61.                 table.insert(ownedAircrafts, {vehicle = vehicle, stored = v.stored, plate = v.plate})
  62.             end
  63.             cb(ownedAircrafts)
  64.         end)
  65.     end
  66. end)
  67.  
  68. -- Fetch Owned Boats
  69. ESX.RegisterServerCallback('esx_advancedgarage:getOwnedBoats', function(source, cb)
  70.     local ownedBoats = {}
  71.  
  72.     if Config.DontShowPoundCarsInGarage == true then
  73.         MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job AND `stored` = @stored', {
  74.             ['@owner']  = GetPlayerIdentifiers(source)[1],
  75.             ['@Type']   = 'boat',
  76.             ['@job']    = '',
  77.             ['@stored'] = true
  78.         }, function(data)
  79.             for _,v in pairs(data) do
  80.                 local vehicle = json.decode(v.vehicle)
  81.                 table.insert(ownedBoats, {vehicle = vehicle, stored = v.stored, plate = v.plate})
  82.             end
  83.             cb(ownedBoats)
  84.         end)
  85.     else
  86.         MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job', {
  87.             ['@owner']  = GetPlayerIdentifiers(source)[1],
  88.             ['@Type']   = 'boat',
  89.             ['@job']    = ''
  90.         }, function(data)
  91.             for _,v in pairs(data) do
  92.                 local vehicle = json.decode(v.vehicle)
  93.                 table.insert(ownedBoats, {vehicle = vehicle, stored = v.stored, plate = v.plate})
  94.             end
  95.             cb(ownedBoats)
  96.         end)
  97.     end
  98. end)
  99.  
  100. -- Fetch Owned Cars
  101. ESX.RegisterServerCallback('esx_advancedgarage:getOwnedCars', function(source, cb)
  102.     local ownedCars = {}
  103.    
  104.     if Config.DontShowPoundCarsInGarage == true then
  105.         MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job AND `stored` = @stored', {
  106.             ['@owner']  = GetPlayerIdentifiers(source)[1],
  107.             ['@Type']   = 'car',
  108.             ['@job']    = '',
  109.             ['@stored'] = true
  110.         }, function(data)
  111.             for _,v in pairs(data) do
  112.                 local vehicle = json.decode(v.vehicle)
  113.                 table.insert(ownedCars, {vehicle = vehicle, stored = v.stored, plate = v.plate})
  114.             end
  115.             cb(ownedCars)
  116.         end)
  117.     else
  118.         MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job', {
  119.             ['@owner']  = GetPlayerIdentifiers(source)[1],
  120.             ['@Type']   = 'car',
  121.             ['@job']    = ''
  122.         }, function(data)
  123.             for _,v in pairs(data) do
  124.                 local vehicle = json.decode(v.vehicle)
  125.                 table.insert(ownedCars, {vehicle = vehicle, stored = v.stored, plate = v.plate})
  126.             end
  127.             cb(ownedCars)
  128.         end)
  129.     end
  130. end)
  131.  
  132. -- Store Vehicles
  133. ESX.RegisterServerCallback('esx_advancedgarage:storeVehicle', function (source, cb, vehicleProps)
  134.     local ownedCars = {}
  135.     local vehplate = vehicleProps.plate:match("^%s*(.-)%s*$")
  136.     local vehiclemodel = vehicleProps.model
  137.     local xPlayer = ESX.GetPlayerFromId(source)
  138.    
  139.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND @plate = plate', {
  140.         ['@owner'] = xPlayer.identifier,
  141.         ['@plate'] = vehicleProps.plate
  142.     }, function (result)
  143.         if result[1] ~= nil then
  144.             local originalvehprops = json.decode(result[1].vehicle)
  145.             if originalvehprops.model == vehiclemodel then
  146.                 MySQL.Async.execute('UPDATE owned_vehicles SET vehicle = @vehicle WHERE owner = @owner AND plate = @plate', {
  147.                     ['@owner']  = GetPlayerIdentifiers(source)[1],
  148.                     ['@vehicle'] = json.encode(vehicleProps),
  149.                     ['@plate']  = vehicleProps.plate
  150.                 }, function (rowsChanged)
  151.                     if rowsChanged == 0 then
  152.                         print(('esx_advancedgarage: %s attempted to store an vehicle they don\'t own!'):format(GetPlayerIdentifiers(source)[1]))
  153.                     end
  154.                     cb(true)
  155.                 end)
  156.             else
  157.                 if Config.KickPossibleCheaters == true then
  158.                     if Config.UseCustomKickMessage == true then
  159.                         print(('esx_advancedgarage: %s attempted to Cheat! Tried Storing: '..vehiclemodel..'. Original Vehicle: '..originalvehprops.model):format(GetPlayerIdentifiers(source)[1]))
  160.                         DropPlayer(source, _U('custom_kick'))
  161.                         cb(false)
  162.                     else
  163.                         print(('esx_advancedgarage: %s attempted to Cheat! Tried Storing: '..vehiclemodel..'. Original Vehicle: '..originalvehprops.model):format(GetPlayerIdentifiers(source)[1]))
  164.                         DropPlayer(source, 'You have been Kicked from the Server for Possible Garage Cheating!!!')
  165.                         cb(false)
  166.                     end
  167.                 else
  168.                     print(('esx_advancedgarage: %s attempted to Cheat! Tried Storing: '..vehiclemodel..'. Original Vehicle: '..originalvehprops.model):format(GetPlayerIdentifiers(source)[1]))
  169.                     cb(false)
  170.                 end
  171.             end
  172.         else
  173.             print(('esx_advancedgarage: %s attempted to store an vehicle they don\'t own!'):format(GetPlayerIdentifiers(source)[1]))
  174.             cb(false)
  175.         end
  176.     end)
  177. end)
  178.  
  179. -- Fetch Pounded Aircrafts
  180. ESX.RegisterServerCallback('esx_advancedgarage:getOutOwnedAircrafts', function(source, cb)
  181.     local ownedAircrafts = {}
  182.  
  183.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job AND `stored` = @stored', {
  184.         ['@owner'] = GetPlayerIdentifiers(source)[1],
  185.         ['@Type']   = 'aircraft',
  186.         ['@job']    = '',
  187.         ['@stored'] = false
  188.     }, function(data)
  189.         for _,v in pairs(data) do
  190.             local vehicle = json.decode(v.vehicle)
  191.             table.insert(ownedAircrafts, vehicle)
  192.         end
  193.         cb(ownedAircrafts)
  194.     end)
  195. end)
  196.  
  197. -- Fetch Pounded Boats
  198. ESX.RegisterServerCallback('esx_advancedgarage:getOutOwnedBoats', function(source, cb)
  199.     local ownedBoats = {}
  200.  
  201.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job AND `stored` = @stored', {
  202.         ['@owner'] = GetPlayerIdentifiers(source)[1],
  203.         ['@Type']   = 'boat',
  204.         ['@job']    = '',
  205.         ['@stored'] = false
  206.     }, function(data)
  207.         for _,v in pairs(data) do
  208.             local vehicle = json.decode(v.vehicle)
  209.             table.insert(ownedBoats, vehicle)
  210.         end
  211.         cb(ownedBoats)
  212.     end)
  213. end)
  214.  
  215. -- Fetch Pounded Cars
  216. ESX.RegisterServerCallback('esx_advancedgarage:getOutOwnedCars', function(source, cb)
  217.     local ownedCars = {}
  218.  
  219.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND Type = @Type AND job = @job AND `stored` = @stored', {
  220.         ['@owner'] = GetPlayerIdentifiers(source)[1],
  221.         ['@Type']   = 'car',
  222.         ['@job']    = '',
  223.         ['@stored'] = false
  224.     }, function(data)
  225.         for _,v in pairs(data) do
  226.             local vehicle = json.decode(v.vehicle)
  227.             table.insert(ownedCars, vehicle)
  228.         end
  229.         cb(ownedCars)
  230.     end)
  231. end)
  232.  
  233. -- Fetch Pounded Policing Vehicles
  234. --[[ESX.RegisterServerCallback('esx_advancedgarage:getOutOwnedPolicingCars', function(source, cb)
  235.     local ownedPolicingCars = {}
  236.  
  237.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND job = @job AND `stored` = @stored', {
  238.         ['@owner'] = GetPlayerIdentifiers(source)[1],
  239.         ['@job']    = 'police',
  240.         ['@stored'] = false
  241.     }, function(data)
  242.         for _,v in pairs(data) do
  243.             local vehicle = json.decode(v.vehicle)
  244.             table.insert(ownedPolicingCars, vehicle)
  245.         end
  246.         cb(ownedPolicingCars)
  247.     end)
  248. end)
  249.  
  250. -- Fetch Pounded Ambulance Vehicles
  251. ESX.RegisterServerCallback('esx_advancedgarage:getOutOwnedAmbulanceCars', function(source, cb)
  252.     local ownedAmbulanceCars = {}
  253.  
  254.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner AND job = @job AND `stored` = @stored', {
  255.         ['@owner'] = GetPlayerIdentifiers(source)[1],
  256.         ['@job']    = 'ambulance',
  257.         ['@stored'] = false
  258.     }, function(data)
  259.         for _,v in pairs(data) do
  260.             local vehicle = json.decode(v.vehicle)
  261.             table.insert(ownedAmbulanceCars, vehicle)
  262.         end
  263.         cb(ownedAmbulanceCars)
  264.     end)
  265. end)]]--
  266.  
  267. -- Check Money for Pounded Aircrafts
  268. ESX.RegisterServerCallback('esx_advancedgarage:checkMoneyAircrafts', function(source, cb)
  269.     local xPlayer = ESX.GetPlayerFromId(source)
  270.     if xPlayer.get('money') >= Config.AircraftPoundPrice then
  271.         cb(true)
  272.     else
  273.         cb(false)
  274.     end
  275. end)
  276.  
  277. -- Check Money for Pounded Boats
  278. ESX.RegisterServerCallback('esx_advancedgarage:checkMoneyBoats', function(source, cb)
  279.     local xPlayer = ESX.GetPlayerFromId(source)
  280.     if xPlayer.get('money') >= Config.BoatPoundPrice then
  281.         cb(true)
  282.     else
  283.         cb(false)
  284.     end
  285. end)
  286.  
  287. -- Check Money for Pounded Cars
  288. ESX.RegisterServerCallback('esx_advancedgarage:checkMoneyCars', function(source, cb)
  289.     local xPlayer = ESX.GetPlayerFromId(source)
  290.     if xPlayer.get('money') >= Config.CarPoundPrice then
  291.         cb(true)
  292.     else
  293.         cb(false)
  294.     end
  295. end)
  296.  
  297. -- Check Money for Pounded Policing
  298. --[[ESX.RegisterServerCallback('esx_advancedgarage:checkMoneyPolicing', function(source, cb)
  299.     local xPlayer = ESX.GetPlayerFromId(source)
  300.     if xPlayer.get('money') >= Config.PolicingPoundPrice then
  301.         cb(true)
  302.     else
  303.         cb(false)
  304.     end
  305. end)
  306.  
  307. -- Check Money for Pounded Ambulance
  308. ESX.RegisterServerCallback('esx_advancedgarage:checkMoneyAmbulance', function(source, cb)
  309.     local xPlayer = ESX.GetPlayerFromId(source)
  310.     if xPlayer.get('money') >= Config.AmbulancePoundPrice then
  311.         cb(true)
  312.     else
  313.         cb(false)
  314.     end
  315. end)]]--
  316.  
  317. -- Pay for Pounded Aircrafts
  318. RegisterServerEvent('esx_advancedgarage:payAircraft')
  319. AddEventHandler('esx_advancedgarage:payAircraft', function()
  320.     local xPlayer = ESX.GetPlayerFromId(source)
  321.     xPlayer.removeMoney(Config.AircraftPoundPrice)
  322.     TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. Config.AircraftPoundPrice)
  323. end)
  324.  
  325. -- Pay for Pounded Boats
  326. RegisterServerEvent('esx_advancedgarage:payBoat')
  327. AddEventHandler('esx_advancedgarage:payBoat', function()
  328.     local xPlayer = ESX.GetPlayerFromId(source)
  329.     xPlayer.removeMoney(Config.BoatPoundPrice)
  330.     TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. Config.BoatPoundPrice)
  331. end)
  332.  
  333. -- Pay for Pounded Cars
  334. RegisterServerEvent('esx_advancedgarage:payCar')
  335. AddEventHandler('esx_advancedgarage:payCar', function()
  336.     local xPlayer = ESX.GetPlayerFromId(source)
  337.     xPlayer.removeMoney(Config.CarPoundPrice)
  338.     TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. Config.CarPoundPrice)
  339. end)
  340.  
  341. -- Pay for Pounded Policing
  342. --[[RegisterServerEvent('esx_advancedgarage:payPolicing')
  343. AddEventHandler('esx_advancedgarage:payPolicing', function()
  344.     local xPlayer = ESX.GetPlayerFromId(source)
  345.     xPlayer.removeMoney(Config.PolicingPoundPrice)
  346.     TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. Config.PolicingPoundPrice)
  347. end)
  348.  
  349. -- Pay for Pounded Ambulance
  350. RegisterServerEvent('esx_advancedgarage:payAmbulance')
  351. AddEventHandler('esx_advancedgarage:payAmbulance', function()
  352.     local xPlayer = ESX.GetPlayerFromId(source)
  353.     xPlayer.removeMoney(Config.AmbulancePoundPrice)
  354.     TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. Config.AmbulancePoundPrice)
  355. end)]]--
  356.  
  357. -- Pay to Return Broken Vehicles
  358. RegisterServerEvent('esx_advancedgarage:payhealth')
  359. AddEventHandler('esx_advancedgarage:payhealth', function(price)
  360.     local xPlayer = ESX.GetPlayerFromId(source)
  361.     xPlayer.removeMoney(price)
  362.     TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. price)
  363. end)
  364.  
  365. -- Modify State of Vehicles
  366. RegisterServerEvent('esx_advancedgarage:setVehicleState')
  367. AddEventHandler('esx_advancedgarage:setVehicleState', function(plate, state)
  368.     local xPlayer = ESX.GetPlayerFromId(source)
  369.  
  370.     MySQL.Async.execute('UPDATE owned_vehicles SET `stored` = @stored WHERE plate = @plate', {
  371.         ['@stored'] = state,
  372.         ['@plate'] = plate
  373.     }, function(rowsChanged)
  374.         if rowsChanged == 0 then
  375.             print(('esx_advancedgarage: %s exploited the garage!'):format(xPlayer.identifier))
  376.         end
  377.     end)
  378. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement