Skip to content
Kex edited this page Jan 5, 2017 · 36 revisions

###Contents:

  1. Notes
  2. Register Custom Modules
  3. Integrate Selection Option
  4. Dynamic Dialogs

###Notes: This page is dedicated to how to register custom modules. In addition, you can find here some useful functions for your module script.

###Register Custom Modules: As in Ares you can define your own custom modules. The function to register custom modules is Ares_fnc_RegisterCustomModule.
The function takes three arguments:

  • _this select 0    STRING     Module Category Name (If the category already exists, the modul will be appended to that category)
  • _this select 1    STRING     Module Name (If the module already exists, the old module gets overridden).
  • _this select 2    CODE        Code that is executed when the module is placed.

There are two arguments available for your script:

  • _this select 0    ARRAY     Returns position AGLS where the module was placed.
  • _this select 1    OBJECT    Returns ObjNull or the object on which the module was placed.

There are two ways to integrate that function:

  1. You can define a custom module in the mission. As an example you can place the code below in the init.sqf of your mission:

if (local player and (isClass (configFile >> "CfgPatches" >> "achilles_modules_f_achilles"))) then
{
    ["My Category", "My Module",
    {
        _module_position = param [0,[0,0,0],];
        _selected_object = param [1,ObjNull,[ObjNull]];
        systemChat format ["Module position: %1", _module_position];
        systemChat format ["Selected Object: %1", _selected_object ]
    }] call Ares_fnc_RegisterCustomModule;
};

  1. Execute Ares_fnc_RegisterCustomModule with the Execute Code module.

###Integrate Selection Option: A template to integrate the Selection Option is presented below:

["My Category", "My Module",
{
     private "_selected_objects";      _module_position = param [0,[0,0,0],];
     _selected_object = param [1,ObjNull,[ObjNull]];
    
    if (isNull _selected_object) then
    {
        _selected_objects = ["objects"] call Achilles_fnc_SelectUnits;
    } else
    {
        _selected_objects = [_selected_object];
    };
    if (isNil "_selected_objects") exitWith {};
    if (count _selected_objects == 0) exitWith
    {
        ["No object was selected!"] call Ares_fnc_ShowZeusMessage;
        playSound "FD_Start_F"
    };
    systemChat str [_module_position, _selected_objects];
}] call Ares_fnc_RegisterCustomModule;

As you see in the line with systemChat, there are two private variables available:

  • _module_position    ARRAY     Returns position AGLS where the module was placed.
  • _selected_object      ARRAY     Array of selected objects.

###Dynamic Dialogs: A good module needs a GUI. For this purpose Ares provides a dynamic dialog which is extended in Achilles.
The function to create dynamic dialogs is Ares_fnc_ShowChooseDialog.
The function takes two to three arguments:

  • _this select 0    STRING     Dialog Title (will be displayed in the header)
  • _this select 1    ARRAY       Array of arrays (see below)
  • _this select 2    STRING     (optional) Name of a custom function that gets executed when the dialog is opened, closed and when the value of a combo box was changed.

The array of arrays can have different structures. One array corresponds to one GUI choice element.

Control Type _this select _i Data Type Description
All Types _i = 0 STRING Label of the choice
Combo Box _i = 1 ARRAY Array of strings corresponding to the different choices
      | _i = 2 | _SCALAR_ | (optional) Default choice (index given by array of choices starting with 0

Text | _i = 1 | STRING | Has to be an empty string "" | _i = 2 | STRING | (optional) Default string in the text window. Slider | _i = 1 | STRING | String has to be "SLIDER" | _i = 2 | SCALAR | (optional) Default slider value (between 0 and 1). Sides | _i = 1 | STRING | String has to be "ALLSIDE" (include sideLogic) or "SIDE" (excludes sideLogic) | _i = 2 | SCALAR | (optional) Default side (0 => sideLogic; 1 => east; 2 => west; 3 => independent; 4 => civilian)

The function returns an array which contains all the choices in the order the GUI choice elements were given. The data type of the array element depends on the control type:

Control Type Data Type Description
Combo Box SCALAR Choice index (index given by array of choices starting with 0).
Text STRING Returns the text.
Slider SCALAR Returns the slider value (between 0 and 1).
Sides SCALAR Returns the sides index (0 => sideLogic; 1 => east; 2 => west; 3 => independent; 4 => civilian)

Here is an example of a dialog that integrates all available control types:

_dialog_result = ["Test Dialog",
[
    ["Combo Box Control", ["Choice 1","Choice 2"], 1],
    ["Text Control", "", "default text"],
    ["Slider Control", "SLIDER", "default text"],
    ["Side Control", "SIDE", 2]
]] call Ares_fnc_showChooseDialog;
if (count _dialog_result == 0) exitWith {};

systemChat format ["Combo Box Result: %1", _dialog_result select 0];
systemChat format ["Typed Text: %1", _dialog_result select 1];
systemChat format ["Slider Result: %1", _dialog_result select 2];
systemChat format ["Selected Side: %1", _dialog_result select 3];

Note that if the dialog is cancled, the function returns an empty array. In order to catch that case, the following line was introduced:

if (count _dialog_result == 0) exitWith {};


You should get the same result as below: