Guest User

Untitled

a guest
May 8th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.70 KB | None | 0 0
  1. ESX = nil
  2.  
  3. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  4. TriggerEvent('esx_society:registerSociety', 'rhodes', 'rhodes', 'society_rhodes', 'society_rhodes', 'society_rhodes', {type = 'public'})
  5.  
  6. RegisterNetEvent('r_rhodes:confiscatePlayerItem')
  7. AddEventHandler('r_rhodes:confiscatePlayerItem', function(target, itemType, itemName, amount)
  8.     local _source = source
  9.     local sourceXPlayer = ESX.GetPlayerFromId(_source)
  10.     local targetXPlayer = ESX.GetPlayerFromId(target)
  11.  
  12.     if sourcexPlayer.job2.name ~= 'rhodes' then
  13.         print(('r_rhodes: %s attempted to confiscate!'):format(xPlayer.identifier))
  14.         return
  15.     end
  16.  
  17.     if itemType == 'item_standard' then
  18.         local targetItem = targetXPlayer.getInventoryItem(itemName)
  19.         local sourceItem = sourceXPlayer.getInventoryItem(itemName)
  20.  
  21.         if targetItem.count > 0 and targetItem.count <= amount then
  22.  
  23.             if sourceXPlayer.canCarryItem(itemName, sourceItem.count) then
  24.                 targetXPlayer.removeInventoryItem(itemName, amount)
  25.                 sourceXPlayer.addInventoryItem   (itemName, amount)
  26.                 sourceXPlayer.showNotification(_U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
  27.                 targetXPlayer.showNotification(_U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
  28.             else
  29.                 sourceXPlayer.showNotification(_U('quantity_invalid'))
  30.             end
  31.         else
  32.             sourceXPlayer.showNotification(_U('quantity_invalid'))
  33.         end
  34.  
  35.     elseif itemType == 'item_account' then
  36.         targetXPlayer.removeAccountMoney(itemName, amount)
  37.         sourceXPlayer.addAccountMoney   (itemName, amount)
  38.  
  39.         sourceXPlayer.showNotification(_U('you_confiscated_account', amount, itemName, targetXPlayer.name))
  40.         targetXPlayer.showNotification(_U('got_confiscated_account', amount, itemName, sourceXPlayer.name))
  41.  
  42.     elseif itemType == 'item_weapon' then
  43.         if amount == nil then amount = 0 end
  44.         targetXPlayer.removeWeapon(itemName, amount)
  45.         sourceXPlayer.addWeapon   (itemName, amount)
  46.  
  47.         sourceXPlayer.showNotification(_U('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount))
  48.         targetXPlayer.showNotification(_U('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name))
  49.     end
  50. end)
  51.  
  52. RegisterNetEvent('r_rhodes:handcuff')
  53. AddEventHandler('r_rhodes:handcuff', function(target)
  54.     local xPlayer = ESX.GetPlayerFromId(source)
  55.  
  56.     if xPlayer.job2.name == 'rhodes' then
  57.         TriggerClientEvent('r_rhodes:handcuff', target)
  58.     else
  59.         print(('r_rhodes: %s attempted to handcuff a player (not cop)!'):format(xPlayer.identifier))
  60.     end
  61. end)
  62.  
  63. RegisterNetEvent('r_rhodes:drag')
  64. AddEventHandler('r_rhodes:drag', function(target)
  65.     local xPlayer = ESX.GetPlayerFromId(source)
  66.  
  67.     if xPlayer.job2.name == 'rhodes' then
  68.         TriggerClientEvent('r_rhodes:drag', target, source)
  69.     else
  70.         print(('r_rhodes: %s attempted to drag (not cop)!'):format(xPlayer.identifier))
  71.     end
  72. end)
  73.  
  74. RegisterNetEvent('r_rhodes:putInVehicle')
  75. AddEventHandler('r_rhodes:putInVehicle', function(target)
  76.     local xPlayer = ESX.GetPlayerFromId(source)
  77.  
  78.     if xPlayer.job2.name == 'rhodes' then
  79.         TriggerClientEvent('r_rhodes:putInVehicle', target)
  80.     else
  81.         print(('r_rhodes: %s attempted to put in vehicle (not cop)!'):format(xPlayer.identifier))
  82.     end
  83. end)
  84.  
  85. RegisterNetEvent('r_rhodes:OutVehicle')
  86. AddEventHandler('r_rhodes:OutVehicle', function(target)
  87.     local xPlayer = ESX.GetPlayerFromId(source)
  88.  
  89.     if xPlayer.job2.name == 'rhodes' then
  90.         TriggerClientEvent('r_rhodes:OutVehicle', target)
  91.     else
  92.         print(('r_rhodes: %s attempted to drag out from vehicle (not cop)!'):format(xPlayer.identifier))
  93.     end
  94. end)
  95.  
  96. ESX.RegisterServerCallback('r_rhodes:getOtherPlayerData', function(source, cb, target, notify)
  97.     local xPlayer = ESX.GetPlayerFromId(target)
  98.  
  99.     if notify then
  100.         xPlayer.showNotification(_U('being_searched'))
  101.     end
  102.  
  103.     if xPlayer then
  104.         local data = {
  105.             name = xPlayer.getName(),
  106.             job = xPlayer.job2.label,
  107.             grade = xPlayer.job2.grade_label,
  108.             inventory = xPlayer.getInventory(),
  109.             accounts = xPlayer.getAccounts(),
  110.             weapons = xPlayer.getLoadout()
  111.         }
  112.  
  113.         if Config.EnableESXIdentity then
  114.             data.dob = xPlayer.get('dateofbirth')
  115.             data.height = xPlayer.get('height')
  116.  
  117.             if xPlayer.get('sex') == 'm' then data.sex = 'male' else data.sex = 'female' end
  118.         end
  119.  
  120.         TriggerEvent('esx_status:getStatus', target, 'drunk', function(status)
  121.             if status then
  122.                 data.drunk = ESX.Math.Round(status.percent)
  123.             end
  124.         end)
  125.     end
  126. end)
  127.  
  128.  
  129. ESX.RegisterServerCallback('r_rhodes:getVehicleInfos', function(source, cb, plate)
  130.     MySQL.Async.fetchAll('SELECT owner FROM owned_vehicles WHERE plate = @plate', {
  131.         ['@plate'] = plate
  132.     }, function(result)
  133.         local retrivedInfo = {plate = plate}
  134.  
  135.         if result[1] then
  136.             local xPlayer = ESX.GetPlayerFromIdentifier(result[1].owner)
  137.  
  138.             if xPlayer then
  139.                 retrivedInfo.owner = xPlayer.getName()
  140.                 cb(retrivedInfo)
  141.             elseif Config.EnableESXIdentity then
  142.                 MySQL.Async.fetchAll('SELECT firstname, lastname FROM users WHERE identifier = @identifier',  {
  143.                     ['@identifier'] = result[1].owner
  144.                 }, function(result2)
  145.                     if result2[1] then
  146.                         retrivedInfo.owner = ('%s %s'):format(result2[1].firstname, result2[1].lastname)
  147.                         cb(retrivedInfo)
  148.                     else
  149.                         cb(retrivedInfo)
  150.                     end
  151.                 end)
  152.             else
  153.                 cb(retrivedInfo)
  154.             end
  155.         else
  156.             cb(retrivedInfo)
  157.         end
  158.     end)
  159. end)
  160.  
  161. ESX.RegisterServerCallback('r_rhodes:buyWeapon', function(source, cb, weaponName, type, componentNum)
  162.     local xPlayer = ESX.GetPlayerFromId(source)
  163.     local authorizedWeapons, selectedWeapon = Config.AuthorizedWeapons[xPlayer.job2.grade_name]
  164.  
  165.     for k,v in ipairs(authorizedWeapons) do
  166.         if v.weapon == weaponName then
  167.             selectedWeapon = v
  168.             break
  169.         end
  170.     end
  171.  
  172.     if not selectedWeapon then
  173.         print(('r_rhodes: %s attempted to buy an invalid weapon.'):format(xPlayer.identifier))
  174.         cb(false)
  175.     else
  176.         if type == 1 then
  177.             if xPlayer.getMoney() >= selectedWeapon.price then
  178.                 xPlayer.removeMoney(selectedWeapon.price)
  179.                 xPlayer.addWeapon(weaponName, 100)
  180.  
  181.                 cb(true)
  182.             else
  183.                 cb(false)
  184.             end
  185.  
  186.         elseif type == 2 then
  187.             local price = selectedWeapon.components[componentNum]
  188.             local weaponNum, weapon = ESX.GetWeapon(weaponName)
  189.             local component = weapon.components[componentNum]
  190.  
  191.             if component then
  192.                 if xPlayer.getMoney() >= price then
  193.                     xPlayer.removeMoney(price)
  194.                     xPlayer.addWeaponComponent(weaponName, component.name)
  195.  
  196.                     cb(true)
  197.                 else
  198.                     cb(false)
  199.                 end
  200.             else
  201.                 print(('r_rhodes: %s attempted to buy an invalid weapon component.'):format(xPlayer.identifier))
  202.                 cb(false)
  203.             end
  204.         end
  205.     end
  206. end)
  207.  
  208. ESX.RegisterServerCallback('r_rhodes:storeNearbyVehicle', function(source, cb, nearbyVehicles)
  209.     local xPlayer = ESX.GetPlayerFromId(source)
  210.     local foundPlate, foundNum
  211.  
  212.     for k,v in ipairs(nearbyVehicles) do
  213.         local result = MySQL.Sync.fetchAll('SELECT plate FROM owned_vehicles WHERE owner = @owner AND plate = @plate AND job = @job', {
  214.             ['@owner'] = xPlayer.identifier,
  215.             ['@plate'] = v.plate,
  216.             ['@job'] = xPlayer.job2.name
  217.         })
  218.  
  219.         if result[1] then
  220.             foundPlate, foundNum = result[1].plate, k
  221.             break
  222.         end
  223.     end
  224.  
  225.     if not foundPlate then
  226.         cb(false)
  227.     else
  228.         MySQL.Async.execute('UPDATE owned_vehicles SET `stored` = true WHERE owner = @owner AND plate = @plate AND job = @job', {
  229.             ['@owner'] = xPlayer.identifier,
  230.             ['@plate'] = foundPlate,
  231.             ['@job'] = xPlayer.job2.name
  232.         }, function (rowsChanged)
  233.             if rowsChanged == 0 then
  234.                 print(('r_rhodes: %s has exploited the garage!'):format(xPlayer.identifier))
  235.                 cb(false)
  236.             else
  237.                 cb(true, foundNum)
  238.             end
  239.         end)
  240.     end
  241. end)
  242.  
  243. ESX.RegisterServerCallback('r_rhodes:getPlayerInventory', function(source, cb)
  244.     local xPlayer = ESX.GetPlayerFromId(source)
  245.     local items   = xPlayer.inventory
  246.  
  247.     cb({items = items})
  248. end)
Add Comment
Please, Sign In to add comment