Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Pocket Shop
- A Shop using Pocket
- and Command Computers ]]
- local x, y, z = commands.getBlockPosition()
- local messages = {
- welcome = "[{text:\"Welcome to the Pocket Shop! Please open the given \",color:\"yellow\"},{text:\"Pocket Computer\",color:\"gold\"}]",
- }
- local chamberCoords = {
- {x+1, y+2, z}, {x-1, y+2, z},
- {x, y+2, z-1}, {x, y+4, z},
- }
- local items = {}
- local player
- hostRunning = true
- function loadItems()
- -- TODO
- table.insert( items, { id = "minecraft:stone", count = 1 } )
- end
- function chamber( lock )
- local block = lock and "stone_slab 7 keep" or "air"
- for _,v in pairs( chamberCoords ) do
- commands.async.setblock( v[1], v[2], v[3], block )
- end
- end
- function getPlayer()
- local s, r = commands.xp( "0 @a["..x..",".. y+2 ..","..z..",0]" )
- if s then
- return r[1]:match "Given 0 experience to (%w+)"
- else
- return false
- end
- end
- function handlePlayer( player )
- commands.async.tp( player, x, y+2, z )
- chamber( true )
- commands.async.give( player, "ComputerCraft:pocketComputer 1 1 {computerID:"..os.computerID()..",display:{Name:\"Pocket Shop\"}}" )
- commands.async.tellraw( player, messages.welcome )
- end
- function handleShop()
- while true do
- sleep(5)
- end
- end
- print "Starting Pocket Shop - Host"
- while hostRunning do
- print "Waiting for user"
- while not rs.getInput "top" do
- os.pullEvent "redstone"
- end
- player = getPlayer()
- print( "\nNew user: "..player )
- if player then
- handlePlayer( player )
- handleShop()
- end
- print( "User "..player.." quit.\n" )
- chamber()
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement