82 posts
Posted 20 April 2013 - 06:55 AM
Hi im trying to make a smart turtle killing program. I need to get the sensors to report the players co-ords and i want the computer to print it too.
Thanks in advance
8543 posts
Posted 20 April 2013 - 08:39 AM
Try using sensorview to examine the detailed output for the player target. This will tell you which table(s) you need to index. Then simply iterate through the targets returned by getTargets, determine which are players and which are not, and use getTargetDetails on the appropriate targets to fetch their details table (which you then index to get the position values).
82 posts
Posted 20 April 2013 - 08:41 AM
sorry how would that be as lua code? or how would i type it in. sorry im new to openccsensors..
8543 posts
Posted 20 April 2013 - 08:52 AM
I don't exactly remember where in the tables all of this info actually is, so this code almost certainly won't work out of the box, but it should get you pointed in the right direction:
os.loadAPI("ocs/apis/sensor")
local proxSense = sensor.wrap("left")
for target in pairs(proxSense.getTargets()) do
local detailedInfo = proxSense.getTargetDetails(target)
if detailedInfo.whateverTellsUsItIsAPlayer == "player" then --you will need to look around and find whatever distinguishes players and non-players in the output.
rednet.broadcast("Player! "..detailedInfo.name.." @ "..detailedInfo.Position.X..", "..detailedInfo.Position.Y..", "..detailedInfo.Position.Z)
end
end
I don't know what the rest of your code looks like, so that's about all I have for you at this point. The rest should be fairly simple. :)/>
82 posts
Posted 20 April 2013 - 09:03 AM
omg! That is actually a lot easier than i expected. thank you thank you thank you. Its going to be like a turtle infected type thing with the objective of blowing up the turtle factory inside a castle. Hope it turns out fun!
Thanks a lot!!!
82 posts
Posted 20 April 2013 - 11:57 AM
Hi, sorry how would i receive it as in rednet.receive()?
54 posts
Posted 24 April 2013 - 09:55 AM
Hi, sorry how would i receive it as in rednet.receive()?
to send tables over rednet you have to use the textutils API and the function serialize() to convert them into a string. you recieve that string and unserialize() it on the other side where the msg has been recieved.. ie
events = os.pullEvent("modem") -- capture a modem event.
tableOfOursWeWant = textutils.unserialize(events[4])
e[4] should be the message in string form. i think that will depend upon your version of cc though because the functions for rednet functioning has been updated somewhat recently.
3 posts
Posted 07 June 2013 - 11:32 AM
Hello.
I want to write my own program to activate redstone signal during night and turn it off during day with help of "World" Open sensor, but the only documentation i could find is about proximity sensor :(/>
Can anyone point me in the right direction where to look for the rest of api commands to other sensors?
Any help would be much appreciated :)/>
7508 posts
Location
Australia
Posted 07 June 2013 - 11:48 AM
I want to write my own program to activate redstone signal during night and turn it off during day with help of "World" Open sensor, but the only documentation i could find is about proximity sensor :(/>
Would probably be just as easy using the time of the Minecraft world instead of having to rely on using OCS. How to get the Minecraft time,
os.time…
3 posts
Posted 07 June 2013 - 03:06 PM
oh, thanks i will use it.
But for future reference if i would like to use any OCS data from any sensor other than proximity how to do it?
7508 posts
Location
Australia
Posted 07 June 2013 - 03:18 PM
But for future reference if i would like to use any OCS data from any sensor other than proximity how to do it?
Ummm, I haven't actually brushed up on OCS as much as I really need too, there have been heaps of questions coming in lately, but iirc there are sensor cards you put into the sensor to have it detect other things, you would have the proximity sensor card in the sensor or be using the proximity sensor block (in which case you just need to use the sensor).
http://www.computercraft.info/wiki/index.php?title=OpenCCSensors