Commanding Menu Modding – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
m (Add another one)
 
(One intermediate revision by the same user not shown)
Line 24: Line 24:


The <enforce inline>CanBeShown()</enforce> 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 <enforce inline>CanBeShown()</enforce> 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 {{Link|#CanBePerformed}} below.
The command can be shown, yet be unavailable - see {{Link|#CanBePerformed}} below.
Line 93: Line 92:
=== Command 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.
The {{Link|enfusion://ResourceManager/~ArmaReforger:Configs/Commanding/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.
Now remains adding that command to the commanding menu.


{{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 {{Link|enfusion://ResourceManager/~ArmaReforger:Configs/Commanding/CommandingMapMenu.conf}} config file declares what is present in the ''map'' 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.
Commands are referenced simply by their previously declared ID there along with their display text.

Latest revision as of 18:17, 13 October 2023

armareforger-symbol black.png1.0.0


Class Creation

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

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

Execute

The Execute() 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 CanBeShown() 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 CanBePerformed() 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

[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 [Attribute()] make it generic and malleable enough

Command Menu Declaration

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.