Advertisement
fremnet

MultiMobLavaBot

Mar 15th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. RADIO="right"
  2.  
  3. controller = nil
  4.  
  5. function checkLavaOn()
  6. return turtle.compareTo(2)
  7. end
  8.  
  9. function processMessage(data)
  10. if data["action"] == "acknowledge" or (data["action"] == "announce" and data["device"] == "controller") then
  11. controller = data["computer_id"]
  12. if data["action"] == "announce" then
  13. rednet.send(data["computer_id"], textutils.serialize({action="acknowledge", type="multimob", device="lavabot"}))
  14. end
  15. elseif data["action"] == "lava" then
  16. if data["state"] == "on" then
  17. if checkLavaOn() then
  18. turtle.place()
  19. end
  20. rednet.send(controller, textutils.serialize({action="lava", state="on", type="multimob", device="lavabot"}))
  21. elseif data["state"] == "off" then
  22. if not checkLavaOn() then
  23. turtle.place()
  24. end
  25. rednet.send(controller, textutils.serialize({action="lava", state="off", type="multimob", device="lavabot"}))
  26. end
  27. end
  28. end
  29.  
  30. if peripheral.isPresent(RADIO) and peripheral.getType(RADIO) == "modem" then
  31. rednet.open(RADIO)
  32. rednet.broadcast(textutils.serialize({action="announce", type="multimob", device="lavabot"}))
  33. else
  34. print("Modem not found")
  35. return
  36. end
  37.  
  38. while true do
  39. ev,p1,p2,p3 = os.pullEvent()
  40. if ev == "rednet_message" then
  41. data = textutils.unserialize(p2)
  42. if data["type"] == "multimob" then
  43. data["computer_id"] = p1
  44. processMessage(data)
  45. end
  46. end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement