Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- turtle.refuel()
- m = peripheral.wrap("right")
- --m.open(1)
- --x,y,z = -511, 95, 167
- facing = "z-"
- function fxp ()
- if facing=="x+" then return
- elseif facing =="x-" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing=="z-" then turtle.turnRight()
- elseif facing=="z+" then turtle.turnLeft()
- end
- facing="x+"
- end
- function fxm ()
- if facing=="x+" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing=="x-" then return
- elseif facing=="z-" then turtle.turnLeft()
- elseif facing=="z+" then turtle.turnRight()
- end
- facing="x-"
- end
- function fzp ()
- if facing=="x+" then turtle.turnRight()
- elseif facing=="x-" then turtle.turnLeft()
- elseif facing=="z+" then return
- elseif facing=="z-" then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- facing="z+"
- end
- function fzm ()
- if facing=="x+" then turtle.turnLeft()
- elseif facing=="x-" then turtle.turnRight()
- elseif facing=="z+" then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif facing=="z-" then return
- end
- facing="z-"
- end
- function move (tx,ty,tz)
- x,y,z=0,0,0
- dx=tx
- dy=ty
- dz=tz
- max = math.max(math.abs(dx), math.abs(dy),math.abs(dz))
- if dy>0.5 and math.abs(dy)==max then
- turtle.up()
- y = y+1
- dy=ty-y
- elseif dy<-0.5 and math.abs(dy)==max then
- turtle.down()
- y=y-1
- dy=ty-y
- elseif dx>0.5 and math.abs(dx)==max then
- fxp()
- -- while dx>0 do
- turtle.forward()
- x = x+1
- dx = tx-x
- -- end
- elseif dx<-0.5 and math.abs(dx)==max then
- fxm()
- -- while dx<0 do
- turtle.forward()
- x=x-1
- dx = tx-x
- -- end
- elseif dz>0.5 and math.abs(dz)==max then
- fzp()
- -- while dz>0 do
- turtle.forward()
- z=z+1
- dz = tz-z
- -- end
- elseif dz<-0.5 and math.abs(dz)==max then
- fzm()
- -- while dz<0 do
- turtle.forward()
- z=z-1
- dz = tz-z
- -- end
- end
- end
- function contains (t, val)
- for index, value in ipairs(t) do
- if value.id==val then
- return true
- end
- end
- return false
- end
- function euDist (ax,ay,az,bx,by,bz)
- cx = math.abs(ax)-math.abs(bx)
- cy = math.abs(ay)-math.abs(by)
- cz = math.abs(az)-math.abs(bz)
- return math.sqrt(cx*cx+cy*cy+cz*cz)
- end
- --turtle.refuel()
- --m = peripheral.wrap("left")
- --facing="z-"
- ignore = {"McSkizz", "lilfinn", "Mentiad", "Item", "Arrow", "XPOrb", "SmallFireball", "ThrownPotion"}
- ignLookup={}
- for i=1,#ignore do
- ignLookup[ignore[i]]=true
- end
- current = {id=0}
- McSkizz = {}
- while true do
- event, key = os.pullEvent()
- if event=="key" and key==keys.x then
- os.exit()
- end
- curMobs = {}
- mobs = m.sense()
- for i=1,#mobs do
- if mobs[i].name=="McSkizz" then McSkizz = mobs[i] end
- if not ignLookup[mobs[i].name] then
- curMobs[#curMobs+1]=mobs[i]
- end
- end
- McDist = euDist(0,0,0,McSkizz.x,McSkizz.y,McSkizz.z)
- if McDist>10 then
- current=McSkizz
- elseif #curMobs>0 then
- closestD = 50
- closest={}
- for i=1,#curMobs do
- mob = curMobs[i]
- if euDist(0,0,0,mob.x,mob.y,mob.z)<closestD then
- closestD=euDist(0,0,0,mob.x,mob.y,mob.z)
- closest=mob
- end
- end
- current = closest
- else
- current = McSkizz
- end
- print(current.name)
- if current.name~="McSkizz" then
- move(current.x,current.y+1,current.z)
- turtle.attackDown()
- turtle.attack()
- turtle.attackUp()
- else
- move(current.x, current.y+1, current.z)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement