Jump to content

Recommended Posts

Hi All,

 

having a little problem ;

 

When I use the following piece of code, the script works (Arma 3 Animals: Override Default Animal Behaviour Via Script).

Here the working code :

_Master = _this select 0;
_DogAgent = createAgent ["Alsatian_Sand_F", (getPos _Master), [], 5, "CAN_COLLIDE"];
_DogAgent setVariable ["BIS_fnc_animalBehaviour_disable", true];

_DogAgent playMoveNow "Dog_Sprint";

while {alive _DogAgent} do
{
	_DogAgent moveTo (getpos _Master);
};

 

When I perfect this script, the dog no longer follows me and walks in a straight line to infinity.

Here my reworked code :

_Master = _this select 0;
_DogAgent = createAgent ["Alsatian_Sand_F", (getPos _Master), [], 5, "CAN_COLLIDE"];
_DogAgent setVariable ["BIS_fnc_animalBehaviour_disable", true];

while {alive _DogAgent} do
{
	if ((_DogAgent distance2D player) > 12) then
	{
		sleep 0.01;
		_DogAgent playMoveNow "Dog_Sprint";
		sleep 0.01;
		hintSilent "SPRINT";
	};

	if (((_DogAgent distance2D player) > 6) && ((_DogAgent distance2D player) < 12)) then
	{
		sleep 0.01;
		_DogAgent playMoveNow "Dog_Run";
		sleep 0.01;
		hintSilent "RUN";
	};

	if (((_DogAgent distance2D player) > 2) && ((_DogAgent distance2D player) < 6)) then
	{
		sleep 0.01;
		_DogAgent playMoveNow "Dog_Walk";
		sleep 0.01;
		hintSilent "WALK";
	};

	if ((_DogAgent distance2D player) < 2) then
	{
		sleep 0.01;
		_DogAgent playMoveNow "Dog_Sit";
		sleep 0.01;
		hintSilent "SIT";
	};
	sleep 0.01;
	_DogAgent moveTo getPos player;
};

 

I want the dog to follow me, sprint when I'm away from him, walk when I'm near him, and sit down when he is very close to me.

If someone found a solution I'm interested !

 

Bye

Share this post


Link to post
Share on other sites

Hi Cheyenne.  You can try my dog command scripts if you like:  JBOY Dog.

 

I think your simple script above will work better with a  sleep time of 1 second.  Sleeping .01 means you are stacking 100s of run animations so dog "runs to infinity" as you say.  Also, you only want to playmove an animation once, until you want to playmove the next different animation.  Only execute a playMove if you want to change the current animation being executed, like this:

if !(_last_anim == "Dog_Run") then 
{
	_dog playMove "Dog_Run"; 
	_last_anim = "Dog_Run";
};

At top of your loop set _last_anim to "", then replace your playMove line with code like I posted above, so when the condition is true, the particular animation only runs once.  So in your script, replace every playMove line with my suggested If statement (but modify the Animation names for each condition...run/walk/sprint/sit).

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks a lot johnnyboy ! That work ! 

I really did not think about that! Like what sometimes we look far what is logical.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Johnnyboy; small questions :

I developed the script and it works well, but I have two small problems !

 

  • the first is that the dog, who is an agent, is not subject to collisions and literally crosses objects (houses, walls, etc.);
  • the second is that although I can define a destination, the dog constantly changes direction between the starting point and the destination position, sometimes it goes to the opposite for a hundred meters before returning on the destination position randomly. I tried to use unitName disableai "PATH" when the dog faces the destination position, using BIS_fnc_inAngleSector, but it does not change much to the deal.

 

Do you have a solution ?

Here is my script / Try it ; call this script with player and put an injured civilian near him

 

Alpha script

_Master = _this select 0;
_DogAgent = createAgent ["Alsatian_SandBlack_F", (_Master getRelPos [1, (getDir _Master) + 35]), [], 5, "NONE"];
_DogAgent setVariable ["BIS_fnc_animalBehaviour_disable", true];
sleep 0.01;
_DogAgent playMoveNow "Dog_Sit";

_DogArrow = "Sign_Arrow_Large_F" createVehicle position _DogAgent;
_DogArrow attachTo [_DogAgent,[0,0,7]];
_DogArrow2 = "Sign_Arrow_Large_F" createVehicle position _DogAgent;
_DogArrow2 attachTo [_DogAgent,[0,0,14]];
_DogArrow3 = "Sign_Arrow_Large_F" createVehicle position _DogAgent;
_DogArrow3 attachTo [_DogAgent,[0,0,21]];

_markerstr0 = createMarker ["Mk_victim", [0,0,0]];
_markerstr0 setMarkerShape "ELLIPSE";
_markerstr0 setMarkerSize [5,5];
_markerstr0 setMarkerColor "ColorRed";

_markerstr1 = createMarker ["Mk_Dog", [0,0,0]];
_markerstr1 setMarkerShape "ELLIPSE";
_markerstr1 setMarkerSize [3,3];
_markerstr1 setMarkerColor "ColorBlue";

_markerstr2 = createMarker ["Mk_Dog_expt", [0,0,0]];
_markerstr2 setMarkerShape "ELLIPSE";
_markerstr2 setMarkerSize [5,5];
_markerstr2 setMarkerColor "ColorGreen";

{_DogAgent enableCollisionWith _x} forEach (nearestTerrainObjects [_DogAgent, [],200]); //does not work

sleep 2.00;

while {alive _DogAgent} do
{
	sleep 0.01;
	_entts = _DogAgent nearEntities ["Man", 50];
	_vctmList = [];
	sleep 0.10;
	{if ((getDammage _x) > 0.1) then {_vctmList pushback _x;}} forEach _entts;

	sleep 1.00;

	if ((count _vctmList) < 1) then
	{
		if ((_DogAgent distance2D _Master) > 10) then
		{
			sleep 0.01;
			_DogAgent playMoveNow "Dog_Run";
		};

		if (((_DogAgent distance2D _Master) > 5) && ((_DogAgent distance2D _Master) < 10)) then
		{
			sleep 0.01;
			_DogAgent playMoveNow "Dog_Walk";
		};

		if ((_DogAgent distance2D _Master) < 5) then
		{
			sleep 0.01;
			_DogAgent playMoveNow "Dog_Sit";
		};

		if ([position _DogAgent, getDir _DogAgent, 30, position _Master] call BIS_fnc_inAngleSector) then
		 {
		 	_DogAgent disableai "PATH";
		 }
		 else
		 {
		 	_DogAgent enableai "PATH";
		 };

		sleep 0.01;
		_DogAgent moveTo (getPos _Master);
	}
	else
	{
		if ((_DogAgent distance2D (_vctmList select 0)) > 10) then
		{
			sleep 0.01;
			_DogAgent playMoveNow "Dog_Run";
		};

		if (((_DogAgent distance2D (_vctmList select 0)) > 5) && ((_DogAgent distance2D (_vctmList select 0)) < 10)) then
		{
			sleep 0.01;
			_DogAgent playMoveNow "Dog_Walk";
		};

		if (((_DogAgent distance2D (_vctmList select 0)) < 5)) then
		{
			sleep 0.01;
			_DogAgent playMoveNow "Dog_Idle_09";
			_DogAgent playMove "Dog_Idle_Bark";
		};

		if ([position _DogAgent, getDir _DogAgent, 30, position (_vctmList select 0)] call BIS_fnc_inAngleSector) then
		 {
		 	_DogAgent disableai "PATH";
		 }
		 else
		 {
		 	_DogAgent enableai "PATH";
		 };

		sleep 0.01;
		_DogAgent moveTo (markerPos "Mk_victim");

		sleep 0.01;
		"Mk_victim" setMarkerPos (getPos (_vctmList select 0)); //victim position

		sleep 0.01;
		"Mk_Dog" setMarkerPos (getPos _DogAgent); //dog position

		sleep 0.01;
		_Expt = expectedDestination _DogAgent; //dog expected destination
		"Mk_Dog_expt" setMarkerPos (_Expt select 0);

		sleep 0.01;
		hintSilent parsetext format ["<t align='left' color='#028ee0'>%4</t><t align='left'> victim(s) found</t><br/><t align='left' color='#ff7200'>%1</t><br/><t align='left'>victim is injured at</t><t align='left' color='#028ee0'> %2</t><t align='left'>%3</t><br/><br/><t align='left'>Dog agent </t><t align='left' color='#e00034'>%6</t><t align='left'>m to victim</t><br/><br/><t align='left' color='#00e003'>%7</t><br/><br/><t align='left'>Dog face victim? (+/-30°) </t><t align='left' color='#fa00ff'>%8</t>", name (_vctmList select 0), round (100-(getDammage (_vctmList select 0))*100), "%", count _vctmList, round (100-(getDammage (_DogAgent))*100), round(_DogAgent distance2D (_vctmList select 0)), _Expt, [position _DogAgent, getDir _DogAgent, 30, position (_vctmList select 0)] call BIS_fnc_inAngleSector];
	};
};

Service-Dogs-Ww1-World-War-One-German-Sh

Share this post


Link to post
Share on other sites
21 hours ago, CheyenneAH56 said:

but I have two small problems !

 

  • the first is that the dog, who is an agent, is not subject to collisions and literally crosses objects (houses, walls, etc.);
  • the second is that although I can define a destination, the dog constantly changes direction between the starting point and the destination position, sometimes it goes to the opposite for a hundred meters before returning on the destination position randomly. I tried to use unitName disableai "PATH" when the dog faces the destination position, using BIS_fnc_inAngleSector, but it does not change much to the deal.

Hi Cheyenne.  Regarding dog collision, that is a problem I do not know how to solve.  My dogs have the exact same problem.  When making missions using the dogs, I try to pick locations where there are few buildings or walls.

 

Regarding dog running many meters away from destination try this:

  • sleep .3 seconds instead of .1 seconds
  • Change all your playMoves to not execute on every loop iteration (as I explained on previous post).   I think dog is overshooting position because it is executing a series of stacked playmoves.

Here's some code from my JBOY_dogCommand script.  This script is a constantly running loop to process different commands/actions for a dog (sit, heel/follow/, move to a position, attack, etc.).  In the Attack section of that code, I have the while loop below that controls how dog chases a victim to attack.  Download my demo mission from JBOY Dog thread to see more details.

 

In the code below, there is a lot of stuff you don't need (like the while conditions), but you should see the stuff you do need.  You probably want the while condition to simply end when dog is near target.

		// Use _last_anim variable to guarantee you do not playmove the same move that is already running.
		// Any time you want to play a different animation, you must also set the _last_anim variable to the new animation being played
		if !(_last_anim == "Dog_Sprint") then {_dog playMove "Dog_Sprint"; _last_anim = "Dog_Sprint";};

		// This loop makes dog chase target unit
		_jj = 0;
		while {( (alive _dog) and !isNull _targetObj
                and (alive _handler or isNull _handler) 
                and ( ((_targetObj distance _dog) > 4 and alive _targetObj AND !isNull _targetObj) 
                        or ((_targetObj distance _dog) >2 and (!(alive _targetObj) or (typeOf _targetObj!="Man")) and isNull(_dog getVariable "vPack")) 
                    )
                and ((_dog getVariable "vCommand") == "attack" ) )} do
        {
            _jj = _jj + 1;
            // *********************************************
            // bark while chasing
            // *********************************************
            if ( (_jj mod 9)==0 and (random 100) > 30 and !(({_x isKindOf "Animal"} count attachedObjects _dog) > 0) ) then // if no prey in mouth, then bark & growl
            {
                _sfx = (["barkmean2","barkmean1","barkmean3","growls3","bark2","bark1"] call BIS_fnc_arrayShuffle) select 0;
                dummy= [_dog, 0, _sfx,""] execVM "JBOY_Dog\delaySay.sqf";
            };
            
            // *********************************************
            // Keep moving to target pos, and check for change of target
            // *********************************************
            if (typeName (_dog getVariable "vTarget")=='STRING') then
            {
                _targetObj = objNull;
            } else
            {
                _targetObj = (_dog getVariable "vTarget");
                if (speed _targetObj < 1) then
                {
                    _moveToPos = getposatl _targetObj;
                } else
                {
                    _moveToPos = _targetObj modelToWorld [0, 0, 1.5];
                };
                _dog doWatch  (_targetObj modelToWorld [0, 0, 1]);
                //sleep .1;
                _surfaceNormal = surfaceNormal getposatl _dog;            
                _dog setVectorUp _surfaceNormal;  

                _dog moveTo _moveToPos;        
            };
            sleep .3;                
        };

 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks a lot for your help.

 

I'll try to modify some parameter and use your method to change anim.

I thought that PlayAnimNow was enouth (not PlayAnim).

 

;D See Ya !

  • Like 1

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

×