Difference between revisions of "OpenCCSensors"

From ComputerCraft Wiki
Jump to: navigation, search
(Usage Examples)
(Usage Examples)
Line 150: Line 150:
 
  print(textutils.serialize(prox.getTargets()))
 
  print(textutils.serialize(prox.getTargets()))
 
|output=A huge blob of text with all nearby available targets to the sensor, and some basic details.
 
|output=A huge blob of text with all nearby available targets to the sensor, and some basic details.
}}
 
{{Example 2
 
|desc=Turn on a Redstone lamp when a player is within a certain distance from it. The sensor is placed to the left of the computer and the lamp is placed on top of the computer.
 
|code=
 
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) < radius then
 
          signal = true 
 
        end
 
  end
 
  rs.setOutput("top", signal)
 
end
 
 
}}
 
}}

Revision as of 02:39, 31 December 2012

This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: I no dun with this, but 'tis a start! AfterLifeLochie 03:34, 25 December 2012 (MSK))

OpenCCSensors is a new, open-source, up to date replacement for CcSensors (outdated), allowing monitoring and gathering information from the Minecraft environment - including players, entities, proximity, world info, IndustrialCraft 2, BuildCraft 2, liquids, inventories - and more!

Grid disk.png   OpenCCSensors Lua API

Method NameDescription
sensor.wrap(side) Returns the wrapped sensor on the side specified.
mySensor.getTargets() Returns a a table of all the targets for mySensor, where the keys are used as a numerical index, and the values are each a table of basic details.
mySensor.getTargetDetails(key) Returns a table of full details for that particular target from the sensor mySensor - where the the "key" is the key returned from getTargets()


Grid disk.png   OpenCCSensors Peripherals

NameDescription
Sensor Peripheral

The Sensor Peripheral needs to be placed next to a computer and it has a single slot to insert a Sensor Card


Obsidian

Redstone

Stone

Obsidian

Obsidian

Stone

Obsidian

Redstone

Stone

Sensor Peripheral




Grid disk.png   OpenCCSensors Sensor Cards

NameDescription
Inventory Sensorcard The Inventory Sensorcard is capable of reading inventories of players and entities (as well as armour slots).


Redstone

Redstone

paper

wooden_plank

Redstone

paper

Redstone

Redstone

paper

Inventory Sensorcard



Proximity Sensorcard The Proximity Sensorcard is capable of detecting players and entities within it's range.


Redstone

Redstone

paper

pressure_plate

Redstone

paper

Redstone

Redstone

paper

Proximity Sensorcard



IndustrialCraft 2 Sensorcard The IndustrialCraft 2 Sensorcard is capable of interfacing and reading IC2 machine values (eg, EU in storage, etc).


Redstone

Redstone

paper

copper_cable

Redstone

paper

Redstone

Redstone

paper

Inventory Sensorcard



BuildCraft Sensorcard


Redstone

Redstone

paper

lever

Redstone

paper

Redstone

Redstone

paper

Buildcraft Sensorcard



Liquid Sensorcard


Redstone

Redstone

paper

Bucket

Redstone

paper

Redstone

Redstone

paper

Liquid Sensorcard



World Sensorcard The World Sensorcard is able to tell the time, weather, and more about the world.


Redstone

Redstone

paper

ender_pearl

Redstone

paper

Redstone

Redstone

paper

World Sensorcard



Dropped Item Sensorcard The Dropped Item Sensorcard is able to locate and identify dropped items.


Redstone

Redstone

paper

slime_ball

Redstone

paper

Redstone

Redstone

paper

Dropped Item Sensorcard



Sign Sensorcard The Sign Sensorcard is capable of reading signs within it's range.


Redstone

Redstone

paper

sign

Redstone

paper

Redstone

Redstone

paper

Sign Sensorcard



Usage Examples

Template:Example 1