Jump to content
J. Schmidt

Reinforcement Script Using Scripted Triggers and BIS_FNC_SpawnGroup

Recommended Posts

I'm trying to create a scripted reinforcement trigger, all the AI groups spawn in and start patrolling using the BIS_FNC_SpawnGroup, BIS_FNC_TaskPatrol, and BIS_FNC_TaskDefend. But when I engage the enemy, the reinforcements that spawned in don't move to the area in which is being patrolled. Here is what I have for my code:

 

if (isServer) then {
    trg = createTrigger ["EmptyDetector", getMarkerPos "marker_0"];
    trg setTriggerArea [300, 300, 0, false];
    trg setTriggerActivation ["WEST", "PRESENT", false];

    trg1 = createTrigger ["EmptyDetector", getMarkerPos "marker_0"];
    trg1 setTriggerArea [0, 0, 0, false];
    trg1 setTriggerActivation ["ANY", "WEST D", false];

    grp = [getMarkerPos "marker_0", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfAssault")] call bis_fnc_spawngroup;
    [grp, position leader grp, 300] call bis_fnc_taskpatrol;

    grp1 = [getMarkerPos "marker_1", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call bis_fnc_spawngroup;
    [grp1, position leader grp1, 300] call bis_fnc_taskpatrol;

    grp2 = [getMarkerPos "marker_2", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call bis_fnc_spawngroup;
    [grp2, position leader grp2, 300] call bis_fnc_taskpatrol;

    grp3 = [getMarkerPos "marker_3", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam")] call bis_fnc_spawngroup;
    [grp3, position leader grp3] call bis_fnc_taskdefend;

    grp4 = [getMarkerPos "marker_4", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Mechanized" >> "OIA_MechInf_Support")] call bis_fnc_spawngroup;
    wp = grp4 addWaypoint [getMarkerPos "marker_4", 0];
    wp setWaypointType "HOLD";
    wp setWaypointBehaviour "SAFE";

    if (triggerActivated trg1) then {
        wp1 = grp4 addWaypoint [getMarkerPos "marker_0", 0];
        wp1 setWaypointType "MOVE";
        wp1 setWaypointSpeed "NORMAL";
        wp1 setWaypointBehaviour "AWARE";
    };
}

 

Share this post


Link to post
Share on other sites

I've got the script working after some more research, but now I need to narrow it down to only call reinforcements if one of the 4 groups started shooting. I'm uncertain of how to do this.

 

if (isServer) then {
    trg = createTrigger ["EmptyDetector", getMarkerPos "marker_0"];
    trg setTriggerArea [300, 300, 0, false];
    trg setTriggerActivation ["WEST", "PRESENT", false];

    grp = [getMarkerPos "marker_0", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfAssault")] call bis_fnc_spawngroup;
    [grp, position leader grp, 300] call bis_fnc_taskpatrol;

    grp1 = [getMarkerPos "marker_1", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call bis_fnc_spawngroup;
    [grp1, position leader grp1, 300] call bis_fnc_taskpatrol;

    grp2 = [getMarkerPos "marker_2", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call bis_fnc_spawngroup;
    [grp2, position leader grp2, 300] call bis_fnc_taskpatrol;

    grp3 = [getMarkerPos "marker_3", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam")] call bis_fnc_spawngroup;
    [grp3, position leader grp3] call bis_fnc_taskdefend;

    grp4 = [getMarkerPos "marker_4", east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Mechanized" >> "OIA_MechInf_Support")] call bis_fnc_spawngroup;
    [grp4, position leader grp4] call bis_fnc_taskdefend;


    alert = false;        // Creation of the name variable "Alert" as "False" that will be used to activate the trigger when it becomes "True"

    // Command that recognizes the firing of a weapon from some AI on the side "East", then removes the handler, and turns the variable named "Alert" to true, which will trigger the trigger in the editor.
    {
        if ((side _x isEqualTo east)) then
        {
            _x addEventHandler ["firedMan", {
                deleteWaypoint [grp4, 1];
                [grp4, getMarkerPos "marker_0"] call BIS_fnc_taskAttack;

                hintSilent "Reinforcements Inbound!"; {
                    if ((side _x isEqualTo east)) then {
                        _x removeEventHandler ["firedMan", 0];
                    };
                } forEach allUnits;

                /*alert = true;
                publicVariable "alert";
                alert remoteExec ["true"];*/        // If Un-Commented Out, mission will fail and then end as soon as the enemy fires.
            }];
        };
    } forEach allUnits;
};

 

Share this post


Link to post
Share on other sites

As far as you spawn units on server, you don't need to remoteExec or public variable anything if your script runs on server.

Your trigger (for BLUFOR presence in area) should be server only.

You need to add a condition for the firing, so your code becomes:

trg = createTrigger ["EmptyDetector", getMarkerPos "marker_0"];

trg setTriggerArea [300, 300, 0, false];

trg setTriggerActivation ["WEST", "PRESENT", false];

trg setTriggerStatements ["this &&  !isnil 'alert' "," wp1 = grp4 addWaypoint [getMarkerPos 'marker_0', 0];  '", "'"];   // there is no need to specify MOVE,AWARE,NORMAL, that's default data.

 

in your EH:

{

  _x addEventHandler ["firedMan", { deleteWaypoint [grp4, 1];

  [grp4, getMarkerPos "marker_0"] call BIS_fnc_taskAttack;

  hintSilent "Reinforcements Inbound!";

   _x removeEventHandler ["firedMan", _thisEventHander];

  alert = true;

  }]; 

} forEach (allUnits select {side _x isEqualTo EAST});  // this EH should be run after the east units creation. You can limit it at units grp0, for example, or (units grp0 + units grp1...)

 

If there are some players (or AIs in players' groups) concerned by the EH, so EAST and not on server, then you must publicVariable "alert" . If only AIs on server are concerned, there is no need to publicVariable it as all fires on server.

I think there is no need for a 2nd trigger for detection. If Your EH fires, that means the EAST have already detected the BLUE.

Share this post


Link to post
Share on other sites

@pierremgi Thanks for your help this worked like a charm, I would like to push it a little further to include an alarm sound that loops until the reinforcements have been taken out. Here's what I have:

 

if (isServer) then {
    trg = createTrigger ["EmptyDetector", getMarkerPos "marker_0"];
    trg setTriggerArea [300, 300, 0, false];
    trg setTriggerActivation ["WEST", "PRESENT", false];
    trg setTriggerStatements ["this && !isnil 'alert'", "wp1 = grp4 addWaypoint [getMarkerPos 'marker_0', 0];", ""];

    grp0 = [getMarkerPos "marker_0", EAST, (configfile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OIA_InfAssault")] call bis_fnc_spawngroup;
    [grp0, position leader grp0, 300] call bis_fnc_taskpatrol;

    grp1 = [getMarkerPos "marker_1", EAST, (configfile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad")] call bis_fnc_spawngroup;
    [grp1, position leader grp1, 300] call bis_fnc_taskpatrol;

    grp2 = [getMarkerPos "marker_2", EAST, (configfile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OIA_InfSquad_Weapons")] call bis_fnc_spawngroup;
    [grp2, position leader grp2, 300] call bis_fnc_taskpatrol;

    grp3 = [getMarkerPos "marker_3", EAST, (configfile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam")] call bis_fnc_spawngroup;
    [grp3, position leader grp3] call bis_fnc_taskdefend;

    grp4 = [getMarkerPos "marker_4", EAST, (configfile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Mechanized" >> "OIA_MechInf_Support")] call bis_fnc_spawngroup;
    [grp4, position leader grp4] call bis_fnc_taskdefend;


    alert = false;        // Creation of the name variable "Alert" as "False" that will be used to activate the trigger when it becomes "True"

    // Command that recognizes the firing of a weapon from some AI on the side "East", then removes the handler, and turns the variable named "Alert" to true, which will trigger the trigger in the editor.
    {
        _x addEventHandler ["firedMan", {
            deleteWaypoint [grp4, 1];
            [grp4, getMarkerPos "marker_0"] call BIS_fnc_taskAttack;
            _x removeEventHandler ["firedMan", _thisEventHander];
            alert = true;
        }];
    } forEach (units grp0 + units grp1 + units grp2 + units grp3 select {side _x isEqualTo EAST});  // This EH Should be Run after the East Units Creation. You can use allUnits or limit it to units grp0, for example, or (units grp0 + units grp1...)
};

 

I came across this and I'm not sure how to implement it:

while {true} do {
    object say3D ["alarm", 300];
    sleep 2;
};

 

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

×