Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function equipAndAttack()
- while true do
- local radar = peripheral.find("radar")
- if not radar and turtle then
- for i=1,16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == "computronics:radar" then -- Changed from "computronics:computronics.radar"
- turtle.select(i)
- turtle.equipRight()
- sleep(0.15)
- radar = peripheral.find("radar")
- break
- end
- end
- end
- end
- if radar then
- local entities = radar.getEntities()
- if entities and #entities > 0 then
- for _, entity in ipairs(entities) do
- if entity and entity.type == "mob" then
- local x, y, z = entity.x, entity.y, entity.z
- local distance = math.sqrt((x - turtle.point.x) ^ 2 + (z - turtle.point.z) ^ 2)
- if distance > 1 then
- -- Move towards the entity
- turtle.attack()
- sleep(0.5) -- Wait for a short time before attacking again
- else
- print("Reached entity. Attacking...")
- turtle.attack()
- sleep(0.5) -- Wait for a short time before attacking again
- end
- end
- end
- else
- print("No entities found. Scanning...")
- end
- else
- print("No radar found. Retrying...")
- sleep(5) -- Wait for 5 seconds before retrying
- end
- end
- end
- equipAndAttack() -- Start the function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement