Skip to content

Laser setup (advanced)

kcinnaJlol edited this page Oct 18, 2018 · 20 revisions

Introduction

This is the programming tutorial on how to setup basic and amplified lasers. This is a follow up, on the basic tutorial here. While only ComputerCraft is covered here, keep in mind that OpenComputers uses the same WarpDrive API. The only difference is about networking, which isn't the object of this tutorial, so we won't describe it here.

Low tier laser cannon

Pre-requisites

You need at least:

  • one Laser Camera with a few Laser mediums,
  • one monitor,
  • a power source (RF or EU based),
  • one computer (ComputerCraft or OpenComputers) per Laser or Laser Camera,
  • a temporary computer to setup the Monitor (see Basic tutorial). Ideally, you would use 1 Laser Camera with a few Laser mediums and a bunch of lasers setup with lots of Laser mediums.

Reminders

Laser Camera is the head/output of the laser cannon. It's used to designate the target.

Any Laser or Laser Camera should have clear view to its target and at least 1 laser medium. All laser mediums shall be placed on a single line with their related Laser or Laser Camera. More laser medium provide more power and more range.

Laser frequency 1420 is reserved for scanning. Any other frequency is for attacking or boosting.

Building

For the non-geeky, non-amplified version, check the basic setup in the related page. Here's the geeky setup used by Cr0s:

1- Targeting laser

Place a computer with modem next to your Laser Camera. Type this program:

modem = peripheral.wrap("right")
laser = peripheral.wrap("left")
laser.beamFrequency(1420)
laser.videoChannel(100)

-- Shoots fired count
firedCount = 0

while true do
  -- pull a laser head for new target
  type, x_, y_, z_, id, meta, res = laser.getScanResult()
  if res ~= -1 then
    firedCount = firedCount + 1
    
    -- send serialized target info
    target = textutils.serialize( { x = x_, y = y_, z = z_ } )
    print("Target#" .. firedCount .. " is " .. target)
    
    -- init main laser with target
    modem.transmit(3, 1, target)
    
    -- init boost (remove comment on next line if you use boosters)
    -- modem.transmit(4, 1, "go")
  end
  sleep(0.05)
end

2- Monitor

Place a monitor and set its frequency to match the Laser Camera videoChannel (100 in our case). To set its frequency, place a computer on its left and type:

lua
peripheral.wrap("right").freq(100)

(you can then break the computer afterward)

3- Main laser

Place a laser 'head' with a few laser medium blocks and a computer (below) with a modem on its left. Type this program:

laser = peripheral.wrap("top")

laser.freq(1010)

modem = peripheral.wrap("left")

-- listening for targets
modem.open(3)

while true do
  -- receive target info
  local event, _, ch, _, msg, _ = os.pullEvent("modem_message")

  -- is targeting channel ?
  if ch == 3 then
    print("Got target: " .. msg)

    -- get coordinates
    target = textutils.unserialize(msg)

    -- calculate targeting vector
    myX, myY, myZ = laser.pos()

    dx = target.x - myX
    dy = target.y - myY
    dz = target.z - myZ

    -- shoot (due to bug in older versions, you were required to use -dz here)
    laser.emitBeam(dx, dy, dz)
  end

  sleep(0)
end

4- Boosting lasers

Repeat step 3 with laser boosters and a modem on channel 4 (optional) Each laser booster should be targeting the laser head to boost its charge (increasing it's destructive power). Each laser booster should have the same frequency as the laser head (otherwise it'll break it). As said earlier, each laser booster should have a clear view to the laser head. Here's an example program, remember to adjust the coordinates in emitBeam calls:

modem = peripheral.wrap("bottom")
laser1 = peripheral.wrap("top")
laser2 = peripheral.wrap("left")
laser3 = peripheral.wrap("right")
laser1.freq(1010)
laser2.freq(1010)
laser3.freq(1010)

modem.open(4)

while true do
  local event, _, ch, _, _, _ = os.pullEvent("modem_message")
  -- is boosting channel ?
  if ch == 4 then
    laser1.emitBeam( 0, 1, 4)
    laser2.emitBeam( 1, 0, 4)
    laser3.emitBeam(-1, 0, 4)
  end
  sleep(0)
end

5- Powering

Power all the particle boosters with your favorite energy (all blocks accept both RF & EU) Here's an example with IndustrialCraft2 Fiber cables: High tier laser cannon

6- Fire!

Right click the monitor:

  • move your mouse around to select a target
  • use left click to cycle zoom level
  • press space to shoot!
  • use right click to exit the monitor

A first blue laser from the targeting laser will acquire the target, then the boosting lasers will charge the head laser then the main laser will shoot.

Tips!

This is a very lag-inducing example, it'll kill your server resources pretty fast (loop on sleep(0) and 3 computers per weapon).

It's strongly advised to use wired modems instead of wireless ones to have a single loop on a single computer. A wired version is notably more stable and you can't be 'hacked' by your enemy.

By adding a Weapon controller to your wired network of Lasers and Laser camera, you'll preload the GUI to control your lasers. You can define batteries of laser working together, and laser station to link a Laser Camera with one more batteries.

For more information on Advanced Laser uses, check the following video

WarpDrive Lasers

More info

for the laser battery/laser station you need:

  • weapon controller
  • advanced computer from CC (just computer from OC)
  • rf or eu power source
  • laser
  • laser+camera
  • monitor (- tuning fork if you run into camera not detected by weapon controller bug)
  • modem (don't need modem for OC)
  • networking cable (just a cable for OC)
  • laser mediums

Config

  1. place down the lasers and mediums with modems on them and cables towards the computer and weapon controller
  2. open the computer
  3. press 1 for laser batteries (if im correct)
  4. make a new battery and configure all lasers and set their frequency's
  5. configure the boosting lasers and the laser getting boosted
  6. make a laser station and set the battery
  7. if the camera doesn't get detected set "video channel" to 100 and right click the laser+camera with the tuning fork that sets beam frequency to 100
  8. enter the camera and enjoy!
Clone this wiki locally