Jump to content




Help with OpenCCSensors


10 replies to this topic

#1 dexter9

  • Members
  • 82 posts

Posted 20 April 2013 - 05: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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 April 2013 - 07: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).

#3 dexter9

  • Members
  • 82 posts

Posted 20 April 2013 - 07:41 AM

sorry how would that be as lua code? or how would i type it in. sorry im new to openccsensors..

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 April 2013 - 07: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. :)

#5 dexter9

  • Members
  • 82 posts

Posted 20 April 2013 - 08: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!!!

#6 dexter9

  • Members
  • 82 posts

Posted 20 April 2013 - 10:57 AM

Hi, sorry how would i receive it as in rednet.receive()?

#7 Molinko

  • Members
  • 54 posts

Posted 24 April 2013 - 08:55 AM

View Postdexter9, on 20 April 2013 - 10:57 AM, said:

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.

#8 azumi

  • Members
  • 3 posts

Posted 07 June 2013 - 10: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 :)

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 07 June 2013 - 10:48 AM

View Postazumi, on 07 June 2013 - 10:32 AM, said:

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...

#10 azumi

  • Members
  • 3 posts

Posted 07 June 2013 - 02: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?

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 07 June 2013 - 02:18 PM

View Postazumi, on 07 June 2013 - 02:06 PM, said:

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.computerc...e=OpenCCSensors





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users