Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
hectrol

A group that chases and kills all the animals that are nearby.

Recommended Posts

Hi I need a  group that chases and kills all the animals that are nearby. 

Something like that but that works:

 

  systemchat "BLU_GRUPO_CAZADOR_1";


private _radius = random 10;      
private _minDistance = 10;    

private _spawnPos = [getPos player, _radius, _radius, 0, 1, _minDistance, 0] call BIS_fnc_findSafePos;




BLU_GRUPO_CAZADOR_1  = [_spawnPos, west, ["B_Sharpshooter_F","B_Sharpshooter_F"]] call BIS_fnc_spawnGroup;





{
    _unit = _x;
	
_unit setBehaviour "AI_Default";
_unit setCombatMode "RED";
_unit setTargetType "ANY";
	

    while {true} do {
        _target = nearestObject [_unit, "All"]; 
        if (_target != objNull && alive _target) then {
            _unit setTarget _target;
            _unit moveTo _target;
        };
        sleep 1;
    };
} forEach units BLU_GRUPO_CAZADOR_1;

Thanks

Share this post


Link to post
Share on other sites

Animals in Arma?  Rabbits, snakes, butterflies...

Animals are spawned by engine in vicinity of the player, like this:

Animals:_Ambient_System

 

- You can add rabbits by editor (and only rabbits because other classes are not in public scope, they are protected)

- you can spawn some classes like found here.

- some mods add specific animals (like dromedaries by Western Sahara DLC)

 

Side: not very handy!

AMBIENT LIFE for edited rabbits (or dromedaries or else)

CIVILIAN for edited by createAgent  (read it from top to bottom!)

UNKNOWN if spawned by engine (butterflies,mosquitos... snakes, rabbits)

You can't modify the side of an animal.

 

That said, here is a little script for hunting. Place it in init field of an AI unit:
 

this spawn { 
  params ["_hunter","_animals","_targets","_target"]; 
  private _initPos = getpos _hunter;
  private _wpt = [group _hunter,0];
  _hunter setSkill 1;
  private _priority = ["Rabbit_F","Dromedary_01_lxWS"]; 
  while {sleep 2; alive _hunter} do { 
    _animals = ((allMissionObjects "Animal" select {alive _x}) apply {_an = _x;[_priority findIf { _an isKindOf _x}, _an distance2D _hunter, _an]}); 
    _targets = _animals select {_x#0 != -1}; 
    _targets sort TRUE; 
    call { 
      if (_targets isEqualTo []) exitWith {	_hunter enableAI "FIREWEAPON"}; 
      if (isNil {_hunter getVariable "target"}) exitWith {
        _target = _targets #0#2; 
        _hunter setVariable ["target",_target]; 
        _hunter doMove getPos _target;
        _hunter enableAI "FIREWEAPON";		
      }; 
      _target = _hunter getVariable ["target",objNull];
      _hunter doMove getPos _target;
      if (isNull _target or !alive _target) exitWith {
        _hunter move _initPos;  
        _hunter setVariable ["target",nil];
      }; 
      if (_hunter distance2D _target < 30) exitWith {
        doStop _hunter;
        _hunter doSuppressiveFire (_target modelToWorldWorld [0,0,0.5]);
        _hunter suppressFor 1;
        sleep 1;
        _hunter disableAI "FIREWEAPON";
        sleep 2;
        if (alive _target && !isNull _target) then {_hunter enableAI "FIREWEAPON"};
      };  
    }; 
  };
};

Where:
_priority is an array of your favorite animals (classes) sort by priority (here Western Sahara dromedaries for test, then rabbits). classes must comply with isKindOf command.

 

I'm using doSuppressiveFire command to fire on a position. Not the best. Feel free to choose something else for firing an object (civilian)

The hunter seems to shoot too many bullets, the reason why I tried to dim that by disabling /enabling its FIREWEAPON ability.

 

 

 




 

 

Edited by pierremgi
improved
  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
On 1/23/2025 at 2:15 AM, pierremgi said:

The hunter seems to shoot too many bullets, the reason why I tried to dim that by disabling /enabling its FIREWEAPON ability.

Hi Pierre!  I hope life is treating you well.

 

As always, I learn something when reading your scripts (somehow I never new about FIREWEAPON toggle).  I like the combination of doSuppressiveFire and disableAI FIREWEAPON because it guarantees AI naturally aims at position, and also limits excessive firing).  I've always used forceWeaponFire for this, but then you have to guarantee unit is aiming at correct spot first, which can be a problem sometimes.

 

I'm curious why you chose addWaypoint for moving the hunter vs. a doMove?

Share this post


Link to post
Share on other sites
10 hours ago, johnnyboy said:

I'm curious why you chose addWaypoint for moving the hunter vs. a doMove?

 

Hi johnnyboy , To say the truth, it was a quick and dirty example. I thought about addWaypoint just for updating the position by setWaypointPosition. You're right doMove is fine.

 

This script could be improved, for sure. I added a better aiming with modelToWorldworld and suppressFor (less ammo waste).

If I'd to give a move to spawned animals, I'll probably use setDestination

And the probable best use for that code needs to choose only spawned species, without rabbits in _priority variable (they spawn too often).

 

  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, pierremgi said:

 

Hi johnnyboy , To say the truth, it was a quick and dirty example. I thought about addWaypoint just for updating the position by setWaypointPosition. You're right doMove is fine.

 

This script could be improved, for sure. I added a better aiming with modelToWorldworld and suppressFor (less ammo waste).

If I'd to give a move to spawned animals, I'll probably use setDestination

And the probable best use for that code needs to choose only spawned species, without rabbits in _priority variable (they spawn too often).

 

Good points.  I may add in this hunting to my "AI React To Wildlife" script in SOG AI mod.  There would be a chance that an AI that reacts to rabbit or chicken sound (he goes to investigate sound), will decide to try and hunt it for a minute or two.   More immersive permutations for player to watch.  🙂

 

 

  • Like 2
  • Haha 1

Share this post


Link to post
Share on other sites

×