Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --robot
- component = require('component')
- event = require('event')
- robot = require('robot')
- computer = require('computer')
- shell = require("shell")
- filesystem = require("filesystem")
- modem = component.modem
- particle = component.particle
- nav = component.navigation
- particle_map = {}
- sides = {[2]={0,-1},[3]={0,1},[4]={-1,0},[5]={1,0}}
- arg = {...}
- pos = {x=arg[1] or 0,y=arg[2] or 0,z=arg[2] or 0}
- send = component.tunnel.send
- filesystem.setAutorunEnabled(true)
- modem.setWakeMessage("ROBOTSTART")
- function getN()
- return #particle_map
- end
- function up(self)
- for i=1,3 do
- local out=robot.up()
- if out then pos.y=pos.y+1 return true end
- os.sleep(0.5)
- end
- return false
- end
- function down(self)
- for i=1,3 do
- local out=robot.down()
- if out then pos.y=pos.y-1 return true end
- os.sleep(0.5)
- end
- return false
- end
- function left(self)
- return robot.turnLeft()
- end
- function right(self)
- return robot.turnRight()
- end
- function go(self)
- for i=1,3 do
- local out=robot.forward()
- if out then
- pos.x=pos.x+sides[nav.getFacing()][1]
- pos.z=pos.z+sides[nav.getFacing()][2]
- return true
- end
- os.sleep(0.5)
- end
- return false
- end
- function back(self)
- for i=1,3 do
- local out=robot.back()
- if out then
- pos.x=pos.x-sides[nav.getFacing()][1]
- pos.z=pos.z-sides[nav.getFacing()][2]
- return true
- end
- os.sleep(0.5)
- end
- return false
- end
- function add(x,y,z,name,random_speed,random_pos_radius)
- table.insert(particle_map,{name=name,x=x,y=y,z=z,rand=random_speed,rand_rad=random_pos_radius*2})
- return #particle_map
- end
- function del(self)
- particle_map[#particle_map]=nil
- return #particle_map
- end
- function editpos(x,y,z)
- pos.x=x
- pos.y=y
- pos.z=z
- return true
- end
- function chat(_,_,_,_,_,msg)
- print("s:"..msg)
- local text=tostring(load("return "..msg)())
- print("c:"..text)
- send(text)
- end
- event.listen("modem_message",chat)
- function particle_update()
- for i=1,#particle_map do
- local self = particle_map[i]
- local vx,vy,vz = 0,0,0
- local name = self.name
- local x = self.x-pos.x+self.rand_rad*(math.random()-0.5)
- local y = self.y-pos.y+math.max(math.min(self.rand_rad,256),0)*math.random()
- local z = self.z-pos.z+self.rand_rad*(math.random()-0.5)
- if self.rand then vx,vy,vz=math.random()-0.5,math.random()-0.5,math.random()-0.5 end
- particle.spawn(name,x,y,z,vx,vy,vz)
- end
- end
- while true do
- os.sleep(0) -- too long without yielding не дремлет!
- pcall(particle_update)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement