Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- drn = component.proxy(component.list("drone")())
- inv = component.proxy(component.list("inventory_controller")())
- mod = component.proxy(component.list("modem")())
- address = nil
- port = 3341
- facing = {
- [1] = { -- N
- forward = {x=0,y=0,z=-1},
- backward = {x=0,y=0,z=1}
- },
- [2] = { -- E
- forward = {x=1,y=0,z=0},
- backward = {x=-1,y=0,z=0}
- },
- [3] = { -- S
- forward = {x=0,y=0,z=1},
- backward = {x=0,y=0,z=-1}
- },
- [4] = { -- W
- forward = {x=-1,y=0,z=0},
- backward = {x=1,y=0,z=0}
- }}
- direct = 1
- light = {[1] = 0x0000FF,[2] = 0xFFFF00,[3] = 0xFF0000,[4] = 0x00FF00}
- sides = {["Q"] = 0,["E"] = 1,["W"] = 2,["S"] = 3,["A"] = 4,["D"] = 5}
- pX = {}
- pY = {}
- pZ = {}
- pI = 0
- pC = 0
- pXk = false
- pYk = false
- pZk = false
- function sleep(tm)
- local go = computer.uptime() + tm
- while (go > computer.uptime()) do
- computer.pullSignal(go - computer.uptime())
- end
- end
- function pZero(i)
- pX[i] = 0
- pY[i] = 0
- pZ[i] = 0
- end
- function addPath(px,py,pz)
- if (px~=0) then
- if (pXk==false) then
- pI = pI + 1
- pZero(pI)
- pXk = true
- pYk = false
- pZk = false
- end
- elseif (py~=0) then
- if (pYk==false) then
- pI = pI + 1
- pZero(pI)
- pXk = false
- pYk = true
- pZk = false
- end
- elseif (pz~=0) then
- if (pZk==false) then
- pI = pI + 1
- pZero(pI)
- pXk = false
- pYk = false
- pZk = true
- end
- end
- pX[pI] = pX[pI] + px
- pY[pI] = pY[pI] + py
- pZ[pI] = pZ[pI] + pz
- end
- function goBack()
- local i = pI
- if (pC~=1) then
- while (i~=0) do
- sleep(2)
- drn.move(-1 * pX[i], -1 * pY[i], -1 * pZ[i])
- i = i - 1
- end
- end
- pC = 1
- end
- function goTo()
- local i = 1
- if (pC~=pI) then
- while (i<=pI) do
- sleep(2)
- drn.move(pX[i],pY[i],pZ[i])
- i = i + 1
- end
- end
- pC = pI
- end
- side = 0
- sideMod = false
- suckSlot = 1
- function suck()
- local i = 4
- while (i>0) do
- --inv.suckFromSlot(side,suckSlot)
- drn.suck(0)
- sleep(0.4)
- suckSlot = suckSlot + 1
- i = i - 1
- end
- end
- mod.open(port)
- drn.setLightColor(light[direct])
- drn.select(1)
- while true do
- local signal,_,remote,iport,_,cmd = computer.pullSignal()
- if (signal=="modem_message") then
- if (port==iport) then
- if (address==nil) then address = remote end
- if(address==remote) then
- if (sideMod==false) then
- if (cmd=="W") then
- local mfx = facing[direct].forward.x
- local mfy = facing[direct].forward.y
- local mfz = facing[direct].forward.z
- addPath(mfx,mfy,mfz)
- drn.move(mfx,mfy,mfz)
- elseif (cmd=="S") then
- local mbx = facing[direct].backward.x
- local mby = facing[direct].backward.y
- local mbz = facing[direct].backward.z
- addPath(mbx,mby,mbz)
- drn.move(mbx,mby,mbz)
- elseif (cmd=="A") then
- direct = direct - 1
- if (direct<=0) then direct = 4 end
- drn.setLightColor(light[direct])
- elseif (cmd=="D") then
- direct = direct + 1
- if (direct>=5) then direct = 1 end
- drn.setLightColor(light[direct])
- elseif (cmd=="Q") then
- drn.move(0,-1,0)
- addPath(0,-1,0)
- elseif (cmd=="E") then
- drn.move(0,1,0)
- addPath(0,1,0)
- end
- else
- side = sides[cmd]
- end
- if (cmd=="1") then
- if (sideMod==true) then sideMod = false
- else sideMod = true end
- elseif (cmd=="2") then
- suck()
- elseif (cmd=="3") then
- end
- if (cmd=="Z") then
- goBack()
- elseif (cmd=="X") then
- goTo()
- elseif (cmd=="C") then
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement