Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RADIO="top"
- MONITOR="left"
- BUNDLE="right"
- DELAY=0.5
- XPGate = colors.white
- MidwayGate = colors.lightBlue
- RoofGate = colors.brown
- AttackGate = colors.green
- WitherSkeleton = colors.lime
- Cow = colors.red
- Clamp = colors.orange
- LongDrop = XPGate + MidwayGate + AttackGate
- XP = 0
- Safe = LongDrop + RoofGate + Clamp
- BotResponses = 0
- Roof = nil
- LavaBot = nil
- monitor = nil
- state = 0
- selection = nil
- function colorOn(color)
- local c = redstone.getBundledOutput(BUNDLE)
- c = colors.combine(c, color)
- redstone.setBundledOutput(BUNDLE, c)
- end
- function colorOff(color)
- local c = redstone.getBundledOutput(BUNDLE)
- c = colors.subtract(c, color)
- redstone.setBundledOutput(BUNDLE, c)
- end
- function colorToggle(color)
- local c = redstone.getBundledOutput(BUNDLE)
- if colors.test(c, color) then
- c = colors.subtract(c, color)
- else
- c = colors.combine(c, color)
- end
- redstone.setBundledOutput(BUNDLE, c)
- end
- function doorIsDown()
- print("- doorIsDown?")
- c = redstone.getBundledInput(BUNDLE)
- return colors.test(c, colors.pink)
- end
- function moveDoor(color)
- for i = 1, 5 do
- colorOn(color)
- os.sleep(DELAY)
- colorOff(color)
- os.sleep(DELAY)
- end
- end
- function moveDoorUp()
- print("- moveDoorUp")
- colorOff(Clamp)
- sleep(0.2)
- moveDoor(colors.yellow)
- end
- function moveDoorDown()
- print("- moveDoorDown")
- moveDoor(colors.purple)
- colorOn(Clamp)
- end
- function reset()
- print("- reset")
- roofMobOff()
- disarmAttackBots()
- if not doorIsDown() then
- moveDoorDown()
- end
- redstone.setBundledOutput(BUNDLE, Safe)
- lava(false)
- end
- function lava(on)
- packet = {action="lava", type="multimob", device="controller"}
- if on then
- packet["state"] = "on"
- else
- packet["state"] = "off"
- end
- rednet.send(LavaBot, textutils.serialize(packet))
- end
- function armAttackBots()
- print("- armAttackBots")
- colorOff(AttackGate)
- sleep(0.2)
- -- This is lazy, should look for a response from the turtles and do it in the event loop
- for i = 1, 5 do
- rednet.broadcast(textutils.serialize({action="attack", state="on", type="multimob", device="controller"}))
- sleep(0.1)
- end
- end
- function disarmAttackBots()
- print("- disarmAttackBots")
- -- This is lazy, should look for a response from the turtles and do it in the event loop
- for i = 1, 5 do
- rednet.broadcast(textutils.serialize({action="attack", state="off", type="multimob", device="controller"}))
- sleep(0.1)
- end
- sleep(0.5)
- colorOn(AttackGate)
- sleep(5)
- end
- function beef()
- roofMobOff()
- lava(true)
- colorOn(RoofGate + XPGate)
- colorOff(MidwayGate)
- if doorIsDown() then
- moveDoorUp()
- end
- disarmAttackBots()
- colorOn(Cow)
- end
- function witherSkeleton()
- roofMobOff()
- lava(false)
- colorOn(RoofGate)
- colorOff(XPGate + MidwayGate)
- armAttackBots()
- if not doorIsDown() then
- moveDoorDown()
- end
- colorOn(WitherSkeleton)
- end
- function roofMob(mob)
- lava(false)
- colorOn(XPGate)
- if doorIsDown() then
- moveDoorUp()
- else
- sleep(2)
- end
- disarmAttackBots()
- colorOff(RoofGate)
- colorOn(LongDrop)
- rednet.send(Roof, textutils.serialize({action="mobon", mob=mob, type="multimob", device="controller"}))
- end
- function roofMobOff()
- rednet.send(Roof, textutils.serialize({action="off", type="multimob", device="controller"}))
- end
- function skeleton()
- roofMob("skeleton")
- end
- function creaper()
- roofMob("creaper")
- end
- function pigmen()
- roofMob("pigmen")
- end
- function processAcknowledge(data)
- if data["device"] == "roof" then
- print("Found roof device " .. data["computer_id"])
- Roof = data["computer_id"]
- elseif data["device"] == "lavabot" then
- print("Found lavabot device " .. data["computer_id"])
- LavaBot = data["computer_id"]
- elseif data["device"] == "xpbot" then
- print("Found xpbot device " .. data["computer_id"])
- BotResponses = BotResponses + 1
- -- do nothing
- end
- if not(Roof == nil) and not(LavaBot == nil) and BotResponses == 2 and state == 0 then
- state = 1
- renderMenu()
- end
- if data["action"] == "announce" then
- rednet.send(data["computer_id"], textutils.serialize({action="acknowledge", type="multimob", device="controller"}))
- end
- end
- function processMessage(data)
- if data["action"] == "acknowledge" or (data["action"] == "announce") then
- processAcknowledge(data)
- elseif data["action"] == "attack" then
- if data["state"] == "on" and not attacking then
- turtle.forward()
- attacking = true
- currentTimer = os.startTimer(SLEEP)
- rednet.send(controller, textutils.serialize({action="attack", state="on", type="multimob", device="xpbot"}))
- elseif data["state"] == "off" and attacking then
- currentTimer = nil
- emptyItems(true)
- attacking = false
- rednet.send(controller, textutils.serialize({action="attack", state="off", type="multimob", device="xpbot"}))
- end
- end
- end
- function renderMode(mode)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("MultiMob")
- monitor.setCursorPos(1,2)
- monitor.write("----------------------------")
- monitor.setCursorPos(1,3)
- monitor.write("Mode selected:")
- monitor.setCursorPos(3,4)
- monitor.write(mode)
- renderWait()
- selection = mode
- end
- function renderWait()
- monitor.setCursorPos(10,5)
- monitor.clearLine()
- monitor.write("Please wait...")
- end
- function renderMenu()
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("MultiMob - Right click mode")
- monitor.setCursorPos(1,2)
- monitor.write("----------------------------")
- monitor.setCursorPos(2,3)
- monitor.write("1) XP Farm/Wither Skeleton")
- monitor.setCursorPos(2,4)
- monitor.write("2) Cooked beef")
- monitor.setCursorPos(2,5)
- monitor.write("3) Skeletons/Bones&Arrows")
- monitor.setCursorPos(2,6)
- monitor.write("4) Creeper/Gunpowder")
- monitor.setCursorPos(2,7)
- monitor.write("5) Zombie Pigman")
- end
- function checkButton(x, y)
- if state == 1 and y >= 3 and y <= 7 then
- state = 2
- if y == 3 then
- renderMode("XP Farm/Wither Skeleton")
- witherSkeleton()
- elseif y == 4 then
- renderMode("Cooked beef")
- beef()
- elseif y == 5 then
- renderMode("Skeletons")
- skeleton()
- elseif y == 6 then
- renderMode("Creeper")
- creaper()
- elseif y == 7 then
- renderMode("Zombie Pigman")
- pigmen()
- end
- monitor.setCursorPos(1,5)
- monitor.clearLine()
- monitor.write("Ready")
- monitor.setCursorPos(18,12)
- monitor.write("End/Done")
- state = 3
- elseif state == 3 and y == 12 and x >= 12 then
- state = 4
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("MultiMob")
- monitor.setCursorPos(1,2)
- monitor.write("----------------------------")
- monitor.setCursorPos(1,3)
- monitor.write("Resetting...")
- renderWait()
- if selection == "XP Farm/Wither Skeleton" or selection == "Cooked beef" then
- colorOff(WitherSkeleton + Cow)
- sleep(5)
- colorOff(MidwayGate)
- sleep(30)
- reset()
- else
- reset()
- end
- state = 1
- renderMenu()
- end
- end
- monitor = peripheral.wrap(MONITOR)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Startup....")
- monitor.setCursorPos(2,2)
- monitor.write("Looking for MultiMob parts...")
- if peripheral.isPresent(RADIO) and peripheral.getType(RADIO) == "modem" then
- rednet.open(RADIO)
- rednet.broadcast(textutils.serialize({action="announce", type="multimob", device="controller"}))
- else
- print("Modem not found")
- return
- end
- while true do
- ev,p1,p2,p3 = os.pullEvent()
- if ev == "rednet_message" then
- data = textutils.unserialize(p2)
- if data["type"] == "multimob" then
- data["computer_id"] = p1
- processMessage(data)
- end
- elseif ev == "char" then
- if p1 == "r" then
- reset()
- elseif p1 == "s" then
- skeleton()
- elseif p1 == "c" then
- creaper()
- elseif p1 == "w" then
- witherSkeleton()
- elseif p1 == "b" then
- beef()
- end
- elseif ev == "monitor_touch" then
- checkButton(p2, p3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement