Advertisement
Guest User

Untitled

a guest
May 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. function OpenBuyWeaponsMenu()
  2.  
  3. local elements = {}
  4. local playerPed = PlayerPedId()
  5. PlayerData = ESX.GetPlayerData()
  6.  
  7. for k,v in ipairs(Config.AuthorizedWeapons[PlayerData.job.grade_name]) do
  8. local weaponNum, weapon = ESX.GetWeapon(v.weapon)
  9. local components, label = {}
  10.  
  11. local hasWeapon = HasPedGotWeapon(playerPed, GetHashKey(v.weapon), false)
  12.  
  13. if v.components then
  14. for i=1, #v.components do
  15. if v.components[i] then
  16.  
  17. local component = weapon.components[i]
  18. local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash)
  19.  
  20. if hasComponent then
  21. label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_owned'))
  22. else
  23. if v.components[i] > 0 then
  24. label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_item', ESX.Math.GroupDigits(v.components[i])))
  25. else
  26. label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_free'))
  27. end
  28. end
  29.  
  30. table.insert(components, {
  31. label = label,
  32. componentLabel = component.label,
  33. hash = component.hash,
  34. name = component.name,
  35. price = v.components[i],
  36. hasComponent = hasComponent,
  37. componentNum = i
  38. })
  39. end
  40. end
  41. end
  42.  
  43. if hasWeapon and v.components then
  44. label = ('%s: <span style="color:green;">></span>'):format(weapon.label)
  45. elseif hasWeapon and not v.components then
  46. label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_owned'))
  47. else
  48. if v.price > 0 then
  49. label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_item', ESX.Math.GroupDigits(v.price)))
  50. else
  51. label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_free'))
  52. end
  53. end
  54.  
  55. table.insert(elements, {
  56. label = label,
  57. weaponLabel = weapon.label,
  58. name = weapon.name,
  59. components = components,
  60. price = v.price,
  61. hasWeapon = hasWeapon
  62. })
  63. end
  64.  
  65. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_buy_weapons', {
  66. title = _U('armory_weapontitle'),
  67. align = 'bottom-right',
  68. elements = elements
  69. }, function(data, menu)
  70.  
  71. if data.current.hasWeapon then
  72. if #data.current.components > 0 then
  73. OpenWeaponComponentShop(data.current.components, data.current.name, menu)
  74. end
  75. else
  76. ESX.TriggerServerCallback('esx_policejob:buyWeapon', function(bought)
  77. if bought then
  78. if data.current.price > 0 then
  79. ESX.ShowNotification(_U('armory_bought', data.current.weaponLabel, ESX.Math.GroupDigits(data.current.price)))
  80. end
  81.  
  82. menu.close()
  83.  
  84. OpenBuyWeaponsMenu()
  85. else
  86. ESX.ShowNotification(_U('armory_money'))
  87. end
  88. end, data.current.name, 1)
  89. end
  90.  
  91. end, function(data, menu)
  92. menu.close()
  93. end)
  94.  
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement