Component : Energy Turret

logo

Description

This is the component provided by the Energy Turret block.

Component name: os_energyturret.

Methods

Example

            
-- https://github.com/PC-Logix/OpenSecurity/wiki/EnergyTurret
--[[
  Minimal example of turret usage

  This script will command turret to shoot exactly once
  pointing towards south with cannon being positioned
  parallel to ground
]]

local component = require "component"
local turret = component.os_energyturret

-- rotation specified in degrees
local horizontalRotation = 180
local verticalRotation = 0

-- prepare turret to fire
turret.powerOn()
turret.setArmed(true)

-- rotate it horizontally and vertically
turret.moveTo(horizontalRotation, verticalRotation)

-- wait while turret is still rotating 
while turret.isOnTarget() == false do
  os.sleep(0.1)
end

-- turret is now on target, try to fire
local fired, error = turret.fire()

-- if was unable to fire, print why
if fired == false then
  print("Unable to fire: " .. error)
end

turret.powerOff()