Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ni = peripheral.wrap("back")
- local R2D = 180/math.pi
- local immu = {
- ["bastoup"] = true,
- ["boubechcraft"] = true,
- ["maxouel54"] = true,
- ["chipax"] = true,
- ["cargolion"] = true,
- ["cow"] = true,
- ["quark:foxhound"] = true,
- ["sheep"] = true,
- ["chicken"] = true,
- ["skeletonhorse"] = true,
- ["horse"] = true,
- ["actuallyadditions.worm"] = true,
- ["villager"] = true,
- ["item"] = true,
- ["plethora:laser"] = true
- }
- local parcours = {
- {
- x = -197,
- y = 70,
- z = 5799
- },
- {
- x = -197,
- y = 70,
- z = 5806
- },
- {
- x = -203,
- y = 70,
- z = 5806
- },
- {
- x = -213,
- y = 69,
- z = 5808
- },
- {
- x = -213,
- y = 69,
- z = 5803
- },
- {
- x = -211,
- y = 70,
- z = 5788
- },
- {
- x = -204,
- y = 70,
- z = 5790
- },
- {
- x = -204,
- y = 70,
- z = 5790
- },
- {
- x = -196,
- y = 70,
- z = 5791
- }
- }
- ni.disableAI()
- local max = #parcours
- local current = 1
- local function nextPoint()
- if current == max then
- current = 1
- else
- current = current + 1
- end
- end
- local function dist(x,y)
- return math.sqrt(x*x + y*y)
- end
- local function distToCurrent()
- local x, _, z = gps.locate(5)
- return dist(parcours[current].x - x, parcours[current].z - z)
- end
- local function goToCurrent()
- local x, y, z = gps.locate(5)
- local r = ni.walk(parcours[current].x - x, parcours[current].y - y, parcours[current].z - z)
- if not r then
- nextPoint()
- print("ERROR: cannot reach destination n°" .. tostring(current) .. ".")
- end
- end
- local function shootAt(x,y,z,p)
- local d = dist(x,z)
- local phi = -90
- local theta = 0
- if d == 0 then
- local sign = y/math.abs(y)
- phi = sign*phi
- else
- local nz = z/d
- theta = R2D*math.acos(nz)
- if x > 0 then
- theta = (-theta)%360
- end
- local ny = y/d
- phi = -R2D*math.atan(ny)
- end
- ni.fire(theta, phi, p)
- end
- local function scanArea()
- local _, y, _ = gps.locate(5)
- local r = ni.sense()
- for _,v in pairs(r) do
- if (not immu[string.lower(v.name)]) and v.y > -3 then
- return v
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Patrol started !")
- while true do
- mob = scanArea()
- if mob then
- ni.walk(0,0,0)
- local prev = ""
- repeat
- if not (mob.id == prev) then
- prev = mob.id
- print("Found entity " .. mob.name .. "! Started shooting !")
- end
- shootAt(mob.x, mob.y, mob.z, 0.5)
- sleep(0)
- mob = scanArea()
- until (not mob)
- print("No more entity to shoot. Continuing patrol.")
- else
- if distToCurrent() < 2 then
- nextPoint()
- end
- if not ni.isWalking() then
- goToCurrent()
- end
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment