Description
This is the component provided by the Energy Turret block.
Component name: os_energyturret
.
This is the component provided by the Energy Turret block.
Component name: os_energyturret
.
powerOn()
Turns on the turret.
powerOff()
Turns off the turret.
isReady()
Returns true if the turret has cooled down from it's previous fire, is armed, and the barrel is valid, otherwise false.
isPowered()
Returns true if the turret is powered on, otherwise false.
setArmed(armed:boolean)
Arms and disarms the turret, must be armed to fire.
extendShaft(len:number)
Valid range (0-2) extends/retracts the rotator shaft, must be at least 1 to fire.
getShaftLength()
Returns the shaft length.
moveToRadians(YaxeRad, XaxeRad)
Moves the turret in radians instead of degrees.
moveTo(YaxeDeg, XaxeDeg)
Moves the turret's aim to the provided coords and tries to use shortest rotation to move to them as quick as possible.
isOnTarget()
Returns true if the turret has finished moving to it's target, false if not
fire()
Returns true if fired, or false, error if it was unable to fire, not enough energy, or gun hasn't cooled down.
-- 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()