SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function exchange(list,y,page) |
| 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 | - | checkmoney = "execute if entity @p[scores={money="..l[2].."..}] run "
|
| 8 | + | |
| 9 | - | invcheckmoney = "execute unless entity @p[scores={money="..l[2].."..}] run "
|
| 9 | + | local r,t,out = commands.exec("numismatic balance @p get")
|
| 10 | if out >= l[2] then | |
| 11 | - | exec(checkmoney.."give @p "..l[3].." "..l[4]) |
| 11 | + | commands.exec("numismatic balance @p subtract "..l[2])
|
| 12 | - | exec(checkmoney.."tellraw @p [{\"text\":\"Success! (You had \",\"color\":\"green\"},{\"score\":{\"name\":\"*\",\"objective\":\"money\"},\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
|
| 12 | + | commands.exec("give @p "..l[3].." "..l[4])
|
| 13 | - | exec(invcheckmoney.."tellraw @p [{\"text\":\"Not enough money! (You have \",\"color\":\"red\"},{\"score\":{\"name\":\"*\",\"objective\":\"money\"},\"color\":\"red\"},{\"text\":\"$)\",\"color\":\"red\"}]")
|
| 13 | + | commands.exec("tellraw @p [{\"text\":\"Success! You have "..out-l[2]..",\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
|
| 14 | - | exec(checkmoney.."scoreboard players remove @p money "..l[2]) |
| 14 | + | else |
| 15 | commands.exec("tellraw @p [{\"text\":\"Not enough money! You have: "..out.."$\",\"color\":\"red\"}]")
| |
| 16 | - | exec(checkstr.."scoreboard players add @p money "..l[2]) |
| 16 | + | |
| 17 | - | exec(checkstr.."tellraw @p [{\"text\":\"Success! (You have \",\"color\":\"green\"},{\"score\":{\"name\":\"*\",\"objective\":\"money\"},\"color\":\"green\"},{\"text\":\"$)\",\"color\":\"green\"}]")
|
| 17 | + | |
| 18 | - | exec(invcheck.."tellraw @p [{\"text\":\"Not enough items!\",\"color\":\"red\"}]")
|
| 18 | + | commands.exec(checkstr.."numismatic balance @p add "..l[2]) |
| 19 | - | exec(checkstr.."clear @p "..l[3].." "..l[4]) |
| 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 | - | exec(checkstr.."clear @p "..l[1].." "..l[2]) |
| 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 | - | function draw(list,page) |
| 24 | + | |
| 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 | - | page = 1 --+# |
| 50 | + | |
| 51 | - | table = {} --+#
|
| 51 | + | |
| 52 | local page = 1 --+# | |
| 53 | local table = {} --+#
| |
| 54 | --------------+ | |
| 55 | table[1] = {"sell",42,"minecraft:dirt",1}
| |
| 56 | - | draw(table,page) |
| 56 | + | |
| 57 | --------------- | |
| 58 | - | name,side,x,y = os.pullEvent("monitor_touch")
|
| 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 |