Jump to content
He'sCalledTheStig

Delaying unit Init until trigger is activated

Recommended Posts

So here's my problem: I have a line of code that goes into the init box of a group leader to make the group hunt the player(s) by setting a waypoint at the player's current position, however, the code runs at mission start (obviously because it's an init). I want to know if there's a line of code similar to WaitUntil that will work for the unit's init box in Eden.

The reason I want to do it this way is because I don't want to mess with .sqfs/variable names for each individual unit/squad. What I have now is copy/paste-able in Eden and that's what I'm looking for.

I've tried:

1) WaitUntil, but that command doesn't work in Eden

2) If TriggerIsActivated, but either I'm getting the syntax wrong or it doesn't work either.

3) enable dynamic sim, which is great, but it still places the waypoint at the start of the mission at the players

 

Alternatively, I could loop the code, but I can't figure out how to use Sleep effectively where it's still performance friendly.

 

Here's the code:

 

if (isServer) then { _null = this spawn { Hunt_players_fnc = { _player = objNull; _players = +(allPlayers - (entities "HeadlessClient_F")); _distance = 100000; { if (alive _x && _x distance (Leader _this) < _distance) then { _distance = _x distance (Leader _this); _player = _x; }; } foreach _players; if !(isNull _player) then { _wp = (Group _this) addWaypoint [getPos _player, (50 + (floor(random 70)))]; _wp setWaypointStatements ["true","_null = this spawn Hunt_players_fnc;"]; _wp setWaypointType "SAD"; _wp setWaypointCombatMode "RED"; _wp setWaypointSpeed "FULL"; }; }; _null = _this spawn Hunt_players_fnc; }; };

 

 

Thanks.

Share this post


Link to post
Share on other sites

I don't know why you want waituntil but it's possible to use it in the editor (init field) like this:

0 = [] spawn
{

 waituntil 
{ 
//wait code here 
};


// rest of the code 

};

 

  • Like 1

Share this post


Link to post
Share on other sites

You can use setVariable on the unit and retrieve it later at any point by filtering allUnits, like this:

//unit object init
this setVariable ["TAG_fnc_huntPlayer",true];

//someplace else
_playerHunters = allUnits select {_x getVariable ["TAG_fnc_huntPlayer",false]};//will contain all flagged units

Cheers

Share this post


Link to post
Share on other sites
15 hours ago, gc8 said:

I don't know why you want waituntil but it's possible to use it in the editor (init field) like this:


0 = [] spawn
{

 waituntil 
{ 
//wait code here 
};


// rest of the code 

};

 

Did not work. It says there's a missing ; somewhere and idk what it wants. Here is what I've got:

 

0 = [] spawn
{

 waituntil 
{ TriggerActivated Trigger1};


if (isServer) then { _null = this spawn { Hunt_players_fnc = { _player = objNull; _players = +(allPlayers - (entities "HeadlessClient_F")); _distance = 100000; { if (alive _x && _x distance (Leader _this) < _distance) then { _distance = _x distance (Leader _this); _player = _x; }; } foreach _players; if !(isNull _player) then { _wp = (Group _this) addWaypoint [getPos _player, (50 + (floor(random 70)))]; _wp setWaypointStatements ["true","_null = this spawn Hunt_players_fnc;"]; _wp setWaypointType "SAD"; _wp setWaypointCombatMode "RED"; _wp setWaypointSpeed "FULL"; }; }; _null = _this spawn Hunt_players_fnc; }; };

};

 

13 hours ago, Grumpy Old Man said:

You can use setVariable on the unit and retrieve it later at any point by filtering allUnits, like this:


//unit object init
this setVariable ["TAG_fnc_huntPlayer",true];

//someplace else
_playerHunters = allUnits select {_x getVariable ["TAG_fnc_huntPlayer",false]};//will contain all flagged units

Cheers

 I tried making a trigger the //someplace else and it didn't work. I'm not sure I understand how to input that.

Share this post


Link to post
Share on other sites
21 minutes ago, He'sCalledTheStig said:

Here is what I've got:

 

Expanded for readability, there are some issues:

0 = [] spawn
{
    waitUntil 
    {
        TriggerActivated Trigger1;
    };
	
    if (isServer) then {
        _null = this spawn { 
            Hunt_players_fnc = {
                _player = objNull; 
                _players = +(allPlayers - (entities "HeadlessClient_F")); 
                _distance = 100000; 
                {
                    if (alive _x && _x distance (Leader _this) < _distance) then {
                        _distance = _x distance (Leader _this); 
                        _player = _x;
                    };
                } foreach _players; 
                if !(isNull _player) then { 
                    _wp = (Group _this) addWaypoint [getPos _player, (50 + (floor(random 70)))]; 
                    _wp setWaypointStatements ["true","_null = this spawn Hunt_players_fnc;"]; 
                    _wp setWaypointType "SAD"; 
                    _wp setWaypointCombatMode "RED"; 
                    _wp setWaypointSpeed "FULL"; 
                }; 
            }; 
        _null = _this spawn Hunt_players_fnc; 
        }; 
    };
};

 

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

×