Jump to content
Hud561

Create group to chase player by script

Recommended Posts

Hi


I've been trying to create in a SP mission a situation like this: my group just after having completed a task is chased by an enemy group.

 

I want to create a group (by script or trigger) and make this group chase me, knowing my position at least 1k away.

 

As everybody notice, I'm not a coder or a script creator if you prefer. I always try to use the simplest commands or even small scripts to do the job.

This way, I've tested many small scripts and command lines, but it seems all of them were created for groups that have already being placed on the scenario previously.  In my case,  as I said earlier,  I want to create the group (by script or even by

trigger) in the instant the trigger starts (execVM "xxx.sqf") and this group must get my position and start chasing me.

 

Here is the main problem. How to combine these scripts so that it creates the group and make this group knows instantly where I am and start chasing me.


The one bellow I liked most because it's simple, creates the group, and give me the chance to pick the units i want to be chasers:

 

Group_Name = [getMarkerPos "MARK1", EAST,["O_Soldier_SL_F","O_Soldier_F","O_soldier_M_F","O_Soldier_AR_F","O_medic_F","O_Soldier_LAT_F","O_Soldier_TL_F","O_Soldier_LAT_F"]] call BIS_fnc_spawnGroup;"  

 

The problem is that it uses a "Marker" as its primary objective rather than chasing me. I tried to change "getMarkerpos into "move getpos player", but it didn't work.

 

I also used the following script with the "call BIS_fnc_spawnGroup" above in another sqf file and in a trigger too. It seemed to have accepted (not sure if this really happened) part of the script, seeing that some units did chased me, but

some just keep on standing there.

 

_null = [] spawn {
while {true} do {    
    {Enemy_Alpha move getposatl Grizly;  --- i also used getpos player
    Enemy_Alpha setCombatMode "RED";
    Enemy_Alpha setSpeedMode "FULL";
    };
    sleep 5;
    };
    };


I also liked the one bellow, it's simple, but it only creates one unit, not to mention that these units, as the previous scripts, have as main objective to get to the marker and not necessarily chase me.

 

Group-Name = creategroup east;
enemy1 = Group_Name createunit ["O_Soldier_SL_F",getmarkerpos "Marker3",[],0,"form"];
enemy1 domove (getmarkerpos "Marker_4");

 

I tried to make modifications as changing "getmarkerpos into "getposatl" or "getpos player", but it didn't work either.

 

The next, as the first one, creates the group, but besides not giving the chance to pick the units I want,  it also has the same problem as the others when it comes to knowing my position and chase me.

 

Enemy_Alpha= [getMarkerPos "MARKER2", EAST, 50] call BIS_fnc_spawnGroup; -- but they only appear on the map and keep standing there and sometimes go to someplace else.

 

If somebody could give me a hand on this I'd appreciate it.

 

Hud

Share this post


Link to post
Share on other sites

This should do what you want.
 


//	Save as HuntPlayer.sqf in mission folder - Where mission.sqm is.
//	Run from On Activation in trigger: execVM "HuntPlayer.sqf";

//	Spawn FIFTY East units on marker "MARKER2" - You are a brave warrior, my son!
_huntGroup = [markerPos "MARKER2", EAST, 50] call BIS_fnc_spawnGroup;

_huntGroup setCombatMode "RED";
_huntGroup setSpeedMode "FULL";

//	Tell _huntGroup to stalk / hunt player / players group.
_isHunting = [_huntGroup, group player] spawn BIS_fnc_stalk;

//	Debug hint to let you know if it has worked or not.
//	This could / should be removed when you know it works.
if (_isHunting) then { hint "Player is being stalked!"; } else { hint "Something has gone wrong!"; };

 

Share this post


Link to post
Share on other sites

 

1 hour ago, Maff said:

This should do what you want.
 



//	Save as HuntPlayer.sqf in mission folder - Where mission.sqm is.
//	Run from On Activation in trigger: execVM "HuntPlayer.sqf";

//	Spawn FIFTY East units on marker "MARKER2" - You are a brave warrior, my son!
_huntGroup = [markerPos "MARKER2", EAST, 50] call BIS_fnc_spawnGroup;

_huntGroup setCombatMode "RED";
_huntGroup setSpeedMode "FULL";

//	Tell _huntGroup to stalk / hunt player / players group.
_isHunting = [_huntGroup, group player] spawn BIS_fnc_stalk;

//	Debug hint to let you know if it has worked or not.
//	This could / should be removed when you know it works.
if (_isHunting) then { hint "Player is being stalked!"; } else { hint "Something has gone wrong!"; };

 

Hi Maff. Thanks for the help. Actually it worked perfectly I'd say.

 

Now one more question:

 

Suppose i wanted  to add these lines to your script:

 

_huntGroup setSkill ["aimingAccuracy", 0.85];
_huntGroup setSkill ["aimingShake", 0.40];
_huntGroup setSkill ["aimingSpeed", 0.75];
_huntGroup setSkill ["reloadSpeed", 1];
_huntGroup deleteGroupWhenEmpty true;

 

how would i do it? I've tried but it returned error all the times.

Hud

Share this post


Link to post
Share on other sites

You are using setSkill on the group - It doesn't work that way.

The command has to be set on each units in a group.

 

I have updated the HuntPlayer.sqf below.

 

//	Save as HuntPlayer.sqf in mission folder - Where mission.sqm is.
//	Run from On Activation in trigger: execVM "HuntPlayer.sqf";

//	Spawn FIFTY East units on marker "MARKER2" - You are a brave warrior, my son!
_huntGroup = [markerPos "MARKER2", EAST, 50] call BIS_fnc_spawnGroup;

_huntGroup setCombatMode "RED";
_huntGroup setSpeedMode "FULL";

_huntGroup deleteGroupWhenEmpty true;

//	setSkill doesn't work on groups.
//	Instead you have to setSkill for each unit in a group.
{
	_x setSkill ["aimingAccuracy", 0.85];
	_x setSkill ["aimingShake", 0.40];
	_x setSkill ["aimingSpeed", 0.75];
	_x setSkill ["reloadSpeed", 1];
} forEach (units _huntGroup);

//	Tell _huntGroup to stalk / hunt player / players group.
_isHunting = [_huntGroup, group player] spawn BIS_fnc_stalk;

//	Debug hint to let you know if it has worked or not.
//	This could / should be removed when you know it works.
if (_isHunting) then { hint "Player is being stalked!"; } else { hint "Something has gone wrong!"; };

 

Edited by Maff
Spacing error!
  • Like 2

Share this post


Link to post
Share on other sites

Hi again Maff "Sarge".

 

It's worked perfectly. Thanks for this little coding lesson and for having taken time to share your coding skills with me, and of course, with all the Arma community.

 

Thanks to this i was able to implement the script a little  bit and the final script is that:

 

//    Save as HuntPlayer.sqf in mission folder - Where mission.sqm is.
//    Run from On Activation in trigger: execVM "HuntPlayer.sqf";

//    Spawn FIFTY East units on marker "MARKER2" - You are a brave warrior, my son!

 

_Enemy1 = [markerPos "MARKER2", EAST, 50] call BIS_fnc_spawnGroup;

_Enemy1 setCombatMode "RED";
_Enemy1 setSpeedMode "FULL";
_Enemy1 allowFleeing 0;
_Enemy1 deleteGroupWhenEmpty true;

 

_isHunting = [_Enemy1, Grizly] spawn BIS_fnc_stalk;

{    
    removeAllContainers _x;
    removeUniform _x;
    removeBackpack _x;
    _x forceAddUniform "V_ARCunis_ARCTech_bduAOR2";
    _x addVest "Avest2";
    _x addBackpack "B_CAF_CADPAT_Carryall_TWD";
    _x addItemToVest "30Rnd_65x39_caseless_mag";
    _x addItemToVest "30Rnd_65x39_caseless_mag";
    _x addItemToVest "30Rnd_65x39_caseless_mag";
    _x addItemToVest "1Rnd_HE_Grenade_shell";
    _x addItemToVest "1Rnd_HE_Grenade_shell";
    _x addItemToVest "1Rnd_HE_Grenade_shell";
    _x addItemToVest "16Rnd_9x21_Mag";
    _x addItemToVest "16Rnd_9x21_Mag";
    _x addItemToVest "1Rnd_HE_Grenade_shell";
    _x addItemToVest "1Rnd_HE_Grenade_shell";
    _x addItemToVest "SmokeShell";
    _x addItemToVest "SmokeShellGreen";
    _x addItemToVest "Chemlight_green";
    _x addItemToBackpack "30Rnd_65x39_caseless_mag";
    _x addItemToBackpack "30Rnd_65x39_caseless_mag";
    _x addItemToBackpack "30Rnd_65x39_caseless_mag";
    _x addItemToBackpack "30Rnd_65x39_caseless_mag";
    _x addItemToBackpack "1Rnd_HE_Grenade_shell";
    _x addItemToBackpack "NLAW_F";
    _x addItemToVest "130Rnd_338_Mag";
    _x addHeadgear "H_HelmetB";
    _x addGoggles "G_Tactical_Clear";
    
    }forEach (units _Enemy1);
    
{
    _x setSkill ["aimingAccuracy", 0.85];
    _x setSkill ["aimingShake", 0.40];
    _x setSkill ["aimingSpeed", 0.75];
    _x setSkill ["reloadSpeed", 1];
} forEach (units _Enemy1);

 

//    Tell _huntGroup to stalk / hunt player / players group.
_isHunting = [_huntGroup, group player] spawn BIS_fnc_stalk;

 

//    Debug hint to let you know if it has worked or not.
//    This could / should be removed when you know it works.
if (_isHunting) then { hint "Player is being stalked!"; } else { hint "Something has gone wrong!"; };

 

I know that "my implementation"  it's not pretty because i had to repeat codes when adding Ammo to group units. I mean, doing something  like this: repeting 3x _x addItemToVest "30Rnd_65x39_caseless_mag";

instead of just writing  _x addItemToVest ["30Rnd_65x39_caseless_mag",3];  It was showing errors that i wasn't able to find out what it really meant.
 
We know there's a long way for me to go when it comes to writing scripts, but with your help, i was able to create a group "on the fly",  Setbehaviours,  change its loadout and setskills.

 

Thanks again

Hud

  • Like 2

Share this post


Link to post
Share on other sites

Hey, you are very welcome!

 

 

' _x addItemToVest ["30Rnd_65x39_caseless_mag", 3]; ' is incorrect.

You can only add item to vest one at a time.

 

A shorter way would be to do:

//	Will add THREE 30Rnd_65x39_caseless_mag to vest.
for "_i" from 1 to 3 do
{
   _x addItemToVest "30Rnd_65x39_caseless_mag";
};



I highly suggest you check out the BIKI.

Most of the commands and functions there are very well described with handy examples.
Introduction to Arma Scripting

Scripting Commands Arma 3

Arma 3: Functions

 

 

Enjoy!

  • Like 1

Share this post


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

Hey, you are very welcome!

 

 

' _x addItemToVest ["30Rnd_65x39_caseless_mag", 3]; ' is incorrect.

You can only add item to vest one at a time.

 

A shorter way would be to do:


//	Will add THREE 30Rnd_65x39_caseless_mag to vest.
for "_i" from 1 to 3 do
{
   _x addItemToVest "30Rnd_65x39_caseless_mag";
};



I highly suggest you check out the BIKI.

Most of the commands and functions there are very well described with handy examples.
Introduction to Arma Scripting

Scripting Commands Arma 3

Arma 3: Functions

 

 

Enjoy!

Hi Sarge. Sorry for pestering you. Suppose i want to give different loadouts to some units. I mean, for a sharpshooter a special kind of rifle and so on. Would that be possible?

 

I tried using SetUnitLoadout :

 

"O_Sharpshooter_F" setUnitLoadout
                    [removeAllContainers _x;
                    removeUniform _x;
                    removeBackpack _x;
                    "V_ARCunis_ARCTech_bduAOR2";
                    "Avest2";
                    "B_CAF_CADPAT_Carryall_TWD";
                    "16Rnd_9x21_Mag";
                    "16Rnd_9x21_Mag";

                     "130Rnd_338_Mag";
                    "SmokeShell";
                    "SmokeShellGreen";
                    "Chemlight_green";
                    "H_HelmetB";
                    "G_Tactical_Clear"];

But it didn't work. I also tried the way i've read in this forum - https://forums.bohemia.net/forums/topic/187312-spawn-unit-with-custom-gear/ -

 

_first_unit = (units _enemy1) select 0;
                    _x forceAddUniform "V_ARCunis_ARCTech_bduAOR2";
                    _x addVest "Avest2";
                    _x addBackpack "B_CAF_CADPAT_Carryall_TWD"
                    _x addItemToVest "16Rnd_9x21_Mag";
                    _x addItemToVest "16Rnd_9x21_Mag";

                     _x addItemToVest "130Rnd_338_Mag";
                    _x addItemToVest "SmokeShell";
                    _x addItemToVest "SmokeShellGreen";
                    _x addItemToVest "Chemlight_green";
                  
                   
                    _x addGoggles "G_Tactical_Clear";

 

It worked, but all my units (10 units) got the same stuff.  Any idea?

Hud

 

Share this post


Link to post
Share on other sites

Have a look at the BIKI entry for setUnitLoadout.

Down at the bottom there is an example on how to use it.

It looks pretty overwhelming but once you get the hang of it, you can knock up loadouts in no time.

 

It looks like you are just changing the uniform, vest, and backpack of each unit.

In the mod you are using there may be units already configured, so you can spawn them using BIS_fnc_spawnGroup, instead of spawning random units and applying loadouts on each of them.

 

If there are no units configured then there is quite a bit of work to do.

 

What mods are you using?

Steam link would be best.

 

Share this post


Link to post
Share on other sites
16 minutes ago, Maff said:

In the mod you are using there may be units already configured, so you can spawn them using BIS_fnc_spawnGroup, instead of spawning random units and applying loadouts on each of them.

Sounds like a good idea. I'll try to do that.

Thanks again.

Share this post


Link to post
Share on other sites

Place yourself on the map and name yourself     blue1

Place an enemy soldier on the map and name him     red1

In the init of the enemy soldier type this:

red1 move getPos player; red1 setCombatMode "RED"

 

 

Test 1:  start the mission and remain stationary. The enemy  will move to your starting position and kill you

Test 2:  start the mission and run away.  The enemy soldier will run to your starting position…….and as you are not there he will stop

 

So, we need to find a way, so that the enemy soldier always knows your current position. We do it like this:

 

 

Place a civilian in an out of the way position on a flat road or on a runway.  I strip him of weapons and ammo so he is not carrying a load.

 

Place a trigger on the map.   Set some waypoints and a cycle waypoint.  He will run through the trigger and activate the trigger. He needs to keep running till the trigger deactivates.  As soon as it deactivates he turns and runs through the trigger again.  He does this over and over again.

 

Place this command in the activation cell, and place the same command in the deactivation cell:

red1 move getPos player; red1 setCombatMode "RED"

 

So, start the mission and immediately run away.  Everytime the civilian activates the trigger, or deactivates the trigger,  the enemy soldier knows your new position.

 

I have had a lot of fun with this.  If the enemy has a handful of soldiers you cannot escape because you cannot look in every direction at once.  If the enemy unit is a small chopper escape is difficult. Fun!

.

 

  • Like 1

Share this post


Link to post
Share on other sites

Good topic!

On my AI compilation list seen here

There is a section under the threads titled AI Hunting player/group

if you need more insights and or perspectives on this subject, hope it helps!

Share this post


Link to post
Share on other sites

@Maff

 

Hi Maff i have used your script to Spawn a group of 10 to hunt the player.

But my player is good at his game so he often makes it to the Choppa and flies away in to the sundown,

but the spawn group will keep coming at him so even if he flies to the other end of the map they come to get him in the end, and as that nice guy i am going to help him a bit and kill the rest of the group,

but since my thunder bolts are missing the guys in the group, do you then have a way of writing my out of the problem, Maff ?

 

cheers Play3r

Share this post


Link to post
Share on other sites

 

 

12 hours ago, Play3r said:

But my player is good at his game so he often makes it to the Choppa and flies away in to the sundown,

but the spawn group will keep coming at him so even if he flies to the other end of the map they come to get him in the end, and as that nice guy i am going to help him a bit and kill the rest of the group

 

Does the mission not complete when the player leaves the area in the helicopter?

 

 

 

12 hours ago, Play3r said:

do you then have a way of writing my out of the problem,

 

That can depend on how you have designed your mission.

I suggest your share your mission so people can make better suggestions on how to achieve what you need.

  • Thanks 1

Share this post


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

 

 

 

Does the mission not complete when the player leaves the area in the helicopter?

 

No the mission does not end, it is a kind of intro mission in my SP-game, the player has to blow some chemicals up and the escape to a heli.

 

 

 

That can depend on how you have designed your mission.

I suggest your share your mission so people can make better suggestions on how to achieve what you need.

 

i want a trigger to fire when the player is inside the heli after the intro mission that delete the Group that i have spawned with your script.

 

i have tried with a ForEach command but it did not work.

like this : {deletevehicle _x} forEach (units _huntGroup);

 

cheers Play3r

 

Share this post


Link to post
Share on other sites
12 hours ago, Play3r said:

{deletevehicle _x} forEach (units _huntGroup);

 

 

_huntGroup is a local variable, that's why the units in the group are not being deleted.

Not tested. But this should work.
 

//	No idea if you have changed anything from the original example...
XYZ_huntGroup = [markerPos "MARKER2", EAST, 50] call BIS_fnc_spawnGroup;

XYZ_huntGroup setCombatMode "RED";
XYZ_huntGroup setSpeedMode "FULL";

_isHunting = [XYZ_huntGroup, group player] spawn BIS_fnc_stalk;

//	In your trigger:
{ deleteVehicle _x; } forEach units XYZ_huntGroup;

 

  • Thanks 1

Share this post


Link to post
Share on other sites

@Maff

 

I have not changed anything in your script, so all i needed was to remove the two ( ) i had around the units Huntgroup, or do i just have to remove the _ in HuntGroup.

 

just so i understand this hole Global/ Local Variable thing.

 

Cheers Play3r

Share this post


Link to post
Share on other sites
1 hour ago, Play3r said:

@Maff

 

I have not changed anything in your script, so all i needed was to remove the two ( ) i had around the units Huntgroup, or do i just have to remove the _ in HuntGroup.

 

just so i understand this hole Global/ Local Variable thing.

 

Cheers Play3r

Just change _huntGroup to XYZ_huntGroup.

It's good practice to give global variables a tag, such as ABC_, XYZ_, or BIS_.

  • Thanks 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

×