Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. -- a basic gunshop implementation
  2. local Tunnel = module("vrp", "lib/Tunnel")
  3. local Proxy = module("vrp", "lib/Proxy")
  4.  
  5. vRPas = {}
  6. vRP = Proxy.getInterface("vRP")
  7. vRPclient = Tunnel.getInterface("vRP","vrp_armorshop")
  8. ASclient = Tunnel.getInterface("vrp_armorshop","vrp_armorshop")
  9. Tunnel.bindInterface("vrp_armorshop",vRPas)
  10.  
  11. local Lang = module("vrp", "lib/Lang")
  12. local lcfg = module("vrp", "cfg/base")
  13. local lang = Lang.new(module("vrp", "cfg/lang/"..lcfg.lang) or {})
  14.  
  15. local cfg = module("vrp_armorshop", "cfg/gunshops")
  16.  
  17. local gunshops = cfg.gunshops
  18. local gunshops_hidden = cfg.gunshops_hidden
  19. local gunshop_types = cfg.gunshop_types
  20.  
  21. local gunshop_menus = {}
  22.  
  23. function vRPas.updateArmor(armor)
  24. local user_id = vRP.getUserId({source})
  25. if user_id ~= nil then
  26. vRP.setUData({user_id,"vRP:bodyarmor",armor})
  27. end
  28. end
  29.  
  30. -- build gunshop menus
  31. for gtype,weapons in pairs(gunshop_types) do
  32. local gunshop_menu = {
  33. name=lang.gunshop.title({gtype}),
  34. css={top = "75px", header_color="rgba(255,0,0,0.75)"}
  35. }
  36.  
  37. -- build gunshop items
  38. local kitems = {}
  39.  
  40. -- item choice
  41. local gunshop_choice = function(player,choice)
  42. local weapon = kitems[choice][1]
  43. local price = kitems[choice][2]
  44. local price_ammo = kitems[choice][3]
  45.  
  46. if weapon then
  47. local user_id = vRP.getUserId({player})
  48. if weapon == "ARMOR" then-- get player weapons to not rebuy the body
  49. -- payment
  50. if user_id ~= nil and vRP.tryFullPayment({user_id,price}) then
  51. ASclient.setArmour(player,{100,true})
  52. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.paid({price})}, type = "success", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  53. else
  54. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.not_enough()}, type = "error", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  55. end
  56. elseif weapon == "ARMOR1" then-- get player weapons to not rebuy the body
  57. -- payment
  58. if user_id ~= nil and vRP.tryFullPayment({user_id,price}) then
  59. ASclient.setArmour(player,{math.random(2,5),true})
  60. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.paid({price})}, type = "success", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  61. else
  62. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.not_enough()}, type = "error", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  63. end
  64. else
  65. -- get player weapons to not rebuy the body
  66. vRPclient.getWeapons(player,{},function(weapons)
  67. -- prompt amount
  68. vRP.prompt({player,lang.gunshop.prompt_ammo({choice}),"",function(player,amount)
  69. local amount = parseInt(amount)
  70. if amount > 250 then
  71. amount = 250
  72. end
  73. if amount >= 0 then
  74. local total = math.ceil(parseFloat(price_ammo)*parseFloat(amount))
  75.  
  76. if weapons[string.upper(weapon)] == nil then -- add body price if not already owned
  77. total = total+price
  78. end
  79.  
  80. if amount > 250 then amount = 250
  81. end
  82.  
  83. -- payment
  84. if user_id ~= nil and vRP.tryFullPayment({user_id,total}) then
  85. vRPclient.giveWeapons(player,{{
  86. [weapon] = {ammo=amount}
  87. }})
  88.  
  89. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.paid({price})}, type = "success", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  90. else
  91. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.not_enough()}, type = "error", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  92. end
  93. else
  94. TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.common.invalid_value()}, type = "error", queue = "global", timeout = 4000, layout = "centerLeft",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
  95. end
  96. end})
  97. end)
  98. end
  99. end
  100. end
  101.  
  102. -- add item options
  103. for k,v in pairs(weapons) do
  104. if k ~= "_config" then -- ignore config property
  105. kitems[v[1]] = {k,math.max(v[2],0),math.max(v[3],0)} -- idname/price/price_ammo
  106. gunshop_menu[v[1]] = {gunshop_choice,lang.gunshop.info({v[2],v[3],v[4]})} -- add description
  107. end
  108. end
  109.  
  110. gunshop_menus[gtype] = gunshop_menu
  111. end
  112.  
  113. local function build_client_gunshops(source)
  114. local user_id = vRP.getUserId({source})
  115. if user_id ~= nil then
  116. for k,v in pairs(gunshops) do
  117. local gtype,x,y,z,hidden = table.unpack(v)
  118. local group = gunshop_types[gtype]
  119. local menu = gunshop_menus[gtype]
  120.  
  121. if group and menu then
  122. local gcfg = group._config
  123.  
  124. local function gunshop_enter()
  125. local user_id = vRP.getUserId({source})
  126. if user_id ~= nil and vRP.hasPermissions({user_id,gcfg.permissions or {}}) then
  127. vRP.openMenu({source,menu})
  128. end
  129. end
  130.  
  131. local function gunshop_leave()
  132. vRP.closeMenu({source})
  133. end
  134.  
  135. if hidden == true then
  136. vRPclient.addMarker(source,{x,y,z-0.87,0.7,0.7,0.5,0,255,125,125,150})
  137. vRP.setArea({source,"vRP:gunshop"..k,x,y,z,1,1.5,gunshop_enter,gunshop_leave})
  138. else
  139. vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.gunshop.title({gtype})})
  140. vRPclient.addMarker(source,{x,y,z-0.87,0.7,0.7,0.5,0,255,125,125,150})
  141. vRP.setArea({source,"vRP:gunshop"..k,x,y,z,1,1.5,gunshop_enter,gunshop_leave})
  142. end
  143. end
  144. end
  145. end
  146. end
  147.  
  148. AddEventHandler("vRP:playerSpawn",function(user_id, source, first_spawn)
  149. if first_spawn then
  150. build_client_gunshops(source)
  151. SetTimeout(30000,function() -- increase this if you have problems with armor not saving
  152. vRP.getUData({user_id,"vRP:bodyarmor",function(armor)
  153. if armor ~= nil then
  154. ASclient.setsArmour(source,{tonumber(armor),true})
  155. end
  156. end})
  157. end)
  158. end
  159. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement