Posted 16 March 2014 - 12:37 AM
So for those who were with me before, I had trouble with the Open CC Sensors peripheral. Now Im taking this script from the CC wiki and working towards something a bit bigger. Only problem is, I don't really know how to go about it.
My goal here is to take the code used for getting the position of the player and making the turtle on a loop constantly run a "goto" program, so that it can chase down the player… or something like that.
Could anyone maybe come up with some code I could use? Keep in mind that I've just started this and I'm basically building right off of the program from the wiki page. So on that note there's most likely a lot of useless code in there. Oh and also I've already tried a bit of this on my own so the additions would be the "~= placement" in the if statement.
My idea was to get the placement of the player in that variable and be able to just tell the turtle "goto placement" but now that I think about more I realize that might have to be a table huh.
Here's the code I've been using.
My goal here is to take the code used for getting the position of the player and making the turtle on a loop constantly run a "goto" program, so that it can chase down the player… or something like that.
Could anyone maybe come up with some code I could use? Keep in mind that I've just started this and I'm basically building right off of the program from the wiki page. So on that note there's most likely a lot of useless code in there. Oh and also I've already tried a bit of this on my own so the additions would be the "~= placement" in the if statement.
My idea was to get the placement of the player in that variable and be able to just tell the turtle "goto placement" but now that I think about more I realize that might have to be a table huh.
Here's the code I've been using.
os.loadAPI("ocs/apis/sensor")
-- the location of the redstone lamp relative to the sensor
local offset = {
X = 1,
Y = 1,
Z = 0
}
-- how close a player has to be to activate the lamp
local radius = 5
-- find the distance from the player position to the offset
function distance(pos)
local xd = pos.X - offset.X
local yd = pos.Y - offset.Y
local zd = pos.Z - offset.Z
return math.sqrt(xd*xd + yd*yd + zd*zd)
end
local proximity = sensor.wrap("left")
while true do
local signal = false
local targets = proximity.getTargets()
for k, v in pairs(targets) do
if distance(v.Position) ~= placement then
signal = true
end
end
rs.setOutput("top", signal)
end