Jump to content
Sign in to follow this  
wiggum2

HunterKiller Patrol - A script for aggressive and smart patrols

Recommended Posts

Hi !

I know that there are tons of patrol scripts around, but i always wanted more aggressive and smarter patrols without the need of a massive script package that adds other stuff i (and maybe you) dont want or need.

This script gives the patroling groups the ability to share informations in a given perimeter. If a enemy is spotted and other groups are in range, they will stop their current patrol and also hunt down the enemy.

After the enemy is dead, they will return to their original patrol position and start again to patrol there.

With the normal (simple) patrol scripts or the BIS fnc taskpatrol, the patroling groups dont react believably. Although gunshots can be heard at their current position they just keep patroling.

Now with this script they will stop the patrol, start to hunt & kill the enemys they know about and later return to their patrol position.

I also added the option to give the patroling group flares which they will use (actually the flares will just spawn) if a enemy is close to them.

This script was only tested in SP (although it should work in MP too) and only with infantry vs. infantry.

CBA is needed because the script uses the great CBA_fnc_taskPatrol.

Everyone can change and improve this script, as long as you share it here with us... ;)

An example:

unbenanntio4l.jpg

1, 2 and 3 are groups patroling with this script, the big circles are their "communication range". The green circles are the areas they patrol.

4 is a enemy group spottted by 2. As you can see 3 is inside the "communication range" of 2 and the enemys are close enough ("engagement range" is the same as "communication range"). 3 will start to engage (5) the enemy 4.

As you can see 1 will just keep patroling because they are not in "communication range".

The small green circles are _areasize around _patrolpos

The big circles are _areasize * _multi around groupleader of _grphunter

If you spot a error or know what i could have done better, please tell me about it !

Known Bugs:

  • For some reason, if the patrolleader has a pistol he will sometimes change to that after the targets are eliminated and dont move again. If he dont had a pistol that behaviour never occurred.

Readme part of the script:

// HunterKiller_Patrol.sqf

// Script File for ArmA2 with CBA

// Made by: Wiggum

// Version: 1.0

// ********************************************

// Enemy groups will patrol a specific area and inform each other inside a specific distance about spotted enemys

// If enemys are spotted the groups will start to hunt them

// A patroling group will reveal all spotted enemys closer then areasize (based on their current position) to all other units of the same side closer then areasize * multi (based on their current position)

// A patroling group will only hunt enemys closer then areasize * multi (based on their current position)

// If you want a patrol to stay close to a specific position, dont give them a high multi !

// The groups will return to their patrolpos after the enemy is dead and start again to patrol there

// ********************************************

// Call from a trigger with condition "true" for each patrol group with:

// nul=[grphunter, patrolpos, areasize, multi, targetside, "typeofhunter", "typeoftarget", flarecount] execVM "HunterKiller_Patrol.sqf"; (dont forget the quotation marks at "typeofhunter", "typeoftarget" !)

// ********************************************

// grphunter is the name of the patroling group

// patrolpos is the centre of the patrol, just place a empty H and give it a name

// areasize is the size of the area around the patrolpos in which the group will patrol

// multi is the multiplicator (of areasize) for the distance around the groupleader in which informations will be shared and received among the patrols. This also is the max. engagement range of the group !

// targetside is the side (west, east, resistance) of the possible targets of the patroling group

// typeofhunter is the type (take a look at CfgVehicles) of the patroling units (SoldierEB for all east units for example, can be different for some addons)

// typeoftarget is the type (take a look at CfgVehicles) of the possible targets (SoldierWB for all west units for example, can be different for some addons)

// flarecount is the number of flares the patroling group has, they will use them if a enemy is close enough (100m). Just give them 0 if you dont want that they use them. Flares will be spawned, no need for special weapons !

-- There will be a new version very soon --

HunterKiller_Patrol.sqf:



// ********************************************
// HunterKiller_Patrol.sqf
// Script File for ArmA2 with CBA
// Made by: Wiggum
// Version: 1.0
// ********************************************
// Enemy groups will patrol a specific area and inform each other inside a specific distance about spotted enemys
// If enemys are spotted the groups will start to hunt them
// A patroling group will reveal all spotted enemys closer then areasize (based on their current position) to all other units of the same side closer then  areasize * multi (based on their current position)
// A patroling group will only hunt enemys closer then areasize * multi (based on their current position)
// If you want a patrol to stay close to a specific position, dont give them a high multi !
// The groups will return to their patrolpos after the enemy is dead and start again to patrol there
// ********************************************
// Call from a trigger with condition "true" for each patrol group with:
// nul=[grphunter, patrolpos, areasize, multi, targetside, "typeofhunter", "typeoftarget", flarecount] execVM "HunterKiller_Patrol.sqf"; (dont forget the quotation marks at "typeofhunter", "typeoftarget" !)
// ********************************************
// grphunter is the name of the patroling group
// patrolpos is the centre of the patrol, just place a empty H and give it a name
// areasize is the size of the area around the patrolpos in which the group will patrol
// multi is the multiplicator (of areasize) for the distance around the groupleader in which informations will be shared and received among the patrols. This also is the max. engagement range of the group !
// targetside is the side (west, east, resistance) of the possible targets of the patroling group
// typeofhunter is the type (take a look at CfgVehicles) of the patroling units (SoldierEB for all east units for example, can be different for some addons)
// typeoftarget is the type (take a look at CfgVehicles) of the possible targets (SoldierWB for all west units for example, can be different for some addons)
// flarecount is the number of flares the patroling group has, they will use them if a enemy is close enough (100m). Just give them 0 if you dont want that they use them. Flares will be spawned, no need for special weapons !
// ********************************************

if (!isServer) exitwith {};

private ["_grptargets","_grphunter","_areasize","_grpToHunt","_temp","_behaviour","_mode","_speed","_formation","_patrol","_targetside","_patrolpos","_ReadyToHunt","_HuntingDone","_multi","_typeofhunter","_typeoftarget","_hunterType","_targetType","_flare","_flarecount","_delay","_ammo","_dist","_dir","_height"];

_grphunter = _this select 0;
_patrolpos = _this select 1;
_areasize = _this select 2;
_multi = _this select 3;
_targetside = _this select 4;
_typeofhunter = _this select 5;
_typeoftarget = _this select 6;
_flarecount = _this select 7;

// Detection stuff and Variables
_grptargets =[];
_grpToHunt = nil;
_flare = nil;
_ReadyToHunt = 0;
_HuntingDone = 0;

// Behaviour of the group while hunting
_formation = ["WEDGE", "ECH LEFT", "ECH RIGHT", "VEE", "DIAMOND"] call BIS_fnc_selectRandom;
_speed = ["NORMAL", "FULL"] call BIS_fnc_selectRandom;
_behaviour = ["AWARE", "COMBAT"] call BIS_fnc_selectRandom;
_mode = ["YELLOW", "RED"] call BIS_fnc_selectRandom;

// Flare ammo, delay and offset from shooter
_ammo = ["F_40mm_White", "F_40mm_Red"] call BIS_fnc_selectRandom;
_delay = 5 + random 3;
_dist = 15 + random 15;
_dir = random 360;
_height = 200 + random 25;

// Begin the patrol
_patrol = [_grphunter, _patrolpos, _areasize, 7, "MOVE", "SAFE", "YELLOW", "LIMITED", "STAG COLUMN", "", [2,5,10]] call CBA_fnc_taskPatrol;
//hint "Patroling";

// Start of loop
while {({alive _x} count units _grphunter > 0)} do {

// Update position
_hunterType = nearestobjects [leader _grphunter,[_typeofhunter],(_areasize * _multi)];
_targetType = nearestobjects [leader _grphunter,[_typeoftarget],(_areasize)];

//Share current informations with other groups
{ 
_temp = _x;
{_temp reveal _x}  foreach _targetType;
} foreach _hunterType;
sleep 1;

// Add all units of side _targetside that are inside _areasize to array _grptargets
{if ((count units _x>0 and side _x==_targetside) && ((leader _grphunter) knowsAbout (leader _x) >= 1.3) && ((leader _x) distance (leader _grphunter) <= (_areasize * _multi)) && (_ReadyToHunt == 0))  then {_grptargets=_grptargets+[_x]}} forEach allGroups;
sleep 1; 

// Choose the closest and set that group as possible _grpToHunt
if ((count _grptargets > 0) && (_ReadyToHunt == 0)) then { 
_grpToHunt = [_grptargets, leader _grphunter] call BIS_fnc_nearestPosition;
sleep 1;
};

// First check if there is any target
if !(isNil "_grpToHunt") then {
// If _grphunter knows about _grpToHunt and is in range then stop patrol and get ready to hunt them
if (((leader _grphunter) knowsAbout (leader _grpToHunt) >= 1.3) && ((leader _grphunter) distance (leader _grpToHunt) <= (_areasize * _multi)) && (_ReadyToHunt == 0) && ({alive _x} count units _grpToHunt > 0)) then {
terminate _patrol;
sleep 1;
while {(count (waypoints _grphunter)) > 0} do {
{
deleteWaypoint [_grphunter, 0];
[_grphunter, 0] setWPPos getpos leader _grphunter; 
} foreach  units _grphunter;
};
sleep 1;
{_x setBehaviour _behaviour; _x setCombatMode _mode; _x setSpeedMode _speed; _x setFormation _formation} foreach units _grphunter;
_ReadyToHunt = 1;
//hint "Ready for hunting";
sleep 1;
};
};

//Share current informations with other groups
{ 
_temp = _x;
{_temp reveal _x}  foreach _targetType;
} foreach _hunterType;
sleep 1;

// Hunting !
if (({alive _x} count units _grpToHunt > 0) && (_ReadyToHunt == 1)) then {
_grphunter move getPos (leader _grpToHunt);
//hint "Hunting Those Basterds !";
_HuntingDone = 1;
sleep 20;
};

// If _grphunter has flares and is close to _grpToHunt then shoot flare
if ((_flarecount > 0) && ((leader _grphunter) distance (leader _grpToHunt) <= 100) && ({alive _x} count units _grphunter > 0) && (_ReadyToHunt == 1)) then {   
//hint "Shooting flare";
sleep _delay;
if ({alive _x} count units _grphunter > 0) then {
_flare = _ammo createVehicle [(getPosASL (leader _grphunter) select 0) + (sin _dir) * _dist, (getPosASL (leader _grphunter) select 1) + (cos _dir) * _dist, _height];
// Playing a flaregun sound, change to a own custom sound if you like
// (leader _grphunter) say ["flaregun",5];
_flarecount = _flarecount - 1;
_delay = _delay + random 5;
};
};

// Start to patrol again
if (({alive _x} count units _grpToHunt == 0) && (_HuntingDone == 1))  then {
_HuntingDone = 0;
_ReadyToHunt = 0;
sleep 10;
_patrol = [_grphunter, _patrolpos, _areasize, 7, "MOVE", "SAFE", "RED", "LIMITED", "STAG COLUMN", "", [2,5,10]] call CBA_fnc_taskPatrol;
//hint "Patroling again";
sleep 10;
};

// End of Loop
};

Thanks to all who helped me with this script !

Edited by Wiggum

Share this post


Link to post
Share on other sites

Awesome script! Going to test this with MP and see its compatibility!

Thanks for the script!

-Bigshot

Share this post


Link to post
Share on other sites

Congratulations.. guess i will test it.

You should make a note that the Functions Module is also needed.. ;)

And one question:

The _formation-part works on Dedicated Server?

:rolleyes:

Share this post


Link to post
Share on other sites

And as i said, i only tested it in SP so i cant tell you if it will work on a Dedicated Server.

Edited by Wiggum

Share this post


Link to post
Share on other sites

Hey mate, mind making an example to how things work etc,.. not all of us are familiar with scripting and using the editor ;) Thanks for release anyways :)

Share this post


Link to post
Share on other sites

Where is the download link for this script? For example Upsmons has a folder along with script you have to put in the missions folder area..thanks

Share this post


Link to post
Share on other sites

@ DarkXess

As i said, i will make a demo mission if someone needs one.

And now that you have asked i will make one, should be ready soon. :)

@ bravo409

There is no download link.

I dont like the concept of making downloads even for simple scripts (UPSMON is another story). You will find the whole script and every info needed to get it running in the first post.

@ All

Anyone already tried it in MP (maybe Dedicated sever too) ?

Share this post


Link to post
Share on other sites
Oh yes, thanks...Function Modul is needed.

You don't need to place the functions module when you use CBA, all functions, including BIS functions, are already in place before the first init runs (and thus can also be used in editor init lines).

Xeno

Share this post


Link to post
Share on other sites

@ Xeno

So i dont have to place anything (Function Module / Or CBA Logic) in oder to get BIS Functions work while using the CBA Mod ?

Great !

Share this post


Link to post
Share on other sites

thank for your script :)

It's working with Function module , and not working without the function module placed.

Here an example

http://www.multiupload.com/0F9ZGCW55H

two notes/suggestions :

- tested by night I didn't see flares, may be ennemies are too far (activation range is 100m, may be better to increase range ?)

- the second group react well but there are set combat red, and some elements like machinegunner engage from too far, the group is toooo slow to join the combat zone.

Edited by panda123

Share this post


Link to post
Share on other sites

So i dont have to place anything (Function Module / Or CBA Logic) in oder to get BIS Functions work while using the CBA Mod ?

Right, they are always compiled when you add CBA to your mod line, no need to place the functions module (and the functions are cached in uiNamespace to prevent compiling them again when you start a new mission or hit the preview button in the editor, caching is available in the upcoming CBA version or the current ACE CBA version).

Contrary to the BIS modules the CBA logic/module is only there to prevent starting such a mission when you don't have CBA included in your mod line (it adds an extra entry to mission.sqm).

And to make some more promo (again) for CBA :)... You can use XEH in a mission too by including XEH events in description.ext, like for example this:

http://dev-heaven.net/issues/25109#note-6

Xeno

Share this post


Link to post
Share on other sites

@ panda123

Really, it does not work without the functions module ?

Xeno, now im puzzled... :D

About the Flares:

Sure that you gave them some ?

And of course, just increase the activation range if you think thats better for your mission. It really depends on the specific map and overall situation.

About Combat Mode:

If you think they are to slow (careful) then just delete the "RED" and "COMBAT" part, make it "YELLOW" and "AWARE" only.

I just wanted some random stuff and not every group should run straight to the spotted enemy. But you could make 2 versions of the script. One for groups which should react fast and one for the other with random behaviour.

Share this post


Link to post
Share on other sites

If you use CBA then you don't have to put the functions module in the mission because that module is automatically loaded by CBA. If you don't use CBA then you have to put the functions module in.

If your mission don't care whether CBA is used or not then you should insert the module in the mission so it would work even if CBA is not being used.

Share this post


Link to post
Share on other sites

Ok...

Now, i thought that because this script needs the CBA Mod (call CBA_fnc_taskPatrol) anyway, a function module on the map is not needed.

So if the script worked for panda123 he should have CBA activated and should not need a Functions module, but as he said he needed it to get the script working.

Anyway, im puzzled.

Share this post


Link to post
Share on other sites

My mistake sorry. It was morning didn't wake up well sorry. Forget my last post.

No need function module as said Xeno (I am sure he laughed at me :) )

The thing I wanted to say that the second group don't come fast to the combat zone. Is there a way to make them come faster ?

Did someone make the ai shoot flares (at least one small flare) ?

I changed 100m for 300m. Ennemies were 250m from patrol, and no flares :(

Sorry again for my mistake :)

Share this post


Link to post
Share on other sites

@ panda123

I will quote myselfe on that one:

About Combat Mode:

If you think they are to slow (careful) then just delete the "RED" and "COMBAT" part, make it "YELLOW" and "AWARE" only.

I just wanted some random stuff and not every group should run straight to the spotted enemy. But you could make 2 versions of the script. One for groups which should react fast and one for the other with random behaviour.

Do they even have flares ?

nul=[grphunter, patrolpos, areasize, multi, targetside, typeofhunter, typeoftarget, flarecount] execVM "HunterKiller_Patrol.sqf";

You need to give them at least 1 here.

Share this post


Link to post
Share on other sites

Do they even have flares ?

nul=[grphunter, patrolpos, areasize, multi, targetside, typeofhunter, typeoftarget, flarecount] execVM "HunterKiller_Patrol.sqf";

You need to give them at least 1 here.

As you can see in my test mission I give them 10 :)

Share this post


Link to post
Share on other sites

Sorry im unable to download your test mission.

Please tell me how you actually call the script.

Like this:

(nul=[grphunter, patrolpos, areasize, multi, targetside, typeofhunter, typeoftarget, flarecount] execVM "HunterKiller_Patrol.sqf")

Thats the flare part of the script:

if ((_flarecount > 0) && ((leader _grphunter) distance (leader _grpToHunt) <= 100) && ({alive _x} count units _grphunter > 0) && (_ReadyToHunt == 1)) then { 

So if _flarecount > 0

And distance between leader _grphunter and leader _grpToHunt <= x (you have 300)

And someone of _grphunter is still alive

And _ReadyToHunt is true (the group is actually hunting the enemy)

...they should use the flares.

I think there is a issue with _ReadyToHunt = true.

Its night and enemy spotting is kind of bad but _ReadyToHunt can only be true if (leader _grphunter) knowsAbout (leader _grpToHunt) >= 1.3

Try to lower this to >= 1.0 for example and tell me if it works !

Edited by Wiggum

Share this post


Link to post
Share on other sites

Anyone already tried it in MP ?

Dedicated servers anyone ?

Would really like to know about that.

I just discovered this command:

if (isDedicated) then {

Would that make the script working on dedicated servers too ?

Or are there any other problems with the script that would prevent it from running on a dedicated server ?

Edited by Wiggum

Share this post


Link to post
Share on other sites
No problems on dedi... ;)

Really, you tried the version posted on the first page without any modifications and it works in MP (Dedicated server) ? :eek:

Nice...

Share this post


Link to post
Share on other sites

Dunno if these are fixed already - I've used the demo by panda123 posted above.

Error in expression <unt (waypoints _grphunter)) > 0} do {
{
deleteWaypoint [_grphunter, 0];
[_grphun>
 Error position: <deleteWaypoint [_grphunter, 0];
[_grphun>
 Error Type Object, expected Group
File c:\arma2\users\test\missions\HunterKiller_Patrol.Desert_E\HunterKiller_Patrol.sqf, line 97

Error in expression <ypoint [_grphunter, 0];
[_grphunter, 0] setWPPos getpos leader _grphunter;
} fo>
 Error position: <setWPPos getpos leader _grphunter;
} fo>
 Error Type Object, expected Group
File c:\arma2\users\test\missions\HunterKiller_Patrol.Desert_E\HunterKiller_Patrol.sqf, line 98

Error in expression <s _grphunter > 0)} do {


_hunterType = nearestobjects [leader _grphunter,[_type>
 Error position: <nearestobjects [leader _grphunter,[_type>
 Error Type Any, expected String
File c:\arma2\users\test\missions\HunterKiller_Patrol.Desert_E\HunterKiller_Patrol.sqf, line 69

Edit: Might be as CBA was not running.. my fault. You should make your code safe not to break

when no CBA is running, exit safely and tell the users about it. Thanks

Edited by .kju [PvPscene]

Share this post


Link to post
Share on other sites

Thanks for that hint PVPscene !

Is there a script command to check if CBA is running ?

Oh, and is there a way to check for what "type" unit is ?

// Update position
_hunterType = nearestobjects [leader _grphunter,[_typeofhunter],(_areasize * _multi)];
_targetType = nearestobjects [leader _grphunter,[_typeoftarget],(_areasize)];

http://community.bistudio.com/wiki/nearestObjects

I mean, the ArmA2 russians are "SoldierEB" for example, but some addons have different "types" and most of them dont tell you about that in there Readme's.

So is there any way (via script for example) to find out what "type" a specific unit is ?

Using the ClassName is no option, i want to cover all units of a type.

Share this post


Link to post
Share on other sites

Hi, I want to use this in an SP mission.

I've already got patrols going with way points, last being "Cycle".

Now, if I put the "HunterScript" in my missions folder, I don't get how it will execute.

Is there something needed in the Patrol Group Leaders Init field or something?

Sorry, I'm learning from you Kung Fu Script masters of config Wing Chun.;)

Please explain what to do in kindergarten terms. Thanks.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×