better armor stand intelligence

This commit is contained in:
kepler155c@gmail.com
2019-04-01 08:51:53 -04:00
parent e51a4108ad
commit 71b343cf86
2 changed files with 54 additions and 21 deletions

11
monitor/help/mirror Normal file
View File

@@ -0,0 +1,11 @@
Mirror the terminal or a program on a monitor. Monitor touch events are translated to mouse click events.
Optional arguments:
-s : set monitor to .5 scaling
-r : resize the terminal to the size of the monitor
-e : run a program on the monitor
If the -e argument is not used, the current terminal will be mirrored.
Example:
mirror -s -r -e edit /startup

View File

@@ -10,39 +10,61 @@ local sensor = device['plethora:sensor'] or error('Missing sensor')
local intro = device['plethora:introspection'] or error('Missing introspection module')
local ownerId = intro.getMetaOwner().id
local targets = { }
local function findTargets()
local l = Array.filter(sensor.sense(), function(a)
return math.abs(a.motionY) > 0 and ownerId ~= a.id
end)
table.sort(l, function(e1, e2)
return Point.distance(e1, pos) < Point.distance(e2, pos)
end)
local now = os.clock()
local moved = { }
local l = Array.filter(sensor.sense(), function(a)
if math.abs(a.motionY) > 0 and ownerId ~= a.id then
local loc = table.concat({ a.x, a.y, a.z }, ':')
if not targets[a.id] then
targets[a.id] = { c = now }
elseif targets[a.id].loc ~= loc then
targets[a.id].c = now
table.insert(moved, a)
end
targets[a.id].loc = loc
a.c = targets[a.id].c
return now - a.c < 5
end
end)
if #moved > 0 then
table.sort(moved, function(e1, e2)
return Point.distance(e1, pos) < Point.distance(e2, pos)
end)
return moved[1]
end
if #l > 1 then
table.sort(l, function(e1, e2)
return now - e1.c < now - e2.c
end)
return targets[1]
end
return l[1]
end
local last
local count = 0
local count = 50
while true do
local target = findTargets()
if target and (not last or Point.distance(last, target) > .2) then
last = target
kinetic.lookAt(target)
if target then
count = 0
kinetic.lookAt(target)
os.sleep(0)
elseif count > 25 then
kinetic.lookAt({
x = math.random(-10, 10),
y = math.random(-10, 10),
z = math.random(-10, 10)
})
os.sleep(3)
else
count = count + 1
if count > 50 or not target then
kinetic.lookAt({
x = math.random(-10, 10),
y = math.random(-10, 10),
z = math.random(-10, 10)
})
os.sleep(3)
else
os.sleep(.1)
end
os.sleep(.1)
end
end