Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function exchange(list,y,page)
- w,h = term.getSize()
- y=y+(h-1)*(page-1)
- local l = list[y]
- if y<=#list then
- invcheck = "execute unless entity @p[nbt={Inventory:[{id:\""..l[3].."\",Count:"..l[4].."b}]}] run "
- checkstr = "execute if entity @p[nbt={Inventory:[{id:\""..l[3].."\",Count:"..l[4].."b}]}] run "
- if l[1] == "buy" then
- local r,t,out = commands.exec("numismatic balance @p get")
- if out >= l[2] then
- commands.exec("numismatic balance @p subtract "..l[2])
- commands.exec("give @p "..l[3].." "..l[4])
- commands.exec("tellraw @p [{\"text\":\"Success! You have "..out-l[2]..",\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
- else
- commands.exec("tellraw @p [{\"text\":\"Not enough money! You have: "..out.."$\",\"color\":\"red\"}]")
- end
- else
- commands.exec(checkstr.."numismatic balance @p add "..l[2])
- local r,t,out = commands.exec("numismatic balance @p get")
- commands.exec(checkstr.."tellraw @p [{\"text\":\"Success! You have "..out.."$\",\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
- commands.exec(invcheck.."tellraw @p [{\"text\":\"Not enough items!\",\"color\":\"red\"}]")
- commands.exec(checkstr.."clear @p "..l[3].." "..l[4])
- end
- end
- end
- local function draw(list,page)
- term.redirect(peripheral.wrap("top"))
- peripheral.wrap("top").setTextScale(0.5)
- term.clear()
- term.setCursorPos(1,1)
- w,h = term.getSize()
- pages = 1
- if h>#list then
- pages = math.floor(#list/(h-1))
- end
- for i=1+(h-1)*(page-1),(h-1)*page do
- if i>#list then break end
- if list[i][1] == "sell" then
- print(list[i][4].." "..list[i][3].." -> "..list[i][2].."$")
- else
- print(list[i][2].."$ -> "..list[i][4].." "..list[i][3])
- end
- end
- term.setCursorPos(1,h)
- write("<<<")
- term.setCursorPos(math.floor(w/2),h)
- write(page)
- term.setCursorPos(w-2,h)
- write(">>>")
- end
- --------------+
- local page = 1 --+#
- local table = {} --+#
- --------------+
- table[1] = {"sell",42,"minecraft:dirt",1}
- table[2] = {"buy",69,"minecraft:amethyst_shard",1}
- ---------------
- local draw(table,page)
- while true do
- local name,side,x,y = os.pullEvent("monitor_touch")
- local w,h = term.getSize()
- if y<h then
- exchange(table,y,page)
- else
- if x<w/2 then
- page=page-1
- if page<1 then
- page = math.ceil(#table/(h-1))
- end
- else
- page=page+1
- if page>math.ceil(#table/(h-1)) then
- page = 1
- end
- end
- end
- draw(table,page)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement