Module Framework – Arma 3
Jump to navigation
Jump to search
m (Corrected explanation of 'global' property, was inaccurate after the last change, but originally it was also slightly misleading) |
mNo edit summary |
||
Line 73: | Line 73: | ||
<li><big>'''Create config for module logic'''</big></li> | <li><big>'''Create config for module logic'''</big></li> | ||
* All in-game objects (soldiers, vehicles, buildings, logics, modules, ...) are defined in ''CfgVehicles'' class. | * All in-game objects (soldiers, vehicles, buildings, logics, modules, ...) are defined in ''CfgVehicles'' class. | ||
* '''All modules must inherit from Module_F''' parent class, either directly or through some additional sub-parent. While modules | * '''All modules must inherit from Module_F''' parent class, either directly or through some additional sub-parent. While modules inheriting from some other class will be still displayed in the Modules menu (F7), they won't be using the module framework and all benefits tied to it. | ||
* Modules functions are by default <u>not</u> executed when in [[Eden Editor]] workspace. It can be enabled using ''is3DEN'' property, but that will also change format of function params (see the section about writing a function below). | |||
class CfgVehicles | class CfgVehicles | ||
{ | { | ||
Line 106: | Line 107: | ||
{{codecomment|// 1 if modules is to be disabled once it's activated (i.e., repeated trigger activation won't work)}} | {{codecomment|// 1 if modules is to be disabled once it's activated (i.e., repeated trigger activation won't work)}} | ||
isDisposable = 1; | isDisposable = 1; | ||
{{codecomment|// // 1 to run init function in [[Eden Editor]] as well}} | |||
is3DEN = 1; | |||
{{codecomment|// Menu displayed when the module is placed or double-clicked on by Zeus}} | {{codecomment|// Menu displayed when the module is placed or double-clicked on by Zeus}} | ||
Line 194: | Line 197: | ||
* Create the ''functions'' folder within the addon folder and place *.sqf or *.fsm files there. | * Create the ''functions'' folder within the addon folder and place *.sqf or *.fsm files there. | ||
* Example: ''\<span style="color:indigo">myTag</span>_addonName\functions\fn_<span style="color:green">module</span><span style="color:orangered;">Nuke</span>.sqf'' | * Example: ''\<span style="color:indigo">myTag</span>_addonName\functions\fn_<span style="color:green">module</span><span style="color:orangered;">Nuke</span>.sqf'' | ||
* Input parameters differ based on value of ''is3DEN'' property. | |||
'''Default''' | |||
{{codecomment|// Argument 0 is module logic.}} | {{codecomment|// Argument 0 is module logic.}} | ||
_logic = [ | _logic = param [0,objNull,[objNull]]; | ||
{{codecomment|// Argument 1 is list of affected units (affected by value selected in the 'class Units' argument))}} | {{codecomment|// Argument 1 is list of affected units (affected by value selected in the 'class Units' argument))}} | ||
_units = [ | _units = param [1,[],<nowiki>[</nowiki>[]]]; | ||
{{codecomment|// True when the module was activated, false when it's deactivated (i.e., synced triggers are no longer active)}} | {{codecomment|// True when the module was activated, false when it's deactivated (i.e., synced triggers are no longer active)}} | ||
_activated = [ | _activated = param [2,true,[true]]; | ||
{{codecomment|// Module specific behavior. Function can extract arguments from logic and use them.}} | {{codecomment|// Module specific behavior. Function can extract arguments from logic and use them.}} | ||
Line 212: | Line 218: | ||
{{codecomment|// Module function is executed by [[spawn]] command, so returned value is not necessary.}} | {{codecomment|// Module function is executed by [[spawn]] command, so returned value is not necessary.}} | ||
{{codecomment|// However, it's a good practice to include one.}} | {{codecomment|// However, it's a good practice to include one.}} | ||
true | |||
'''Eden Editor Compatible''' | |||
When ''is3DEN = 1'' is set in module config, different, more detailed params are passed to the function. | |||
_mode = param [0,"",[""]]; | |||
_input = param [1,[],<nowiki>[</nowiki>[]]]; | |||
switch _mode do { | |||
{{codecomment|// Default object init}} | |||
case "init": { | |||
_logic = _input param [0,objNull,[objNull]]; {{codecomment|// Module logic}} | |||
_isActivated = _input param [1,true,[true]]; {{codecomment|// True when the module was activated, false when it's deactivated}} | |||
_isCuratorPlaced = _input param [2,false,[true]]; {{codecomment|// True if the module was placed by Zeus}} | |||
{{codecomment|// ... code here...}} | |||
}; | |||
{{codecomment|// When some attributes were changed (including position and rotation)}} | |||
case "attributesChanged3DEN": { | |||
_logic = _input param [0,objNull,[objNull]]; {{codecomment|// Module logic}} | |||
{{codecomment|// ... code here...}} | |||
}; | |||
{{codecomment|// When added to the world (e.g., after undoing and redoing creation)}} | |||
case "registeredToWorld3DEN": { | |||
_logic = _input param [0,objNull,[objNull]]; {{codecomment|// Module logic}} | |||
{{codecomment|// ... code here...}} | |||
}; | |||
{{codecomment|// When removed from the world (i.e., by deletion or undoing creation)}} | |||
case "unregisteredFromWorld3DEN": { | |||
_logic = _input param [0,objNull,[objNull]]; {{codecomment|// Module logic}} | |||
{{codecomment|// ... code here...}} | |||
}; | |||
{{codecomment|// When connection to object changes (i.e., new one is added or existing one removed)}} | |||
case "connectionChanged3DEN": { | |||
_logic = _input param [0,objNull,[objNull]]; {{codecomment|// Module logic}} | |||
{{codecomment|// ... code here...}} | |||
}; | |||
}; | |||
true | true | ||
<li><big>'''Create a module icon</big></li> | <li><big>'''Create a module icon</big></li> | ||
For use in [[2D Editor]], icons should be created with a standardized frame, as described below. [[Eden Editor]] adds a frame automatically and the icon file can contain just the desired image. | |||
<div style="background-color:grey; width:64px; height:64px; float:left; margin-right:30px;"> | <div style="background-color:grey; width:64px; height:64px; float:left; margin-right:30px;"> | ||
[[File:IconModule_ca.png]]</div> | [[File:IconModule_ca.png]]</div> | ||
# Right click on the image on left and ''Save Image As | # Right click on the image on left and ''Save Image As'' to get the default module icon. | ||
# Create a simple icon presenting the module in the circle. Avoid using too much detail, as the icon may downsized in the game. | # Create a simple icon presenting the module in the circle. Avoid using too much detail, as the icon may downsized in the game. | ||
# Save the image to ''\<span style="color:indigo">myTag</span>_addonName\data\icon<span style="color:orangered;">Nuke</span>_ca.paa'' | # Save the image to ''\<span style="color:indigo">myTag</span>_addonName\data\icon<span style="color:orangered;">Nuke</span>_ca.paa'' | ||
If you cannot or don't want to create a custom image, avoid using ''icon'' entry in the module config. The default icon will then be inherited from Module_F base class. | If you cannot or don't want to create a custom image, avoid using ''icon'' entry in the module config. The default icon will then be inherited from Module_F base class. |
Revision as of 15:42, 24 November 2015
Arma 3 introduces a module framework, which lets designer to simplify the configuration and chose how the module function will be executed (e.g., globally and for every player who joins later).
How to Create a Module
When creating a new module, follow these steps:
- Create a module addon.
- Make a folder named myTag_addonName a create a config.cpp file in it.
- Inside, declare a CfgPatches class with your addon and its modules (in the units array). Without this, the game wouldn't recognize the addon.
- Make sure the addon and all objects start with your tag, e.g. myTag
- Select a module category
- Modules are placed into basic categories which makes finding a desired module easier for an user. Use can use on of the existing categories:
- Create config for module logic
- All in-game objects (soldiers, vehicles, buildings, logics, modules, ...) are defined in CfgVehicles class.
- All modules must inherit from Module_F parent class, either directly or through some additional sub-parent. While modules inheriting from some other class will be still displayed in the Modules menu (F7), they won't be using the module framework and all benefits tied to it.
- Modules functions are by default not executed when in Eden Editor workspace. It can be enabled using is3DEN property, but that will also change format of function params (see the section about writing a function below).
- Pre-defined sync preview entities are:
- Anything - Any object - persons, vehicles, static objects, etc.
- AnyPerson - Any person. Not vehicles or static objects.
- AnyVehicle - Any vehicle. No persons or static objects.
- AnyStaticObject - Any static object. Not persons or vehicles.
- AnyBrain - Any AI or player. Not empty objects
- AnyAI - Any AI unit. Not players or empty objects
- AnyPlayer - Any player. Not AI units or empty objects
- EmptyDetector - Any trigger
- Configure a module function
- Place class CfgFunctions to config.cpp. See Functions Library (Arma 3) for more info about functions configuration.
- Write the module function
- Create the functions folder within the addon folder and place *.sqf or *.fsm files there.
- Example: \myTag_addonName\functions\fn_moduleNuke.sqf
- Input parameters differ based on value of is3DEN property.
- Create a module icon For use in 2D Editor, icons should be created with a standardized frame, as described below. Eden Editor adds a frame automatically and the icon file can contain just the desired image.
- Right click on the image on left and Save Image As to get the default module icon.
- Create a simple icon presenting the module in the circle. Avoid using too much detail, as the icon may downsized in the game.
- Save the image to \myTag_addonName\data\iconNuke_ca.paa
class | displayName |
---|---|
Effects | Effects |
Events | Events |
Modes | Gameplay Modes |
GroupModifiers | Group Modifiers |
Intel | Intel |
NO_CATEGORY | Misc |
Multiplayer | Multiplayer |
ObjectModifiers | Object Modifiers |
Sites | Sites |
StrategicMap | Strategic |
Supports | Supports |
Alternatively, you can create your own one:
class CfgFactionClasses { class NO_CATEGORY; class myTag_explosions: NO_CATEGORY { displayName = "Explosions"; }; };
If you cannot or don't want to create a custom image, avoid using icon entry in the module config. The default icon will then be inherited from Module_F base class.