Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 "
- checkmoney = "execute if entity @p[scores={money="..l[2].."..}] run "
- invcheckmoney = "execute unless entity @p[scores={money="..l[2].."..}] run "
- if l[1] == "buy" then
- exec(checkmoney.."give @p "..l[3].." "..l[4])
- exec(checkmoney.."tellraw @p [{\"text\":\"Success! (You had \",\"color\":\"green\"},{\"score\":{\"name\":\"*\",\"objective\":\"money\"},\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
- exec(invcheckmoney.."tellraw @p [{\"text\":\"Not enough money! (You have \",\"color\":\"red\"},{\"score\":{\"name\":\"*\",\"objective\":\"money\"},\"color\":\"red\"},{\"text\":\"$)\",\"color\":\"red\"}]")
- exec(checkmoney.."scoreboard players remove @p money "..l[2])
- else
- exec(checkstr.."scoreboard players add @p money "..l[2])
- exec(checkstr.."tellraw @p [{\"text\":\"Success! (You have \",\"color\":\"green\"},{\"score\":{\"name\":\"*\",\"objective\":\"money\"},\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
- exec(invcheck.."tellraw @p [{\"text\":\"Not enough items!\",\"color\":\"red\"}]")
- exec(checkstr.."clear @p "..l[3].." "..l[4])
- end
- exec(checkstr.."clear @p "..l[1].." "..l[2])
- end
- end
- 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
- --------------+
- page = 1 --+#
- table = {} --+#
- --------------+
- table[1] = {"sell",42,"minecraft:dirt",1}
- table[2] = {"buy",69,"minecraft:amethyst_shard",1}
- ---------------
- draw(table,page)
- while true do
- name,side,x,y = os.pullEvent("monitor_touch")
- 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
Add Comment
Please, Sign In to add comment