← 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

Start here

Enforce Script basics

Everything you need to know before the first line of walker code – for people who can program a little, but have not modded Arma Reforger yet.

The tools

Enforce Script in two minutes

Enforce Script looks like C# or Java: classes, methods, if/for, strong types. A few things are different:

ThingWhat it means
vectorthree floats (x, y, z). y is up, z is forward. v[0], v[1], v[2] read the parts.
vector mat[4]a transform: three axis vectors (right, up, forward) and the position in mat[3].
refstrong reference for class members holding objects (ref array<int> m_aList). Without it the object can be deleted.
overriderequired when you replace a method of the parent class.
modded class Xchanges an existing class (also vanilla ones) everywhere, without copying it.
anglesmost engine angles are degrees, but some setters want radians – check the method comment.

Components: how code gets into the game

You do not write a main(). You write a component and add it to a prefab (an entity template, for example a vehicle) in the Workbench. A component always comes as a pair of classes:

Example code – free to useScripts/Game/MyMod/MyMod_SpeedPrinterComponent.c
// 1) the "Class" class: holds data shared by all instances; the editor props make it show up in the Workbench
[ComponentEditorProps(category: "MyMod", description: "Prints the speed of the vehicle")]
class MyMod_SpeedPrinterComponentClass : ScriptComponentClass
{
}

// 2) the component itself: one instance per entity
class MyMod_SpeedPrinterComponent : ScriptComponent
{
	// [Attribute] = editable in the prefab editor, value saved in the prefab
	[Attribute("1.0", desc: "Print every n seconds")]
	protected float m_fInterval;

	protected float m_fTimer;

	//! called once when the entity is created
	override void OnPostInit(IEntity owner)
	{
		super.OnPostInit(owner);
		SetEventMask(owner, EntityEvent.FRAME);		// without this, EOnFrame is never called
	}

	//! called every frame
	override void EOnFrame(IEntity owner, float timeSlice)
	{
		m_fTimer += timeSlice;			// timeSlice = seconds since the last frame
		if (m_fTimer < m_fInterval)
			return;

		m_fTimer = 0;
		Physics phys = owner.GetPhysics();
		if (phys)
			Print("Speed: " + (phys.GetVelocity().Length() * 3.6).ToString() + " km/h");
	}
}

Compile (Script Editor → Compile and Reload), open a vehicle prefab, Add component → your component appears under the category you gave it. Drive the vehicle in the world editor (Play) and watch the log console.

TipThe Print output goes to the console of the Workbench and into console.log in the profile's logs folder. Logging is your main debugging tool – use it generously while building.

Multiplayer in plain words

In multiplayer the same entity exists on the server and on every client. Your component runs on all of them. Three questions decide where code has to run:

QuestionAnswer in code
Is this the server?Replication.IsServer() – decides game rules, damage, who may do what.
Does this machine simulate the physics of this entity?RplComponent.IsOwner() – only the owner should change velocities.
Is this only for looks?Run it everywhere: animation, effects, sound, HUD.

Two tools move information around:

The one pitfall everybody hitsA client can only call a server RPC on something it owns – in practice its own SCR_PlayerController. RPCs sent from a vehicle component disappear without any error message. See Architecture for the pattern.

Testing in multiplayer

  1. First test in the world editor (singleplayer = server and client in one).
  2. Then on a real dedicated server with a separate client. Things that work in the editor often break there, because the client is no longer the server and no longer the physics owner.
  3. Read both logs: the server's and the client's console.log.
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