Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RADIO="right"
- SLEEP = 0.1
- currentTimer = nil
- attacking = false
- controller = nil
- function emptyItems(stay)
- rednet.send(controller, textutils.serialize({action="dump", type="multimob", device="xpbot"}))
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- turtle.turnRight()
- turtle.turnRight()
- if stay == nil then
- turtle.forward()
- end
- end
- function processMessage(data)
- if data["action"] == "acknowledge" or (data["action"] == "announce" and data["device"] == "controller") then
- controller = data["computer_id"]
- if data["action"] == "announce" then
- rednet.send(data["computer_id"], textutils.serialize({action="acknowledge", type="multimob", device="xpbot"}))
- end
- 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
- if peripheral.isPresent(RADIO) and peripheral.getType(RADIO) == "modem" then
- rednet.open(RADIO)
- rednet.broadcast(textutils.serialize({action="announce", type="multimob", device="xpbot"}))
- 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 == "timer" and currentTimer == p1 then
- turtle.attack()
- if turtle.getItemCount(16) > 16 then
- emptyItems()
- end
- currentTimer = os.startTimer(SLEEP)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement