Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.37 KB | None | 0 0
  1. RegisterServerEvent('esx:giveInventoryItem')
  2. AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
  3. local _source = source
  4.  
  5. local sourceXPlayer = ESX.GetPlayerFromId(_source)
  6. local targetXPlayer = ESX.GetPlayerFromId(target)
  7.  
  8. if type == 'item_standard' then
  9.  
  10. local sourceItem = sourceXPlayer.getInventoryItem(itemName)
  11. local targetItem = targetXPlayer.getInventoryItem(itemName)
  12.  
  13. if itemCount > 0 and sourceItem.count >= itemCount then
  14.  
  15. if targetItem.limit ~= -1 and (targetItem.count + itemCount) > targetItem.limit then
  16. TriggerClientEvent('esx:showNotification', _source, _U('ex_inv_lim', targetXPlayer.name))
  17. else
  18. sourceXPlayer.removeInventoryItem(itemName, itemCount)
  19. targetXPlayer.addInventoryItem (itemName, itemCount)
  20.  
  21. TriggerClientEvent('esx:showNotification', _source, _U('gave_item', itemCount, ESX.Items[itemName].label, targetXPlayer.name))
  22. TriggerClientEvent('esx:showNotification', target, _U('received_item', itemCount, ESX.Items[itemName].label, sourceXPlayer.name))
  23.  
  24. TriggerEvent("esx:giveitemalert",sourceXPlayer.name,targetXPlayer.name,ESX.Items[itemName].label,itemCount)
  25. end
  26.  
  27. else
  28. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
  29. end
  30.  
  31. elseif type == 'item_money' then
  32.  
  33. if itemCount > 0 and sourceXPlayer.getMoney() >= itemCount then
  34. sourceXPlayer.removeMoney(itemCount)
  35. targetXPlayer.addMoney (itemCount)
  36.  
  37. TriggerClientEvent('esx:showNotification', _source, _U('gave_money', ESX.Math.GroupDigits(itemCount), targetXPlayer.name))
  38. TriggerClientEvent('esx:showNotification', target, _U('received_money', ESX.Math.GroupDigits(itemCount), sourceXPlayer.name))
  39.  
  40. TriggerEvent("esx:givemoneyalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
  41. else
  42. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
  43. end
  44.  
  45. elseif type == 'item_account' then
  46.  
  47. if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
  48. sourceXPlayer.removeAccountMoney(itemName, itemCount)
  49. targetXPlayer.addAccountMoney (itemName, itemCount)
  50.  
  51. TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], targetXPlayer.name))
  52. TriggerClientEvent('esx:showNotification', target, _U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], sourceXPlayer.name))
  53.  
  54. TriggerEvent("esx:givemoneybankalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
  55. else
  56. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
  57. end
  58.  
  59. elseif type == 'item_weapon' then
  60.  
  61. if not targetXPlayer.hasWeapon(itemName) then
  62. sourceXPlayer.removeWeapon(itemName)
  63. targetXPlayer.addWeapon(itemName, itemCount)
  64.  
  65. local weaponLabel = ESX.GetWeaponLabel(itemName)
  66.  
  67. if itemCount > 0 then
  68. TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon_ammo', weaponLabel, itemCount, targetXPlayer.name))
  69. TriggerClientEvent('esx:showNotification', target, _U('received_weapon_ammo', weaponLabel, itemCount, sourceXPlayer.name))
  70. TriggerEvent("esx:giveweaponalert",sourceXPlayer.name,targetXPlayer.name,weaponLabel)
  71. else
  72. TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, targetXPlayer.name))
  73. TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, sourceXPlayer.name))
  74. TriggerEvent("esx:giveweaponalert",sourceXPlayer.name,targetXPlayer.name,weaponLabel)
  75. end
  76. else
  77. TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))
  78. TriggerClientEvent('esx:showNotification', _source, _U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
  79. end
  80.  
  81. end
  82. end)
  83.  
  84. RegisterServerEvent('esx:removeInventoryItem')
  85. AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
  86. local _source = source
  87. local sourceXPlayer = ESX.GetPlayerFromId(_source)
  88.  
  89. if type == 'item_standard' then
  90.  
  91. if itemCount == nil or itemCount < 1 then
  92. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
  93. else
  94. local xPlayer = ESX.GetPlayerFromId(source)
  95. local xItem = xPlayer.getInventoryItem(itemName)
  96.  
  97. if (itemCount > xItem.count or xItem.count < 1) then
  98. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
  99. else
  100. xPlayer.removeInventoryItem(itemName, itemCount)
  101.  
  102. local pickupLabel = ('~y~%s~s~ [~b~%s~s~]'):format(xItem.label, itemCount)
  103. ESX.CreatePickup('item_standard', itemName, itemCount, pickupLabel, _source)
  104. TriggerClientEvent('esx:showNotification', _source, _U('threw_standard', itemCount, xItem.label))
  105. TriggerEvent("esx:removeitemalert",sourceXPlayer.name,ESX.Items[itemName].label,itemCount)
  106. end
  107. end
  108.  
  109. elseif type == 'item_money' then
  110.  
  111. if itemCount == nil or itemCount < 1 then
  112. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
  113. else
  114. local xPlayer = ESX.GetPlayerFromId(source)
  115. local playerCash = xPlayer.getMoney()
  116.  
  117. if (itemCount > playerCash or playerCash < 1) then
  118. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
  119. else
  120. xPlayer.removeMoney(itemCount)
  121.  
  122. local pickupLabel = ('~y~%s~s~ [~g~%s~s~]'):format(_U('cash'), _U('locale_currency', ESX.Math.GroupDigits(itemCount)))
  123. ESX.CreatePickup('item_money', 'money', itemCount, pickupLabel, _source)
  124. TriggerClientEvent('esx:showNotification', _source, _U('threw_money', ESX.Math.GroupDigits(itemCount)))
  125. TriggerEvent("esx:removemoneyalert",sourceXPlayer.name,itemCount)
  126.  
  127. end
  128. end
  129.  
  130. elseif type == 'item_account' then
  131.  
  132. if itemCount == nil or itemCount < 1 then
  133. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
  134. else
  135. local xPlayer = ESX.GetPlayerFromId(source)
  136. local account = xPlayer.getAccount(itemName)
  137.  
  138. if (itemCount > account.money or account.money < 1) then
  139. TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
  140. else
  141. xPlayer.removeAccountMoney(itemName, itemCount)
  142.  
  143. local pickupLabel = ('~y~%s~s~ [~g~%s~s~]'):format(account.label, _U('locale_currency', ESX.Math.GroupDigits(itemCount)))
  144. ESX.CreatePickup('item_account', itemName, itemCount, pickupLabel, _source)
  145. TriggerClientEvent('esx:showNotification', _source, _U('threw_account', ESX.Math.GroupDigits(itemCount), string.lower(account.label)))
  146. end
  147. end
  148.  
  149. elseif type == 'item_weapon' then
  150.  
  151. local xPlayer = ESX.GetPlayerFromId(source)
  152. local loadout = xPlayer.getLoadout()
  153.  
  154. for i=1, #loadout, 1 do
  155. if loadout[i].name == itemName then
  156. itemCount = loadout[i].ammo
  157. break
  158. end
  159. end
  160.  
  161. if xPlayer.hasWeapon(itemName) then
  162. local weaponLabel, weaponPickup = ESX.GetWeaponLabel(itemName), 'PICKUP_' .. string.upper(itemName)
  163.  
  164. xPlayer.removeWeapon(itemName)
  165.  
  166. if itemCount > 0 then
  167. TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, itemName, itemCount)
  168. TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon_ammo', weaponLabel, itemCount))
  169. TriggerEvent("esx:removeweaponalert",sourceXPlayer.name,weaponLabel)
  170. else
  171. -- workaround for CreateAmbientPickup() giving 30 rounds of ammo when you drop the weapon with 0 ammo
  172. TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, itemName, 1)
  173. TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel))
  174. TriggerEvent("esx:removeweaponalert",sourceXPlayer.name,weaponLabel)
  175.  
  176. end
  177. end
  178.  
  179. end
  180. end)
  181.  
  182. RegisterServerEvent('esx:useItem')
  183. AddEventHandler('esx:useItem', function(itemName)
  184. local xPlayer = ESX.GetPlayerFromId(source)
  185. local count = xPlayer.getInventoryItem(itemName).count
  186.  
  187. if count > 0 then
  188. ESX.UseItem(source, itemName)
  189. else
  190. TriggerClientEvent('esx:showNotification', xPlayer.source, _U('act_imp'))
  191. end
  192. end)
  193.  
  194. RegisterServerEvent('esx:onPickup')
  195. AddEventHandler('esx:onPickup', function(id)
  196. local _source = source
  197. local pickup = ESX.Pickups[id]
  198. local xPlayer = ESX.GetPlayerFromId(_source)
  199. local sourceXPlayer = ESX.GetPlayerFromId(_source)
  200.  
  201. if pickup.type == 'item_standard' then
  202.  
  203. local item = xPlayer.getInventoryItem(pickup.name)
  204. local canTake = ((item.limit == -1) and (pickup.count)) or ((item.limit - item.count > 0) and (item.limit - item.count)) or 0
  205. local total = pickup.count < canTake and pickup.count or canTake
  206. local remaining = pickup.count - total
  207.  
  208. TriggerClientEvent('esx:removePickup', -1, id)
  209.  
  210. if total > 0 then
  211. xPlayer.addInventoryItem(pickup.name, total)
  212. TriggerEvent("esx:pickupitemalert",sourceXPlayer.name,pickup.name,total)
  213. end
  214.  
  215. if remaining > 0 then
  216. TriggerClientEvent('esx:showNotification', _source, _U('cannot_pickup_room', item.label))
  217.  
  218. local pickupLabel = ('~y~%s~s~ [~b~%s~s~]'):format(item.label, remaining)
  219. ESX.CreatePickup('item_standard', pickup.name, remaining, pickupLabel, _source)
  220. end
  221.  
  222. elseif pickup.type == 'item_money' then
  223. TriggerClientEvent('esx:removePickup', -1, id)
  224. xPlayer.addMoney(pickup.count)
  225. TriggerEvent("esx:pickupmoneyalert",sourceXPlayer.name,pickup.count)
  226. elseif pickup.type == 'item_account' then
  227. TriggerClientEvent('esx:removePickup', -1, id)
  228. xPlayer.addAccountMoney(pickup.name, pickup.count)
  229. end
  230. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement