mirko_effe

Untitled

Sep 29th, 2021 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.84 KB | None | 0 0
  1. ESX                = nil
  2.  
  3. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  4.  
  5. if Config.MaxInService ~= -1 then
  6.   TriggerEvent('esx_service:activateService', 'hosameki', Config.MaxInService)
  7. end
  8.  
  9. TriggerEvent('esx_phone:registerNumber', 'hosameki', _U('hosameki_customer'), true, true)
  10. TriggerEvent('esx_society:registerSociety', 'hosameki', 'hosameki', 'society_hosameki', 'society_hosameki', 'society_hosameki', {type = 'private'})
  11.  
  12. RegisterServerEvent('esx_hosameki:getStockItem')
  13. AddEventHandler('esx_hosameki:getStockItem', function(itemName, count)
  14.  
  15.     local xPlayer = ESX.GetPlayerFromId(source)
  16.  
  17.     TriggerEvent('esx_addoninventory:getSharedInventory', 'society_hosameki', function(inventory)
  18.  
  19.         local item = inventory.getItem(itemName)
  20.  
  21.         if item.count >= count then
  22.             inventory.removeItem(itemName, count)
  23.             xPlayer.addInventoryItem(itemName, count)
  24.         else
  25.             TriggerClientEvent("esx:showNotification", source, 'Quantità non valida!')
  26.         end
  27.  
  28.     end)
  29.  
  30. end)
  31.  
  32. ESX.RegisterServerCallback('esx_hosameki:getStockItems', function(source, cb)
  33.  
  34.     TriggerEvent('esx_addoninventory:getSharedInventory', 'society_hosameki', function(inventory)
  35.         cb(inventory.items)
  36.     end)
  37.  
  38. end)
  39.  
  40. RegisterServerEvent('esx_hosameki:putStockItems')
  41. AddEventHandler('esx_hosameki:putStockItems', function(itemName, count)
  42.  
  43.     local xPlayer = ESX.GetPlayerFromId(source)
  44.  
  45.     TriggerEvent('esx_addoninventory:getSharedInventory', 'society_hosameki', function(inventory)
  46.  
  47.         local item = inventory.getItem(itemName)
  48.         local playerItemCount = xPlayer.getInventoryItem(itemName).count
  49.  
  50.         if item.count >= 0 and count <= playerItemCount then
  51.             xPlayer.removeInventoryItem(itemName, count)
  52.             inventory.addItem(itemName, count)
  53.         else
  54.             TriggerClientEvent("esx:showNotification", source, 'Quantità non valida!')
  55.         end
  56.  
  57.     end)
  58.  
  59. end)
  60.  
  61.  
  62. RegisterServerEvent('esx_hosameki:getFridgeStockItem')
  63. AddEventHandler('esx_hosameki:getFridgeStockItem', function(itemName, count)
  64.  
  65.     local xPlayer = ESX.GetPlayerFromId(source)
  66.  
  67.     TriggerEvent('esx_addoninventory:getSharedInventory', 'society_hosameki_fridge', function(inventory)
  68.  
  69.         local item = inventory.getItem(itemName)
  70.  
  71.         if item.count >= count then
  72.             inventory.removeItem(itemName, count)
  73.             xPlayer.addInventoryItem(itemName, count)
  74.         else
  75.             TriggerClientEvent("esx:showNotification", source, 'Quantità non valida!')
  76.         end
  77.  
  78.     end)
  79.  
  80. end)
  81.  
  82. ESX.RegisterServerCallback('esx_hosameki:getFridgeStockItems', function(source, cb)
  83.  
  84.     TriggerEvent('esx_addoninventory:getSharedInventory', 'society_hosameki_fridge', function(inventory)
  85.         cb(inventory.items)
  86.     end)
  87.  
  88. end)
  89.  
  90. RegisterServerEvent('esx_hosameki:putFridgeStockItems')
  91. AddEventHandler('esx_hosameki:putFridgeStockItems', function(itemName, count)
  92.  
  93.     local xPlayer = ESX.GetPlayerFromId(source)
  94.  
  95.     TriggerEvent('esx_addoninventory:getSharedInventory', 'society_hosameki_fridge', function(inventory)
  96.  
  97.         local item = inventory.getItem(itemName)
  98.         local playerItemCount = xPlayer.getInventoryItem(itemName).count
  99.  
  100.         if item.count >= 0 and count <= playerItemCount then
  101.             xPlayer.removeInventoryItem(itemName, count)
  102.             inventory.addItem(itemName, count)
  103.         else
  104.             TriggerClientEvent("esx:showNotification", source, 'Quantità non valida!')
  105.         end
  106.  
  107.     end)
  108.  
  109. end)
  110.  
  111.  
  112. ESX.RegisterServerCallback('esx_hosameki:getVaultWeapons', function(source, cb)
  113.  
  114.     TriggerEvent('esx_datastore:getSharedDataStore', 'society_hosameki', function(store)
  115.  
  116.         local weapons = store.get('weapons')
  117.  
  118.         if weapons == nil then
  119.         weapons = {}
  120.         end
  121.  
  122.         cb(weapons)
  123.  
  124.     end)
  125.  
  126. end)
  127.  
  128. ESX.RegisterServerCallback('esx_hosameki:addVaultWeapon', function(source, cb, weaponName)
  129.  
  130.     local _source = source
  131.     local xPlayer = ESX.GetPlayerFromId(_source)
  132.  
  133.     xPlayer.removeWeapon(weaponName)
  134.  
  135.     TriggerEvent('esx_datastore:getSharedDataStore', 'society_hosameki', function(store)
  136.  
  137.         local weapons = store.get('weapons')
  138.  
  139.         if weapons == nil then
  140.             weapons = {}
  141.         end
  142.  
  143.         local foundWeapon = false
  144.  
  145.         for i=1, #weapons, 1 do
  146.         if weapons[i].name == weaponName then
  147.             weapons[i].count = weapons[i].count + 1
  148.             foundWeapon = true
  149.         end
  150.         end
  151.  
  152.         if not foundWeapon then
  153.         table.insert(weapons, {
  154.             name  = weaponName,
  155.             count = 1
  156.         })
  157.         end
  158.  
  159.         store.set('weapons', weapons)
  160.  
  161.         cb()
  162.  
  163.     end)
  164.  
  165. end)
  166.  
  167. ESX.RegisterServerCallback('esx_hosameki:removeVaultWeapon', function(source, cb, weaponName)
  168.  
  169.     local _source = source
  170.     local xPlayer = ESX.GetPlayerFromId(_source)
  171.  
  172.     xPlayer.addWeapon(weaponName, 1000)
  173.  
  174.     TriggerEvent('esx_datastore:getSharedDataStore', 'society_hosameki', function(store)
  175.  
  176.         local weapons = store.get('weapons')
  177.  
  178.         if weapons == nil then
  179.         weapons = {}
  180.         end
  181.  
  182.         local foundWeapon = false
  183.  
  184.         for i=1, #weapons, 1 do
  185.         if weapons[i].name == weaponName then
  186.             weapons[i].count = (weapons[i].count > 0 and weapons[i].count - 1 or 0)
  187.             foundWeapon = true
  188.         end
  189.         end
  190.  
  191.         if not foundWeapon then
  192.         table.insert(weapons, {
  193.             name  = weaponName,
  194.             count = 0
  195.         })
  196.         end
  197.  
  198.         store.set('weapons', weapons)
  199.  
  200.         cb()
  201.  
  202.     end)
  203.  
  204. end)
  205.  
  206. ESX.RegisterServerCallback('esx_hosameki:getPlayerInventory', function(source, cb)
  207.  
  208.     local _source = source
  209.     local xPlayer = ESX.GetPlayerFromId(_source)
  210.     local items = xPlayer.inventory
  211.  
  212.     cb({items = items})
  213. end)
  214.  
Add Comment
Please, Sign In to add comment