Jump to content
Sign in to follow this  
tomhighway

Set/Update module attributes in a script

Recommended Posts

I want to create a module (any module) dynamically in a script and change it's attributes on certain events. I've read that modules can be created like any other LOGIC object (example https://community.bistudio.com/wiki/Artillery_Module#Frequently_Asked_Questions for artillery module) using createUnit, synchronizeObjectsAdd, synchronizeObjectsRemove.

 

But is there a way to:

  1. set the module attributes upon creation
  2. change them later during course of the mission

Thank you.

Share this post


Link to post
Share on other sites

Judging by the example of how to create a module, getVariable and setVariable on module object should be used. See more here (write the module function).

  • Like 1

Share this post


Link to post
Share on other sites

Ok, I'm going to help out people following me.

 

Here it is - I've dynamically added a ACE 3 sitting module by init.sqf. The essential thing is finding out the function name that has to be spawned (so the wiki says, modules are spawned, not called). You can do that in 3DEN by temporarily placing module in mission - right click on it and select Find in Config Viewer. Then look for value of the function attribute - that is module function name.

_center = createCenter sideLogic;
_group = createGroup _center;
_pos = getPos player;

module_sitting = _group createUnit ["ACE_ModuleSitting", _pos, [], 0, ""];

/* 
 * this is where you set the arguments of the module, name can be found out from config viewer
 * class Arguments
 */

module_sitting setVariable ["enable", true]; 

// [name of the module, units that module is affecting, activated] spawn function_name;
[module_sitting, [], true] spawn ace_sitting_fnc_moduleInit;
  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

Unfortunately, I was getting excited too early. It seems that createUnit calls the initialization of the module but with default options rendering the following setVariable calls useless in ACE 3 case.

 

There is a telling warning in the .rpt log

 

SetSetting [ace_captives_allowHandcuffOwnSide] Trying to set forced setting

 

I am stuck. I don't know if there is a Bohemia function that is spawning the modules instead of createUnit. Help appreciated.

Share this post


Link to post
Share on other sites

I was also confronted with this question for the vanilla spawn AI modules. Although this thread is old, I still think it is the best place to post a solution.

The solution is to use the alternative syntax of createUnit:

type createUnit [position, group, init, skill, rank]

The init argument is the init line, which is executed before the module function. Hence, if you do the synchronizations and set the variables here, then it works fine.

Note that this syntax does not return the object, so you will have to assign the module to a global variable.

 

  • Thanks 2

Share this post


Link to post
Share on other sites

Don't mean to necro but thank you for this! Turns out I was getting the arguments from the wrong place (game files themselves), Config Viewer fixed that. 
Now I can have the Warlords module on our Zeus template begin only if a mission parameter is set. 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×