Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mode="shoot"
- ni=peripheral.wrap("back")
- function getAngle(x,y)
- return (180/math.pi)*math.atan(y,x)
- end
- function getDistance(block)
- vec=vector.new(block.x,block.y,block.z)
- return vec.length(vec)
- end
- function swing()
- while true do
- ni.swing()
- end
- end
- function use()
- while true do
- ni.use()
- end
- end
- function moveTo(x,y,z,power)
- pitch = -math.atan2(y, math.sqrt(x * x + z * z))
- yaw = math.atan2(-x, z)
- ni.launch(math.deg(yaw),math.deg(pitch),power)
- end
- function moveToBlock(filter,meta)
- while true do
- blocks={}
- ni.canvas3d().clear()
- c3d=ni.canvas3d().create()
- --c3d.recenter()
- for _, block in pairs(ni.scan()) do
- if string.find(block.name,filter) and block.metadata==meta then
- table.insert(blocks,block)
- end
- end
- table.sort(blocks,function(a,b) return getDistance(a)<getDistance(b) end)
- if #blocks>0 then
- block=blocks[1]
- msg=(("The block at %d, %d, %d is %s"):format(block.x, block.y, block.z, block.name))
- ni.tell(msg)
- pitch = -math.atan2(block.y, math.sqrt(block.x * block.x + block.z * block.z))
- yaw = math.atan2(-block.x, block.z)
- ni.fire(math.deg(yaw),math.deg(pitch),5)
- c3d.addLine({x=0,y=0,z=0},{block.x, block.y, block.z})
- --moveTo(block.x,block.y,block.z)
- print(msg)
- end
- sleep(0.5)
- end
- end
- function follow(mobFilter)
- while true do
- mobs=ni.sense()
- mobs=filterArray(mobs,mobFilter)
- table.sort(mobs,function(a,b) return getDistance(a)<getDistance(b) end)
- if #mobs>1 then
- mob=mobs[2]
- if getDistance(mob)<16 and getDistance(mob)>2 then
- msg=(("The mob at %d, %d, %d is %s"):format(mob.x, mob.y, mob.z, mob.name))
- pitch = -math.atan2(mob.y, math.sqrt(mob.x * mob.x + mob.z * mob.z))
- yaw = math.atan2(-mob.x, mob.z)
- ni.look(math.deg(yaw),math.deg(pitch))
- moveTo(mob.x,mob.y,mob.z,0.5)
- print(msg)
- end
- end
- sleep(0.1)
- end
- end
- function followSwing(mobfilter)
- while true do
- mobs=ni.sense()
- mobs=filterArray(mobs,mobFilter)
- table.sort(mobs,function(a,b) return getDistance(a)<getDistance(b) end)
- if #mobs>1 then
- mob=mobs[2]
- if getDistance(mob)<2 and getDistance(mob)>1 then
- msg=(("The mob at %d, %d, %d is %s"):format(mob.x, mob.y, mob.z, mob.name))
- pitch = -math.atan2(mob.y, math.sqrt(mob.x * mob.x + mob.z * mob.z))
- yaw = math.atan2(-mob.x, mob.z)
- ni.look(math.deg(yaw),math.deg(pitch))
- moveTo(mob.x,mob.y,mob.z,0.5)
- print(msg)
- else
- for is=1,10 do
- ni.swing()
- end
- end
- end
- sleep(0.1)
- end
- end
- function filterArray(iArray,iFilter)
- oArray={}
- for iA=1, #iArray do
- if string.find(iFilter,iArray[iA].name)==nil then
- table.insert(oArray,iArray[iA])
- end
- end
- return oArray
- end
- mobFilter="ecco7777ItemAlphaCyclesplethora:laserxp_orb_bigxp_orb_smallspiritArrow"
- function autoKill(filter)
- while true do
- mobs=ni.sense()
- ni.canvas3d().clear()
- c3d=ni.canvas3d().create()
- --c3d.recenter()
- mobs=filterArray(mobs,mobFilter)
- table.sort(mobs,function(a,b) return getDistance(a)<getDistance(b) end)
- if #mobs>0 then
- mob=mobs[1]
- msg=(("The mob at %d, %d, %d is %s"):format(mob.x, mob.y, mob.z, mob.name))
- ni.tell(msg)
- pitch = -math.atan2(mob.y, math.sqrt(mob.x * mob.x + mob.z * mob.z))
- yaw = math.atan2(-mob.x, mob.z)
- ni.fire(math.deg(yaw),math.deg(pitch),5)
- c3d.addLine({x=0,y=0,z=0},{mob.x, mob.y, mob.z})
- --moveTo(mob.x,mob.y,mob.z)
- print(msg)
- end
- sleep(0.1)
- end
- end
- function autoSwing(filter)
- while true do
- mobs=ni.sense()
- ni.canvas3d().clear()
- c3d=ni.canvas3d().create()
- --c3d.recenter()
- mobs=filterArray(mobs,mobFilter)
- table.sort(mobs,function(a,b) return getDistance(a)<getDistance(b) end)
- if #mobs>1 then
- mob=mobs[1]
- if getDistance(mob)<4 then
- msg=(("The mob at %d, %d, %d is %s"):format(mob.x, mob.y, mob.z, mob.name))
- ni.tell(msg)
- pitch = -math.atan2(mob.y, math.sqrt(mob.x * mob.x + mob.z * mob.z))
- yaw = math.atan2(-mob.x, mob.z)
- ni.look(math.deg(yaw),math.deg(pitch))
- ni.swing()
- c3d.addLine({x=0,y=0,z=0},{mob.x, mob.y, mob.z})
- --moveTo(mob.x,mob.y,mob.z)
- print(msg)
- end
- end
- sleep(0.1)
- end
- end
- function fire()
- while true do
- meta=ni.getMetaOwner()
- ni.fire(meta.yaw,meta.pitch,4)
- end
- end
- function split (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function loadFile(filename)
- fp=fs.open(filename,"r")
- lines={}
- i=1
- lines[i]=fp.readLine()
- while lines[i]~=nil do
- i=i+1
- lines[i]=fp.readLine()
- end
- return lines
- end
- function compileObj(lines)
- v = {}
- vt = {}
- vn = {}
- f = {}
- l = {}
- print(#lines)
- for i=5, #lines do
- if string.sub(lines[i],1,2)=="v " then
- table.insert(v,split(lines[i]))
- end
- if string.sub(lines[i],1,2)=="vt" then
- table.insert(vt,split(lines[i]))
- end
- if string.sub(lines[i],1,2)=="vn" then
- table.insert(vn,split(lines[i]))
- end
- if string.sub(lines[i],1,2)=="f " then
- table.insert(f,split(lines[i]))
- end
- if string.sub(lines[i],1,2)=="l " then
- table.insert(l,split(lines[i]))
- end
- end
- end
- function showModel()
- compileObj(loadFile("model"))
- br=10
- line=1
- ni.canvas3d().clear()
- c3d=ni.canvas3d().create()
- for mi=1, 5000 do
- i=math.random(1,#v)
- i2=math.random(1,#v)
- c3d.addLine({x=v[i][2]*br,y=v[i][3]*br,z=v[i][4]*br},{x=v[i][2]*br,y=v[i][3]*br+0.1,z=v[i][4]*br})
- end
- end
- function displayImage()
- l=2
- br=1
- xOff=0
- yOff=0
- --shell.run(file)
- os.loadAPI("bild")
- color=bild.color
- ni.canvas().clear()
- cvs=ni.canvas()
- --fp=fs.open(file,"r")
- xMax=#color
- yMax=#color[1]
- for y=1,xMax do
- for x=1,yMax do
- pixel=cvs.addRectangle(y*l+xOff,xMax*l-x*l+yOff,l,l)
- pixel.setColor(color[x][y])
- pixel.setAlpha(br*0xff)
- end
- end
- end
- function debug()
- autoSwing(mobFilter)
- end
- function keyevent()
- while true do
- e,val=os.pullEvent()
- if e=="key" then
- if val==57 then
- debug()
- end
- end
- end
- end
- function main()
- if mode=="" then
- end
- if mode=="followSwing" then
- mobFilter="ItemAlphaCyclesplethora:laserxp_orb_bigxp_orb_smallspiritArrowThrownPotionbotania:magicMissilebotania:magicLandmine"
- followSwing(mobFilter)
- end
- if mode=="model" then
- showModel()
- end
- if mode=="laserkill" then
- autokill()
- end
- if mode=="shoot" then
- fire()
- end
- if mode=="autoSwing" then
- mobFilter="ecco7777ItemAlphaCyclesplethora:laserxp_orb_bigxp_orb_smallspiritArrowThrownPotionbotania:magicMissilebotania:magicLandmine"
- autoSwing(mobFilter)
- end
- if mode=="follow" then
- filter="ItemAlphaCyclesplethora:laserxp_orb_bigxp_orb_smallspiritArrowThrownPotionbotania:magicMissilebotania:magicLandmine"
- follow(filter)
- end
- end
- main()
Add Comment
Please, Sign In to add comment