Commanding Menu Modding – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
(Add config links)
Line 98: Line 98:


{{Feature|informative|
{{Feature|informative|
A command class can be used more than once, provided its <enforce inline>[Attribute()]</enforce> make it generic and malleable enough <!-- see <enforce inline>SCR_WaypointGroupCommand</enforce> multiple usages in {{Link/Enfusion|armaR|enfusion://ResourceManager/~ArmaReforger:Configs/Commanding/Commands.conf}} .-->
A command class can be used more than once, provided its <enforce inline>[Attribute()]</enforce> make it generic and malleable enough <!-- see <enforce inline>SCR_WaypointGroupCommand</enforce> multiple usages in {{Link|enfusion://ResourceManager/~ArmaReforger:Configs/Commanding/Commands.conf}} .-->
}}
}}


=== Command Menu Declaration ===
=== Command Menu Declaration ===


The ''commandingMenu.conf'' config file declares what is present in the actual commanding menu.
The {{Link|enfusion://ResourceManager/~ArmaReforger:Configs/Commanding/CommandingMenu.conf}} config file declares what is present in the actual commanding menu.


The ''commandingMapMenu.conf'' config file declares what is present in the ''map'' commanding menu.
The {{Link|enfusion://ResourceManager/~ArmaReforger:Configs/Commanding/CommandingMapMenu.conf}} config file declares what is present in the ''map'' commanding menu.


Commands are referenced simply by their previously declared ID there along with their display text.
Commands are referenced simply by their previously declared ID there along with their display text.

Revision as of 12:23, 13 October 2023

armareforger-symbol black.png1.0.0


Class Creation

The first step is to create a new class inheriting from cSCR_BaseGroupCommand.

From there, it is time to override important methods to give life to the command:

Execute

The cExecute() method determines what happens when the command is executed from the menu; it can be AI commanding, but it can actually be anything - an emote, a hint, a Game Master lightning, etc.

This method is broadcast to everyone, meaning it is executed on the server and on each client; be sure to have the adequate checks to retain server-only logic or target UI-equipped machines.

This behaviour may change in the future with more network targeting options.

See also Replication.

CanBeShown

The cCanBeShown() method determines when is the command shown in the command menu; for example, a "move" order cannot be issued by a non-leader, a "get in" order cannot be issued without aiming at a vehicle, etc.


The command can be shown, yet be unavailable - see CanBePerformed below.

CanBePerformed

The cCanBePerformed() method determines whether or not the command can be executed; for example, an emote cannot be used when in a vehicle, lightning cannot be thrown if not aiming at the terrain, etc.

Example

Copy
[BaseContainerProps()] class SCR_MurderinoCommand : SCR_BaseGroupCommand { //------------------------------------------------------------------------------------------------ override bool Execute(IEntity cursorTarget, IEntity target, vector targetPosition, int playerID, bool isClient) { // server-only, as killing a character is handled by other systems that handle its replication if (isClient) return false; ChimeraCharacter character = ChimeraCharacter.Cast(cursorTarget); if (!character) return false; // we get the damage manager so we can do the intended thing SCR_DamageManagerComponent dmgManager = character.GetDamageManager(); if (!dmgManager) return false; // execute dmgManager.Kill(dmgManager.GetInstigator()); return true; } //------------------------------------------------------------------------------------------------ // this method is always called on player machine, no need for additional checks override bool CanBePerformed() { PlayerCamera camera = PlayerCamera.Cast(GetGame().GetCameraManager().CurrentCamera()); if (!camera) return false; // get the entity at which the local player is currenty aiming IEntity cursorEntity = camera.GetCursorTarget(); // only characters can be killed if (!ChimeraCharacter.Cast(cursorEntity)) return false; SCR_CharacterControllerComponent characterControllerComp = SCR_CharacterControllerComponent.Cast(cursorEntity.FindComponent(SCR_CharacterControllerComponent)); if (!characterControllerComp) return false; // do not allow the action on dead characters if (characterControllerComp.IsDead()) return false; // all checks passed - the action can be performed return true; } }


Config Declaration

Command Declaration

The commands.conf config file is the file that declares the class as a command and holds its various properties, including its string ID, whether or not the command is leader-only, etc.

Now remains adding that command to the commanding menu.

A command class can be used more than once, provided its c[Attribute()] make it generic and malleable enough

Command Menu Declaration

The CommandingMenu.conf config file declares what is present in the actual commanding menu.

The CommandingMapMenu.conf config file declares what is present in the map commanding menu.

Commands are referenced simply by their previously declared ID there along with their display text.

That's it! The new command is now added to the desired Command Menu.