Advertisement
RodrickLord

[Pocket Shop] Host

May 22nd, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. --[[ Pocket Shop
  2. A Shop using Pocket
  3. and Command Computers ]]
  4.  
  5. local x, y, z = commands.getBlockPosition()
  6.  
  7. local messages = {
  8. welcome = "[{text:\"Welcome to the Pocket Shop! Please open the given \",color:\"yellow\"},{text:\"Pocket Computer\",color:\"gold\"}]",
  9. }
  10.  
  11. local chamberCoords = {
  12. {x+1, y+2, z}, {x-1, y+2, z},
  13. {x, y+2, z-1}, {x, y+4, z},
  14. }
  15.  
  16. local items = {}
  17. local player
  18. hostRunning = true
  19.  
  20. function loadItems()
  21. -- TODO
  22. table.insert( items, { id = "minecraft:stone", count = 1 } )
  23. end
  24.  
  25. function chamber( lock )
  26. local block = lock and "stone_slab 7 keep" or "air"
  27. for _,v in pairs( chamberCoords ) do
  28. commands.async.setblock( v[1], v[2], v[3], block )
  29. end
  30. end
  31.  
  32. function getPlayer()
  33. local s, r = commands.xp( "0 @a["..x..",".. y+2 ..","..z..",0]" )
  34. if s then
  35. return r[1]:match "Given 0 experience to (%w+)"
  36. else
  37. return false
  38. end
  39. end
  40.  
  41. function handlePlayer( player )
  42. commands.async.tp( player, x, y+2, z )
  43. chamber( true )
  44. commands.async.give( player, "ComputerCraft:pocketComputer 1 1 {computerID:"..os.computerID()..",display:{Name:\"Pocket Shop\"}}" )
  45. commands.async.tellraw( player, messages.welcome )
  46. end
  47.  
  48. function handleShop()
  49. while true do
  50. sleep(5)
  51. end
  52. end
  53.  
  54. print "Starting Pocket Shop - Host"
  55.  
  56. while hostRunning do
  57. print "Waiting for user"
  58. while not rs.getInput "top" do
  59. os.pullEvent "redstone"
  60. end
  61. player = getPlayer()
  62. print( "\nNew user: "..player )
  63. if player then
  64. handlePlayer( player )
  65. handleShop()
  66. end
  67. print( "User "..player.." quit.\n" )
  68. chamber()
  69. sleep(5)
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement