Advertisement
Guest User

guns

a guest
Mar 20th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. os.unloadAPI("buttons")
  2. os.unloadAPI("gundata")
  3. os.loadAPI("buttons")
  4. os.loadAPI("gundata")
  5.  
  6. log = fs.open("log", "w")
  7.  
  8.  
  9. gun_buttons = {}
  10. gun = nil
  11.  
  12. ammo_buttons = {}
  13. ammo = nil
  14.  
  15. print_button = nil
  16.  
  17. function updatePrintButton()
  18.   if (gun ~= nil and ammo ~= nil) then
  19.     buttons.setColor(print_button, colors.white, colors.green)
  20.   end
  21. end
  22.  
  23. function pickGun(string)
  24.   log.writeLine("Set gun " .. string)
  25.   if gun ~= nil then
  26.     buttons.setColor(gun_buttons[string], colors.white, colors.black)
  27.   end
  28.   gun = string
  29.   buttons.setColor(gun_buttons[string], colors.white, colors.green)
  30.   updatePrintButton()
  31. end  
  32.  
  33. function pickAmmo(string)
  34.   log.writeLine("Set ammo "..string)
  35.   if ammo ~= nil then
  36.     buttons.setColor(ammo_buttons[string], colors.white, colors.black)
  37.   end
  38.   ammo = string
  39.   buttons.setColor(ammo_buttons[string], colors.white, colors.green)
  40.   updatePrintButton()
  41. end
  42.  
  43. x = 3
  44. y = 2
  45.  
  46. for gun in pairs(gundata.guns) do
  47.   f = function()
  48.     --log.writeLine("f was called")
  49.     pickGun(gun)
  50.   end
  51.   gun_buttons[gun] = buttons.register(x, y, 10, 1, colors.white, colors.black, gun, f)
  52.   y = y + 2
  53. end
  54.  
  55. x = x + 13
  56. y = 2
  57.  
  58. for ammo in pairs(gundata.ammo) do
  59.   f = function()
  60.     pickAmmo(ammo)
  61.   end
  62.   ammo_buttons[ammo] = buttons.register(x, y, 10, 1, colors.white, colors.black, ammo, f)
  63.   y = y + 1
  64. end
  65.  
  66. printGun = function()
  67.   ok, result = commands.exec("give @p " .. gundata.guns[gun] .. " 1 0 ".. "{ammo:[0:{id:" .. gundata.ammo[ammo] .."s,Count:1b,Damage:0s}]}")
  68.   if ok == false then
  69.     log.writeLine("Print gun result: " .. result)
  70.   end
  71. end
  72.  
  73. x = x + 13
  74. y = 4
  75.  
  76. print_button = buttons.register(x, y, 10, 3, colors.white, colors.red, "Make gun!", printGun)
  77.  
  78. while true do
  79.   buttons.draw()
  80.   eventTable = {os.pullEvent()}
  81.   buttons.event(eventTable)
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement