Jump to content
Sign in to follow this  
TyrDaishi

How to issue commands to unnamed units that enter a trigger

Recommended Posts

Hi,

 

I can't figure out how to keep the AI in a certain area. What I basically want to do is creating simple triggers and when any East (OpFor) unit is walking into it to send it back to a marker location or what would be even better if it would be a random spot in a fixed area.

 

I tried to create a trigger set to

 

activation opfor

repeatable

on activation something like: "this domove (getMarkerpos "wp1");"

 

So how can I tell the trigger that "this" is every unit from opfor side that walks into the triggerline?

 

Share this post


Link to post
Share on other sites

{_x doMove (getMarkerPos "wp1")} forEach thisList;

 

Being activated by OpFor, any OpFor in that trigger will be part of thisList. So all you need to do is use it with a forEach loop to make sure, and that should work. Why are they straying out of the area though?

 

https://community.bistudio.com/wiki/2D_Editor:_Triggers - Search down the page for thisList

Share this post


Link to post
Share on other sites

First off, thanks for the help, I really appreciate it.

 

Why are they straying out of the area though?

 

 

They seem to leave the area sometimes due to commands issued by the vcom ai script. As much as I like the script it shows unexpected behavior sometimes.

 

[edit] so how does the game know that _x is a substitute for every unit? :o Still having troubles understanding the whole scripting stuff. I get that foreach means that every element from thislist right? so how is_x the representing the current unit in the trigger?

Share this post


Link to post
Share on other sites

in the Vcom AI topic. 

 

IMPORTANT EDITING COMMANDS

this setVariable ["NOAI",1,false]; - This will turn off the VCOM AI on the given unit

 

This will make the AI not execute extra waypoint behavior OR respond to calls for help

this setVariable ["VCOM_NOPATHING_Unit",1,false];

Share this post


Link to post
Share on other sites

One of the many problems with undocumented AI platforms...

Try T8's AI script. Very nicely done, although some of the dynamic code, could present possible issues.

Share this post


Link to post
Share on other sites

so how is_x the representing the current unit in the trigger?

Using forEach with an array will execute all the code on everything in the array. Each element in the array will then be represented in place of _x when it is executed for it.

{_x setDamage 1} forEach [_unit1,_unit2];

The above does this:

_unit1 setDamage 1;

_unit2 setDamage 1;

https://community.bistudio.com/wiki/forEach

  • Like 1

Share this post


Link to post
Share on other sites

{_x doMove (getMarkerPos "wp1")} forEach thisList;

 

Being activated by OpFor, any OpFor in that trigger will be part of thisList. So all you need to do is use it with a forEach loop to make sure, and that should work. Why are they straying out of the area though?

 

https://community.bistudio.com/wiki/2D_Editor:_Triggers - Search down the page for thisList

 

This worked very well, thanks!

 

I would like to ask another question, I found a counter to show how many enemies are left in an area, and changed it so it can be used in mp as well. The code is added to the init.sqf. It is working in general but my problem is that deaths of independent units (player faction) will be counted as well. I tried to select only faction EAST units but it didn't work:

//ENEMY COUNTER
enmc = {(alive _x) && (side _x == EAST)} count allUnits; 
{_x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then {[(format ["Enemy remaining: %1",enmc ]), "hintsilent", true, true] call BIS_fnc_MP;} else {(_this select 0) cameraEffect ["Fixedwithzoom","top"]}; _mrk = createMarkerLocal [format["%1", enmc], getpos (_this select 0)]; format["%1", enmc] setMarkerTypeLocal "Empty"; "_mrk" setMarkerColorLocal "ColorRed"}]} foreach allunits;
sleep 0.5;
player removeAllEventHandlers "killed";
titletext ["KILL 'EM ALL","plain"];
titleFadeOut 2;
sleep 2;

[(format ["Enemy remaining: %1",enmc]), "hintsilent", true, true] call BIS_fnc_MP;

waitUntil {enmc == 0};
sleep 3;
cuttext ["All enemy has been eliminated.","plain down"];
sleep 3;
titletext ["MISSION COMPLETED","plain",0.4];
cuttext ["","black out"];
sleep 4;
endMission "END1";

Share this post


Link to post
Share on other sites

You're adding the killed event-handler to all units when you should just add it to the enemy units.

Share this post


Link to post
Share on other sites

You're adding the killed event-handler to all units when you should just add it to the enemy units.

 

That is actually what I thought as well but since

enmc = {(alive _x) && (side _x == EAST)} count allUnits; 

checks for all alive enemy units I tried to substitute "_x" with "enmc" but that didn't work. probably because it returns a number not the array with all units? I don't know how to get that content though.

 

Do you think I could check if the faction is east only for the eventhandler like this?

{
	if ((side _x) == East) then
	{
		{_x addEventHandler ["killed", {enmc = enmc -1; if (enmc != 0) then {[(format ["Enemy remaining: %1",enmc ]), "hintsilent", true, true] call BIS_fnc_MP;} else {(_this select 0) cameraEffect ["Fixedwithzoom","top"]}; _mrk = createMarkerLocal [format["%1", enmc], getpos (_this select 0)]; format["%1", enmc] setMarkerTypeLocal "Empty"; "_mrk" setMarkerColorLocal "ColorRed"}]} foreach allunits;
	};
} forEach allUnits;

Share this post


Link to post
Share on other sites

You have messed up code where some of lines should be run on server and some on every player.

 

server part:

if (isServer) then {
//ENEMY COUNTER
private "_eastUnits";
    
    _eastUnits = [];
    {
    
        if (alive _x && side _x == EAST) then {
        
        _eastUnits pushback _x;
        
        };
        
    }forEach allunits;
    
    enmc = count _eastUnits;

    {
        _x addEventHandler ["killed", {

        enmc = enmc -1;
        if (enmc != 0) then {
        
            [(format ["Enemy remaining: %1",enmc ]), "hintsilent", true, true] call BIS_fnc_MP;
            
        } else {

            private "_mrk";
            (_this select 0) cameraEffect ["Fixedwithzoom","top"]}; //what should that line do on killed EAST unit? Has the EAST unit any interface?
            _mrk = createMarkerLocal [format["%1", enmc], getpos (_this select 0)];
            format["%1", enmc] setMarkerTypeLocal "Empty";
            "_mrk" setMarkerColorLocal "ColorRed";
        }];
    } foreach _eastUnits;

    [] spawn {

        [(format ["Enemy remaining: %1",enmc]), "hintsilent", true, true] call BIS_fnc_MP;
        waitUntil {sleep 10; enmc == 0};
        ["end1","BIS_fnc_endMission",true,false,true] call BIS_fnc_MP;
    };
};

players part:

        sleep 0.5
        titletext ["KILL 'EM ALL","plain"];
        titleFadeOut 2;
        sleep 2;
        cuttext ["All enemy has been eliminated.","plain down"];
        sleep 3;
        titletext ["MISSION COMPLETED","plain",0.4];
        cuttext ["","black out"];
        sleep 4;

You should public variable enmc and some how align in time execution of each part,

or use  remoteExec or BIS_fnc_MP on the players part and than run everything server side only

Share this post


Link to post
Share on other sites

I have to admit I'm even more confused now and just to be sure this won't help with my problem regarding the killcount not being only for the east faction, or I don't see how :o

Share this post


Link to post
Share on other sites

Sorry i miss that you have set foreach for allunits. Bad. Post updated!

Share this post


Link to post
Share on other sites

Thank you very much. It would have taken me weeks until I would have found a working solution on my own. I will try to understand what you did and hopefully I can release some more complex scenarios in the future with what I learned so far and will learn. Arma keeps me more motivated to finally learn more about scripting / programming then any other method I tried :)

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  

×