Creating new profile

  1. 7 years ago

    Hi,

    Ive been plating around creating a new profile from script and assignin it an activeCommand.
    The profiles are spawning ok on start and assuming their roles as desired. So I guess params are being passed ok to Alive fnc.

    I'm just using this modules: Virtual Ai System, Alive required and Player Options.

    This is the fnc i'm using:

    params ["_comm","_pat_area","_g_mrkr","_g_type","_g_size","_g_ia","_g_rinf"];

    private _g_side = format ["%1",_comm getVariable "side"];
    private _c_faction = _comm getVariable "faction";
    private _g_pos = markerpos _g_mrkr;

    waitUntil {!isNil "ALIVE_profileSystemInit"};

    private _g_units = call compile format ["%1_%2_%3", _c_faction, _g_type, _g_size];
    private _g_faction = call compile format ["%1_FACTION", _c_faction];

    private _g_profile = [_g_units, _g_side, _g_faction, _g_pos] call ALIVE_fnc_createProfileEntity;
    private _g_profile_id = [_g_profile, "profileID"] call ALIVE_fnc_hashGet;

    waitUntil {sleep 0.03; !isNil "_g_profile_id"};

    switch (_g_ia) do {
    case "BASE_GUARD": {
    [_g_profile, "setActiveCommand", ["ALIVE_fnc_garrison","spawn",[25,"false"]]] call ALIVE_fnc_profileEntity;
    };
    case "BASE_PATROL": {
    [_g_profile, "setActiveCommand", ["ALIVE_fnc_ambientMovement","spawn",[150,"SAFE"]]] call ALIVE_fnc_profileEntity;
    };
    default {};
    };

    if (!_g_rinf) exitWith {};

    while {
    _g_profile_id in ([ALIVE_profileHandler, "getProfilesBySide", _g_side] call ALIVE_fnc_profileHandler)
    } do {
    sleep 10;
    };

    sleep 10;

    [_comm,_pat_area,_g_mrkr,_g_type,_g_size,_g_ia,_g_rinf] spawn grp_spawn;

    I can check if the profile is alive or not, as soon it gets unregistered I should be able to re-create it (in the example im removing all conditions like player distance to base, or side control, etc, just existence of the profile)

    So, here's the problem.

    I kill the spawned groups, it gets unregistered, and the while-do loop gets its time to recreate it. The new iteration of the function creates the profile in its starting position and then teleport it to [0,0,0]. Shouldn't it work like in the first iteration?

    Im having an additional error sometimes when groups spawn/despawn by player distance, the profile gets unregistered and tries to recreate (of this get me to the first problem).

    This the error it shows in RPT:

    10:41:00 Error in expression < (_units select 0));
    _units = _units - [_leader];

    if (count _units == 0) exitwi>
    10:41:00 Error position: <_leader];

    if (count _units == 0) exitwi>
    10:41:00 Error Undefined variable in expression: _leader
    10:41:00 File x\alive\addons\x_lib\functions\behaviour\fnc_groupGarrison.sqf, line 40

    Any help, please? Or is it just this can't be done?

    Thx in advance.

    B.

  2. Edited 7 years ago by marceldev89

    I think your call to ALIVE_fnc_createProfileEntity is a bit off. It should be called as _result = [["B_Heli_Light_01_F"],"WEST","BLU_F",getPosATL player] call ALIVE_fnc_createProfileEntity;.

    So:

    Parameter 1 => array of unit classes
    Parameter 2 => string with the name of the side
    Parameter 3 => string with the name of the faction
    Parameter 4 => position (array)
  3. Edited 7 years ago by Baireswolf

    I will stick to one error at a time.

    I've tested it without assigning the group any ActiveCommand and it happens anyway.

    In fact all parameters passed are valid in the first iteration and de profile/group is created as desired.

    _g_units is an array of unit man classes
    _g_side is string (formated side stored ina a game logic variable)
    _g_faction is string (formated from a lib that passes true factions according to side and global params)
    _g_pos is a 2D position array (markerpos)

    When the system detects the profile is unregistered, and so it is no longer in the list provided by [ALIVE_profileHandler, "getProfilesBySide", _g_side] call ALIVE_fnc_profileHandler, it passes same params that haven't been modified to the next iteration.. that's when the new profile is created in the same initial position, but then is teleported to [0,0,0].

  4. Ah, missed the call compile bits.. :)

    But yeah, it should work. I guess it's time to start debugging all the vars with diag_log and check whether they are what you think they are.

  5. Edited 7 years ago by Baireswolf

    Not that,

    The fnc is precompiled at mission initialization

    grp_spawn = compile preprocessFile "grp\spawn.sqf";

    The first iteration runs fine spawned with the same params... but i think i've found it

    private _g_units = call compile format ["%1_%2_%3", _c_faction, _g_type, _g_size];
    This line iis passing an empty array to the profile creator fnc for the unit list. Gonna rebuild the array generator.. can't figure out why its not happening in the first spawning round (or perhaps im not realizing it really happens with some instances).

  6. Fixed:

    params ["_comm","_pat_area","_g_mrkr","_g_type","_g_size","_g_ia","_g_rinf"];

    private _g_side = format ["%1",_comm getVariable "side"];
    private _c_faction = _comm getVariable "faction";
    private _g_pos = markerpos _g_mrkr;

    waitUntil {!isNil "ALIVE_profileSystemInit"};

    private _g_data = [_c_faction,_g_type,_g_size] call grp_types;
    private _g_faction = [_g_data,"faction"] call CBA_fnc_hashGet;
    private _g_units = [_g_data,"units"] call CBA_fnc_hashGet;

    //player sideChat format ["%1 %2 %3 %4 %5", _g_units, _g_side, _g_faction, _g_pos, _comm];
    private _g_profile = [_g_units, _g_side, _g_faction, _g_pos] call ALIVE_fnc_createProfileEntity;
    private _g_profile_id = [_g_profile, "profileID"] call ALIVE_fnc_hashGet;

    waitUntil {sleep 0.03; !isNil "_g_profile_id"};

    switch (_g_ia) do {
    case "BASE_GUARD": {
    [_g_profile, "setActiveCommand", ["ALIVE_fnc_garrison","spawn",[25,"false"]]] call ALIVE_fnc_profileEntity;
    };
    case "BASE_PATROL": {
    [_g_profile, "setActiveCommand", ["ALIVE_fnc_ambientMovement","spawn",[150,"SAFE"]]] call ALIVE_fnc_profileEntity;
    };
    default {};
    };

    if (!_g_rinf) exitWith {};

    while {
    _g_profile_id in ([ALIVE_profileHandler, "getProfilesBySide", _g_side] call ALIVE_fnc_profileHandler)
    } do {
    sleep 10;
    };

    while {
    ({isPlayer _x || _x == vehicle player} count ((markerpos _g_mrkr) nearEntities 1500) > 0) || (markerColor _pat_area != format ["color%1", _comm getVariable "side"])
    } do {
    sleep 10;
    };

    sleep 10;

    [_comm,_pat_area,_g_mrkr,_g_type,_g_size,_g_ia,_g_rinf] spawn grp_spawn;

    Created a fnc that generates a hash with valid values for _g_faction and _g_units array.

    Later it checks for near players and the color of the sector they operate on after generating a new iteration. The old problem with activecommands was also solved by this.

    Thx to @marceldev89 who pointed (unwillingly perhaps to that call compile bit) :)

    I'll post the full system at a later stage

 

or Sign Up to reply!