Time for something... flashy!

Code:
ffc script Lightning {
	void run(int delay, int distance, int col, int lay, int sfx) {
		while(true) {
			int w;
			
			w = delay / 2 + Rand(distance * 1.5);
			Waitframes(w);
			int d = distance;
			for(int i = 0; i < 5; i++) {
				if(d == 0 && sfx != 0)
					Game->PlaySound(sfx);
				flash(col, lay, false);
				d--;
				Waitframe();
			}
			for(int i = 0; i < 5; i++) {
				if(d == 0 && sfx != 0)
					Game->PlaySound(sfx);
				flash(col, lay, true);
				d--;
				Waitframe();
			}
			if(d > 0) {
				Waitframes(d);
				Game->PlaySound(sfx);
			}
			
			
			Waitframe();
		}
	}
	
	void flash(int col, int lay, bool trans) {
		int t;
		if(trans) t = 64; else t = 128;
		Screen->Rectangle(lay, 0, 0, 256, 172, col, 1, 0, 0, 0, true, t);
	}
}
- D0: delay between lightning flashes (varies between roughly 1/2 and 1.5 times this value) (use large values, like 500+)
- D1: "distance" of lightning strike. How long after the initial flash should the sound effect play? (20 is a good value)
- D2: colour of the flash. This is an index into the master palette. (for most palettes, you can use 1)
- D3: layer to draw on. Yeah. If the screen is outside, use layer 6. If it's inside, and you're simulating lightning "outside" (eg through a window), use layer 0 (and draw everything on layer 1)
- D4: thunder sound effect. Will play after every flash after D1 frames.

Note: When it flashes, it will cover the screen with the colour for 5 frames, and then cover the screen transparently for 5 frames. You can adjust these timings by changing the two for-loops.

Coming soon, a rain script to compliment this one!