Advertisement
AdditionalPylons

Numismatic

Mar 1st, 2024 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function exchange(list,y,page)
  2.     w,h = term.getSize()
  3.     y=y+(h-1)*(page-1)
  4.     local l = list[y]
  5.     if y<=#list then
  6.         invcheck = "execute unless entity @p[nbt={Inventory:[{id:\""..l[3].."\",Count:"..l[4].."b}]}] run "
  7.         checkstr = "execute if entity @p[nbt={Inventory:[{id:\""..l[3].."\",Count:"..l[4].."b}]}] run "
  8.         if l[1] == "buy" then
  9.             local r,t,out = commands.exec("numismatic balance @p get")
  10.             if out >= l[2] then
  11.                 commands.exec("numismatic balance @p subtract "..l[2])
  12.                 commands.exec("give @p "..l[3].." "..l[4])
  13.                 commands.exec("tellraw @p [{\"text\":\"Success! You have "..out-l[2]..",\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
  14.             else
  15.                 commands.exec("tellraw @p [{\"text\":\"Not enough money! You have: "..out.."$\",\"color\":\"red\"}]")
  16.             end
  17.         else
  18.             commands.exec(checkstr.."numismatic balance @p add "..l[2])
  19.             local r,t,out = commands.exec("numismatic balance @p get")
  20.             commands.exec(checkstr.."tellraw @p [{\"text\":\"Success! You have "..out.."$\",\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
  21.             commands.exec(invcheck.."tellraw @p [{\"text\":\"Not enough items!\",\"color\":\"red\"}]")
  22.             commands.exec(checkstr.."clear @p "..l[3].." "..l[4])
  23.         end
  24.     end
  25. end
  26. local function draw(list,page)
  27.     term.redirect(peripheral.wrap("top"))
  28.     peripheral.wrap("top").setTextScale(0.5)
  29.     term.clear()
  30.     term.setCursorPos(1,1)
  31.     w,h = term.getSize()
  32.     pages = 1
  33.     if h>#list then
  34.         pages = math.floor(#list/(h-1))
  35.     end
  36.     for i=1+(h-1)*(page-1),(h-1)*page do
  37.         if i>#list then break end
  38.         if list[i][1] == "sell" then
  39.             print(list[i][4].." "..list[i][3].." -> "..list[i][2].."$")
  40.         else
  41.             print(list[i][2].."$ -> "..list[i][4].." "..list[i][3])
  42.         end
  43.     end
  44.     term.setCursorPos(1,h)
  45.     write("<<<")
  46.     term.setCursorPos(math.floor(w/2),h)
  47.     write(page)
  48.     term.setCursorPos(w-2,h)
  49.     write(">>>")
  50. end
  51. --------------+
  52. local page = 1   --+#
  53. local table = {} --+#
  54. --------------+
  55. table[1] = {"sell",42,"minecraft:dirt",1}
  56. table[2] = {"buy",69,"minecraft:amethyst_shard",1}
  57. ---------------
  58. local draw(table,page)
  59. while true do
  60.     local name,side,x,y = os.pullEvent("monitor_touch")
  61.     local w,h = term.getSize()
  62.     if y<h then
  63.         exchange(table,y,page)
  64.     else
  65.         if x<w/2 then
  66.             page=page-1
  67.             if page<1 then
  68.                 page = math.ceil(#table/(h-1))
  69.             end
  70.         else
  71.             page=page+1
  72.             if page>math.ceil(#table/(h-1)) then
  73.                 page = 1
  74.             end
  75.         end
  76.     end
  77.     draw(table,page)
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement