← Home SEEBIE90 DOCS
Download PDF
No copies or uploads of M.A.W.S. assetsExample code is free to useNo printed reproduction or modification of this documentationSuggestions: Discord to the authorLicense

Sci-Fi Expansion Pack

Orbital laser

A shoulder module that calls a deep-red beam down from orbit: 10 seconds of warning, then 12 seconds of beam that destroys whatever stands inside it – and the effect has to be visible kilometres away, far outside the walker's streaming range.

In plain wordsThe crew sets a target, the salvo key fires. The server sends every phase to all players, and each machine draws the beam itself.
Orbital laser uplink, shoulder module of the M.A.W.S. Sci-Fi Expansion Pack
The uplink module on the shoulder yoke: armoured base, phased-array panel, emitter mast.

Sequence

PhaseDurationWhat happens
TARGET SETuntil firedmap circle menu (point, track, or START + END for a sweep) or the mark key; nothing happens yet
FIRE–salvo key, the same key that fires the rockets
WARN10 sred light pillar and a 40 m ring at the target, rising sound – for every player
DESCENT1.2 sthe beam comes down from 2.5 km; no damage yet
BEAM12 sdamage, heat zone, burning path; follows a vehicle, the steering player or the sweep A → B
COOLDOWN3 minone charge per mounted module, refilled at a depot

Set the target, fire with the salvo key

Players already know how the rockets work: mark targets, then fire. The laser uses the same rhythm. The map menu and the mark key only store a target on the server; the salvo key fires it. The stored target lives in [RplProp] fields on the module manager, so the map and the HUD of the whole crew can show it.

Example code – free to use
// add-on: module manager (modded class), server side
[RplProp()] protected bool m_bPlanned;
[RplProp()] protected vector m_vPlanA;		// target or sweep start
[RplProp()] protected vector m_vPlanB;		// sweep end
[RplProp()] protected bool m_bPlanSweep;

string ServerSetTarget(vector a, bool sweep, vector b)
{
	string error = CheckRange(a, sweep, b);	// 80 m .. 4 km, sweep <= 400 m, not across the own walker
	if (!error.IsEmpty())
		return error;				// sent back to the player as a hint

	m_bPlanned = true;
	m_vPlanA = a;
	m_vPlanB = b;
	m_bPlanSweep = sweep;
	Replication.BumpMe();
	return "";
}

The salvo key belongs to the base mod. The add-on mods its input component: when a laser target is set, it sends its own request first and only falls through to the rockets if rocket targets are marked as well.

Example code – free to use
modded class MyWalker_CrewInput
{
	override protected void OnFireSalvo(float value, EActionTrigger reason)
	{
		MyWalker_Modules mods = MyWalker_Modules.FindOn(GetOwner().GetRootParent());
		if (mods && mods.HasLaserTarget())
		{
			MyPlayerController.Local().RequestFireLaser(GetOwner().GetRootParent());
			if (!HasRocketTargets())
				return;				// no "no target set" hint from the rockets
		}

		super.OnFireSalvo(value, reason);
	}
}

Effects for everyone, not for the walker's neighbours

Replicated state on the walker only reaches clients that stream the walker. The target can be 4 km away, and players standing next to it may not stream the walker at all. So the server sends each phase to every player controller (the same path the base mod uses for explosions), and each machine with a display builds the effect from that message. The dedicated server draws nothing.

Server: phase change→RPC to every player controller→Client: spawn pillar / beam / ring locally→Client: per frame place, sound, fire, decals
Example code – free to use
//! [Server] One message to all players. START / SWEEP / BEAM / END reliable, MOVE unreliable (10 Hz).
static void Broadcast(int msg, int strikeId, vector a, vector b)
{
	array<int> players = {};
	GetGame().GetPlayerManager().GetPlayers(players);
	foreach (int id : players)
	{
		MyPlayerController pc = MyPlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(id));
		if (pc)
			pc.SendLaserFx(msg, strikeId, a, b);	// local host: handled directly, others: Rpc to the owner
	}
}

A sweep from A to B is not sent position by position. Every client knows A, B and the start time and computes the beam position itself – the fire and the scorch marks run exactly with the beam, without network delay.

PitfallWith the beam position sent at 5 Hz and smoothed on the client, the burning path visibly lagged behind the beam. Compute what can be computed (the sweep) locally, and send the rest at 10 Hz.

A 2.5 km beam that does not disappear

PitfallA single beam mesh 2.5 km tall stayed invisible, while the ring on the ground next to it was drawn. The engine culls an object by the distance of its bounds: the centre of such a mesh is over a kilometre away even when its foot stands next to you. The shorter warning pillar (1.5 km) was still visible – a good hint.

The beam is therefore built from 25 pieces of 100 m, each with its own bounds. That alone makes it visible up to the object view distance. To see it even further, the whole column is drawn as a scaled-down copy closer to the camera: every point X becomes C + (X - C) * k. Seen from the camera C the projection is exactly the same, but the copy is close enough to be drawn.

Example code – free to use
//! Place one column of segments; beyond NEAR_LIMIT the column is scaled towards the camera.
void PlaceColumn(array<IEntity> segs, vector foot, float height, float width)
{
	vector cam[4];
	GetGame().GetWorld().GetCurrentCamera(cam);
	vector c = cam[3];

	float far = Math.Max(vector.Distance(c, foot), vector.Distance(c, foot + Vector(0, height, 0)));
	float k = 1.0;
	if (far > NEAR_LIMIT)				// 600 m
		k = NEAR_LIMIT / far;

	width = Math.Max(width, vector.Distance(c, foot) * MIN_ANGLE);	// stays a few pixels wide far away

	for (int i = 0; i < segs.Count(); i++)
	{
		vector real = foot + Vector(0, i * SEG_LEN, 0);
		vector pos = c + (real - c) * k;
		PlaceScaled(segs[i], pos, width * k, SEG_LEN * k);	// scale x/z = width, y = length
	}
}
NoteThe scaled copy no longer sits behind hills that hide the real beam. A terrain trace from the camera to each piece (every 0.2 s, only while the copy is active) hides the pieces a hill would cover.

Damage by bounds, not by origin

Inside the beam everything takes 8,000 points per second. Checking the distance to an entity's origin misses buildings and large vehicles whose origin is metres away from the edge the beam touches. The distance to the world bounds is just as cheap and hits the house the beam actually grazes.

Example code – free to use
vector mins, maxs;
target.GetWorldBounds(mins, maxs);
float dx = Math.Max(Math.Max(mins[0] - p[0], p[0] - maxs[0]), 0);
float dz = Math.Max(Math.Max(mins[2] - p[2], p[2] - maxs[2]), 0);
if (Math.Sqrt(dx * dx + dz * dz) > CORE_RADIUS)	// 5 m: the visible beam incl. its glow
	continue;

vector hit = Vector(Math.Clamp(p[0], mins[0], maxs[0]), Math.Clamp(p[1], mins[1], maxs[1]), Math.Clamp(p[2], mins[2], maxs[2]));
MyDamage.Apply(target, EDamageType.TRUE, 8000 * dt, hit);

Around the beam a 40 m heat zone works every half second: vehicles take incendiary damage on their burnable zones (they catch fire), infantry takes fire damage, and trees fall. Vanilla destructible trees break on enough damage and fall away from the hit point for explosive damage – putting the hit point on the beam side makes them fall outward, like a blast.

Example code – free to use
if (BaseTree.Cast(target) && !m_aFelled.Contains(target))
{
	m_aFelled.Insert(target);
	vector away = target.GetOrigin() - beam;
	away[1] = 0;
	away.Normalize();
	MyDamage.Apply(target, EDamageType.EXPLOSIVE, 20000, target.GetOrigin() - away * 0.5, away);
}
NoteBuildings with a destructible building component collapse through their own damage manager; the replication of fallen trees and collapsed buildings is done by the vanilla systems. The add-on only has to deal the damage on the server.

Scorched ground

Every few metres the beam leaves a burning patch and a scorch decal. The decal is projected straight down onto whatever the trace from above hits – terrain, a roof or a wreck.

Example code – free to use
TraceParam param = new TraceParam();
param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
param.Start = pos + Vector(0, 3, 0);
param.End = pos - Vector(0, 3, 0);
world.TraceMove(param, null);
if (param.TraceEnt)
	world.CreateDecal(param.TraceEnt, pos + Vector(0, 2, 0), Vector(0, -1, 0), 0, 5,
		Math.RandomFloat(0, Math.PI2), 9, 1, SCORCH_EMAT, 600, 0xFFFFFFFF);	// 10 minutes
NoteVanilla resources are referenced as {{GUID}}path. Packed game data has no .meta files; the GUIDs of vanilla materials and particles can be looked up in the game's resourceDatabase.rdb.
Example code on this site is free to use in your own projects (credit appreciated). The M.A.W.S. mods, their code and assets are covered by the M.A.W.S. License – no copies or uploads. This documentation may not be reproduced in print or modified. Suggestions: Discord. Arma Reforger / Enfusion are trademarks of Bohemia Interactive.
Impressum · Privacy Policy