by Rotem12
generates lines, beams or lightning bolts [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Rotem12.Lightning##version=9

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:


Version 1.07
Date added: Jun 21 2015
Last updated: Aug 19 2016
9 fans
Lightning can create a line, beam, lightning bolt or branched lightning bolt between two vectors.

Lightning GitHub

This was made following this article. The article can be used for further explanation of how it works.

Usage is as simple as:
var/vector/start = new (x1 * 32, y1 * 32) // position in pixels
var/vector/dest = new (x2 * 32, y2 * 32) // position in pixels

var/line/l = new(start, dest)

var/bolt/b = new(start, dest)


  • Renamed atan2 and rand to avoid conflicts.

  • Drastically reduces appearance churn.

  • Tiny optimization.
  • Added force lightning demo. Click stickman faces to zap them.

  • Added ability to draw lines as overlays.
  • Bolts can now be drawn as overlays, this greatly improves CPU usage as well as adds the ability to rotate bolts by changing transform angle on a single object.
  • Added a proc to rotate last made bolt.

  • Added bar datum to bars, you can adjust the size of the bar via Adjust()
  • Library now supports drawing on client.screen
  • Line vectors can now be rotated

  • Added beam datum to handle creation of beams.
  • Added parameter to control the thickness of segments
  • Segment type parameter is now defaulted to /obj/segment

  • Added targets parameter to branched bolt allowing to set amount of branches amount or targets fire branched bolts at.
  • The demo will now clear lines when mode is changed
  • Fixes the library to allow different icon_size

For a full list of changes click here.


Rotem12: (Jun 25 2015, 4:17 am)
I released a beam datum for all those who are interested in beams, there's also a parameter to control thickness, it comes handy with lines beams or if you're using a different icon size.

Because of the new thickness parameter I moved /obj/segment from the demo to the library, the parameter now defaults to /obj/segment, you can still use a different type to generate different results.

I've yet to mess with beam "head", I didn't see much need for it with lightning but it may be nice to do so now.
Avidanimefan: (Jun 25 2015, 12:28 am)
Why not just generate all the rotations up front in a associated list and build the bolts based on the list?

This might have to be done on a player by player basis but it might be a decent alternative to generating them all on the fly.

I'm going to go play with this, I was actually thinking of putting something like a skill that allows the player to shoot lightning rods. Then another skill that releases electricity , which is drawn to anything struck with a lightning rod. Thanks for posting
Rotem12: (Jun 24 2015, 4:27 pm)
Bravo1 wrote:
The problem seems to be exacerbated the closer the destination is to the source.

I updated to attempt fix it, the update effects both normal and branched bolts, the segments are positioned slightly different now, I hope it looks better.

Aside from that, it also aims to branch out other bolts earlier than it did before, what I think happened was it attempted to branch when it's over 90% close to the end leaving it no room.

There's not much point if bolts branch out too late anyway so that should be better now.

EDIT: I also toyed with pooling, just pooling segments is not having any impact, I already know how to rotate an entire bolt, I'll work on it more later in hopes pooling entire bolts can help.
Bravo1: (Jun 24 2015, 1:56 pm)
I have it running at 60fps. Not sure if that's the cause of the issue or not.

The problem seems to be exacerbated the closer the destination is to the source.
Kaiochao: (Jun 24 2015, 1:40 pm)
I remember making a Force Lightning skill for an unreleased Star Wars fan-game years ago. It used Kunark's Line Drawer library and it looked pretty cool for being tile-based. Every couple tiles it would fork, and each segment would be attracted to certain objects like explosive barrels, droids, or other people.

This is much fancier-looking.