Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Nether PVP Arena
- Cell program
- --]]
- -- Load dependencies
- dofile("/common/all")
- program.load("../mcnet/message", "../mcnet/names", "../mcnet/device")
- program.load("../mcnet/devices/servant")
- program.load("msg", "devices/cell")
- -- Create cell
- local configPath = "/cell.conf"
- local defaultConfig = {
- name = "cell",
- domain = "netherpvp",
- detectTimeout = 1
- }
- local config = common.loadStore(configPath, defaultConfig)
- local cell = game.Cell:new{
- -- MCNet
- name = config.name,
- domain = config.domain,
- -- Game
- winTimeout = 5,
- -- Redstone
- getColorSide = "front",
- setColorSide = "back",
- setColorBit = colors.black,
- leverSide = "back",
- leverBit = colors.green,
- resetLeverSide = "back",
- resetLeverBit = colors.brown,
- openSide = "back",
- openBit = colors.red
- }
- print(" Address: "..mcnet.address.format(cell.address))
- print(" Computer ID: "..tostring(os.computerID()))
- print()
- -- Register handlers
- cell:on("registerServer", function(masterId)
- print("Registering master at ", masterId, "...")
- end)
- cell:on("registeredServer", function()
- print(" Successfully registered at master")
- end)
- cell:on("unregisteredServer", function(masterId)
- print("Unregistered master at ", masterId)
- end)
- cell:on("newRound", function()
- print("New round started")
- end)
- cell:on("winRound", function()
- print("Round won!")
- end)
- cell:on("char", function(char)
- if char == "q" then
- -- Confirm quit
- write("Confirm quit? [y/n] > ")
- local event, char = os.pullEvent("char")
- -- Check response
- local response = (string.lower(char) == "y" and "y") or "n"
- print(response)
- if (response == "y") then
- cell:stop()
- end
- end
- end)
- cell:on("error", function(errorType, errorMessage)
- print("[ERROR] "..errorMessage)
- end)
- -- Start
- print("Starting...")
- cell:start(config.detectTimeout)
- write(" Detected:")
- for i,deviceId in pairs(cell:neighbours()) do
- write(" "..deviceId)
- end
- print()
- print()
- -- Main loop
- print("Listening...")
- print(" Press Q to quit")
- print()
- while cell.isRunning do
- cell:trigger(os.pullEvent())
- end
- -- Stop
- print()
- print("Stopped")
- print()
Advertisement
Add Comment
Please, Sign In to add comment