Jump to content
Madin

Help: trigger detect AI behaviour

Recommended Posts

Hi. Im new to Arma 3 and of course to eden. I want to do a simple script. I have one unit who is patrolling, and i want him to run to specific place, when he is in "combat" or "aware" mode (or when any unit in specific area detects enemy). I can easily make him go when he is standing still (target1 doMove position box1), but when i have waypoints, or have to detect his behaviour... i dont know how to do it. im using arma wiki https://community.bistudio.com/wiki/behaviour , but i dont know exactly how to execute it. English is not my first language, so i have hard time to understand scripting from english sites.

Thanks for any help :)

Share this post


Link to post
Share on other sites

In the units init field:

TAG_fnc_move = [this,getposatl box1] spawn { //remove getposatl box1 with the position of your choice

	params ["_unit","_position"];//declare parameters

	waitUntil {behavior _unit in ["AWARE","COMBAT"]};//wait for matching behavior

	group _unit lockWP true;//prevent waypoints from completing
	_unit domove _position;//move unit

};

Cheers

Share this post


Link to post
Share on other sites

And i deleted post...

so again. Thanks for fast reply, but im affraid it's not working for me. I think it will be easier to do with triggers. Condition - when "target1" is in behaviour AWARE/COMBAT. on active - delete all waypoints of "target1", and go (as fast as possible) to item "box1"

i try with this, but for sure i make some mistake here:

TAG_fnc_move = [this,getposatl box1] spawn {
params ["target1","box1"];
waitUntil {behaviour target1 in ["AWARE","COMBAT"]};
group target1 lockWP true;
target1 domove box1;
};

 

Share this post


Link to post
Share on other sites
7 minutes ago, Madin said:

TAG_fnc_move = [this,getposatl box1] spawn {
params ["target1","box1"];
waitUntil {behaviour General in ["AWARE","COMBAT"]};
group target1 lockWP true;
target1 domove box1;
};

 

Why? Oh why.

 

Cheers

Share this post


Link to post
Share on other sites

This is a local (in its scope) variable:

_bla

 

this is a global variable:

bla

 

the params command must be filled with local variables!! read those not helping wiki !!!

Share this post


Link to post
Share on other sites

"Local variable in general space" (google translate :p)

|#|params ["target1","box1"];

Share this post


Link to post
Share on other sites
5 minutes ago, Madin said:

"Local variable in general space" (google translate :p)

|#|params ["target1","box1"];

I dont see the point.

Share this post


Link to post
Share on other sites

i think i have it working now, thanks guys :)

TAG_fnc_move = [this,getposatl box1] spawn { 
params ["_target1","_box1"]; 
waitUntil {behaviour _target1 in ["AWARE","COMBAT"]}; 
group _target1 lockWP true;
_target1 setSpeedMode "FULL";
_target1 domove _box1;
};

But i still need to learn what does mean "local vaiable" and "global space"

  • Like 1

Share this post


Link to post
Share on other sites

You basically renamed _unit and _position from my snippet into _target1 and _box1.

Was not necessary at all, since only the parameters (this and getposatl box1) in the first line matter.

The rest does not need to be changed at all.

 

A local variable will only exist inside the scope where it's been defined.

 

_test = "Test";
hint str _test; //will display "Test"

_test = "Test";
[] call {hint str _test};//will throw an error because _test does not exist here

_test = "Test";
_test call {hint str _this};//will hint "Test"

//Now this little gem:
_test = "Test";
_success = [] call {

_noTest = "Success";
_noTest
};

hint str _test;//will hint "Test"
hint str _noTest;//will throw an error because _noTest only exists inside the call
hint str _success;//will hint "Success" because _noTest is being returned by the call and available through the _success variable

 

A global variable will exist in an entire namespace.

MyTest = "Test";
hint str MyTest; //will display "Test"

MyTest = "Test";
[] call {hint str MyTest}; //will display "Test"

 

There are different namespaces, to name the most used ones:

  • missionNamespace: variables will exist as long as the mission is running
  • UINamespace: variables will exist as long as the game is running
  • profileNamespace: variables will exist as long as the user profile exists/stays the same

 

For the snippet I posted you could put this inside the init.sqf:

TAG_fnc_move = { 

	params ["_unit","_position"];

	waitUntil {behavior _unit in ["AWARE","COMBAT"]};

	group _unit lockWP true;
	_unit domove _position;

};

This will define the function named as TAG_fnc_move, is global so you can access it anywhere, and can be used as many times on as many units as you want.

Now to make one unit run this function you put this into the units init field:

_move = [this,getposatl box1] spawn TAG_fnc_move;

Using this line in the objects init field, the first parameter "this" refers to the unit, which will be passed on to the function as first parameter.

Inside the function it will be referred to as "_unit", as defined by the params command.

Same goes for the position parameter.

 

Hope I have made things a bit more clear.

 

Cheers

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

×