Jump to content
jakkob4682

configProperties Question

Recommended Posts

How would I use this to generate a random group from a specific side?  I've used it to generate a random faction from a certain side, what I'm trying to do is use this command to generate a random infantry group from a random faction.

Share this post


Link to post
Share on other sites

Hey, this a variation of something i've been using for a while. Hope it works for you. Extracting config credits goes to @davidoss.

Spoiler

/*
    Description:
    Spawns a random group of given faction, at given position, of given type with a size of given minimum/maximum number of units.

    Usage:
    _group = ["BLU_F", (getPos player), "Infantry", [2,5]] execVM "spawnfactiongroup.sqf";

    Params:
    0 (faction) - e.g. "BLU_F".
    1 (position) - e.g. (getPos player).
    2 (type) - Faction dependent. e.g. "Armored", "Infantry", "Mechanized", "Motorized", "SpecOps", "Support".
    3 (minimum and maximum number of units) - e.g. [2,5].

    Returns:
    _group
*/

params [["_faction", "BLU_F"], ["_position", [0,0,0]], ["_type", "Infantry"], ["_minmaxsize", [2,5]]];

_fnc_getFactionSide = {
    /*
        Returns faction side

        0 = opfor (east)
        1 = blufor (west)
        2 = independent (resistance)
        3 = civilian
    */
    params ["_faction"];

    private _index = [0,1,2,3] findIf{
        private _factions = _x call _fnc_getSideFactions;
        private _index = _factions findIf {_x isEqualTo _faction};
        if (_index != -1) then{true}else{false};
    };

    private _side = call {
        if (_index isEqualTo 0) exitWith {east};
        if (_index isEqualTo 1) exitWith {west};
        if (_index isEqualTo 2)  exitWith {resistance};
        if (_index isEqualTo 3) exitWith {civilian};
        if (_index isEqualTo -1) exitWith {false};
    };

    _side
};

_fnc_getSideFactions = {
    /*
        Returns factions for each side ID

        Author: davidoss
        Reference: https://forums.bohemia.net/forums/topic/190474-solvedtrouble-with-gathering-classes-from-configfile/

        Input: BIS_fnc_sideID. https://community.bistudio.com/wiki/BIS_fnc_sideID
    */
    params ["_side"];

    private _array = [];
    {
        _array pushback    (configName _x);
    } forEach ("getNumber (_x >> 'side') isEqualTo _side" configClasses (configfile >> "CfgFactionClasses"));
    
    _array
};

_fnc_getGroupTypes = {
    /*
        Returns configName groups of given side-faction-type of given size.
        Ex: _infgroups = [_side,_faction,"Infantry",_minmaxsize] call _fnc_getGroupTypes;
        Select one from the array to spawn with BIS_Fnc_spawnGroup.
        Ex: _group = [[0,0,0], west, (configFile >> "CfgGroups" >> (str west) >> "BLU_F" >> "Infantry" >> (_infgroups select 0))] call BIS_Fnc_spawnGroup;
    */
    params ["_side", "_faction", "_class", "_minmaxsize", "_sidestrg"];

    private _minsize = _minmaxsize param [0, 2];
    private _maxsize = _minmaxsize param [1, 8];

    _sidestrg = if (_side isEqualTo resistance) then{"indep"}else{(str _side)};

    private _array = [];
    {
        private _unitscount = count ("true" configClasses _x);
        if (_unitscount >= _minsize && _unitscount <= _maxsize) then{
            _array pushback    (configName _x);
        };
    }forEach ("true" configClasses (configFile >> "CfgGroups" >> _sidestrg >> _faction >> _class));
    
    _array
};

private _side = _faction call _fnc_getFactionSide;

private _groups = [_side, _faction, _type, _minmaxsize] call _fnc_getGroupTypes;

private _group = [_position, _side, (configFile >> "CfgGroups" >> (str _side) >> _faction >> _type >> selectRandom _groups)] call BIS_Fnc_spawnGroup;

_group

 

Save this as spawnfactiongroup.sqf on your mission folder and execVM it with something like:

null=["BLU_F", (getPos player), "Infantry", [2,5]] execVM "spawnfactiongroup.sqf";

 

If you want a random faction do:

_allfactions = ["BLU_F",  "BLU_G_F", "IND_F"]; //add/edit all your factions inside this array.

_group = [(selectRandom _allfactions), (getPos player), "Infantry", [2,5]] execVM "spawnfactiongroup.sqf";

 

 

Edited by RCA3
min/max group size

Share this post


Link to post
Share on other sites

The reason for wanting to use config entries was so I don't need to copy and paste 31 different factions, and 124 different infantry group types just to select one random faction and a random infantry group type from that config.

 

So I'm trying to select a random faction from the config.  Then using the same config select a random Infantry group type.

 

Thats where I'm stuck.

Share this post


Link to post
Share on other sites

Edited the script above so you can pass minimum and maximum group size.

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

×