SHARE
TWEET

Untitled

a guest Jan 25th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ESX = nil
  2.  
  3. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  4.  
  5. local xPlayer = ESX.GetPlayerFromId(_source)
  6.  
  7. -- Récupère les véhicules
  8. ESX.RegisterServerCallback('esx_eden_mrv_garage:getStoredVehicles', function(source, cb)
  9.     local _source = source
  10.     local xPlayer = ESX.GetPlayerFromId(_source)
  11.     local vehicules = {}
  12.  
  13.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @identifier AND stored = @stored', {
  14.         ['@identifier'] = xPlayer.getIdentifier(),
  15.         ['@stored'] = 1
  16.     }, function(data)
  17.         for _, v in pairs(data) do
  18.             local vehicle = json.decode(v.vehicle)
  19.  
  20.             table.insert(vehicules, {
  21.                 vehicle = vehicle,
  22.                 stored = v.stored,
  23.                 plate = v.plate,
  24.             })
  25.         end
  26.  
  27.         cb(vehicules)
  28.     end)
  29. end)
  30.  
  31. ESX.RegisterServerCallback('esx_eden_mrv_garage:getOthersVehicles', function(source, cb)
  32.     local _source = source
  33.     local xPlayer = ESX.GetPlayerFromId(_source)
  34.     local vehicules = {}
  35.  
  36.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @identifier AND stored = @stored', {
  37.         ['@identifier'] = xPlayer.getIdentifier(),
  38.         ['@stored'] = 0
  39.     }, function(data)
  40.         for _, v in pairs(data) do
  41.             local vehicle = json.decode(v.vehicle)
  42.  
  43.             table.insert(vehicules, {
  44.                 vehicle = vehicle,
  45.                 stored = v.stored,
  46.                 plate = v.plate,
  47.             })
  48.         end
  49.  
  50.         cb(vehicules)
  51.     end)
  52. end)
  53.  
  54. ESX.RegisterServerCallback('esx_eden_mrv_garage:getPoundVehicles', function(source, cb)
  55.     local _source = source
  56.     local xPlayer = ESX.GetPlayerFromId(_source)
  57.     local vehicules = {}
  58.  
  59.     MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @identifier AND impound = true AND stored = false', {
  60.         ['@identifier'] = xPlayer.getIdentifier()
  61.     }, function(data)
  62.  
  63.         for _, v in pairs(data) do
  64.             local vehicle = json.decode(v.vehicle)
  65.             table.insert(vehicules, vehicle)
  66.         end
  67.  
  68.         cb(vehicules)
  69.     end)
  70. end)
  71.  
  72. RegisterServerEvent('esx_eden_mrv_garage:deletevehicle_sv')
  73. AddEventHandler('esx_eden_mrv_garage:deletevehicle_sv', function(vehicle)
  74.     TriggerClientEvent('esx_eden_mrv_garage:deletevehicle_cl', -1, vehicle)
  75. end)
  76.  
  77. RegisterServerEvent('esx_eden_mrv_garage:modifyStored')
  78. AddEventHandler('esx_eden_mrv_garage:modifyStored', function(plate, stored)
  79.     local _source = source
  80.     local xPlayer = ESX.GetPlayerFromId(_source)
  81.     local stored = stored
  82.  
  83.     MySQL.Sync.execute('UPDATE owned_vehicles SET stored = @stored WHERE plate = @plate', {
  84.         ['@stored'] = stored,
  85.         ['@plate'] = plate
  86.     })
  87. end)
  88.  
  89. RegisterServerEvent('esx_eden_mrv_garage:modifyImPound')
  90. AddEventHandler('esx_eden_mrv_garage:modifyImPound', function(plate, impound)
  91.     local _source = source
  92.     local xPlayer = ESX.GetPlayerFromId(_source)
  93.     local impound = impound
  94.  
  95.     MySQL.Sync.execute('UPDATE owned_vehicles SET impound = @impound WHERE plate = @plate', {
  96.         ['@impound'] = impound,
  97.         ['@plate'] = plate
  98.     })
  99. end)
  100.  
  101. ESX.RegisterServerCallback('esx_eden_mrv_garage:checkMoney', function(source, cb)
  102.     local xPlayer = ESX.GetPlayerFromId(source)
  103.  
  104.     local price = Config.Price
  105.     cb(xPlayer.get('money') >= price)
  106. end)
  107.  
  108. RegisterServerEvent('esx_eden_mrv_garage:pay')
  109. AddEventHandler('esx_eden_mrv_garage:pay', function(price)
  110.     local _source = source
  111.     local xPlayer = ESX.GetPlayerFromId(_source)
  112.  
  113.     xPlayer.removeMoney(price)
  114. end)
  115.  
  116. -- Return all vehicles to garage (stored update) on server restart
  117. AddEventHandler('onMySQLReady', function()
  118.     MySQL.Sync.execute('UPDATE owned_vehicles SET impound=true WHERE stored=false', {})
  119. end)
  120.  
  121. -- End vehicle return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top