Jump to content
Sign in to follow this  
anthonyfromtheuk

how to make this enemy spawn script multiplayer

Recommended Posts

I am using this script to call an enemy recon team against me in SP but i would like to know how to make the enemy team move towards all players in multiplayer instead of just player in SP? Anybody assist please?

if (!isServer) exitwith {};
private ["_side", "_reconTeam", "_leader"];
_side = createCenter east;
_spawns = ["north","south","east","west"];
_randomspawn = _spawns call BIS_fnc_selectRandom;
_reconteam = [getMarkerPos _randomspawn, _side, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OI_reconTeam")] call BIS_fnc_spawnGroup;

_leader = leader _reconTeam;
_leader move (getPosATL player);
_reconTeam setCombatMode "RED";
_reconTeam setBehaviour "AWARE";

0 = _reconTeam spawn {
   while {true} do {
       sleep 3;
       if ((player distance (leader _this)) > 500) exitWith {
           {
               deleteVehicle _x;
           } forEach (units _this);
       };
   };
};
//anthonyfromtheuk.
while {true} do {

   _leader = leader _reconTeam;
   if ((unitReady _leader) && {(alive _leader)}) then {
       sleep 3;
       if (({ alive _x} count (units _reconTeam)) != 0) then {
           _leader = leader _reconTeam;
           _leader move (getPosATL player);
           _reconTeam setCombatMode "RED";
           _reconTeam setBehaviour "AWARE";
           _reconTeam setSpeedMode "NORMAL";
       };
   };
};

Share this post


Link to post
Share on other sites

I'm afraid it's impossible to move in different directions at the same time, so you have to choose only one unit anyway (_leader move (getPosATL leader group player) for example). :D Of course you can find average position of all squad members but it can cause problems if players aren't close to each other.

BTW, it's not adviced to use exitWith command to exit script.

Edited by Semiconductor

Share this post


Link to post
Share on other sites

How about scanning for enemies and moving to a position around the closest or randomly selected enemy?

_nearestEnemies = []; 
_nearestMen = nearestObjects [getPosATL _leader, ["Man"], 1000]; 

{
   if ( (side _x getFriend (side _leader)) < 0.6 && {side _x != CIVILIAN} ) then { //filter out friendlies and animals
      _nearestEnemies = _nearestEnemies + [_x]; 
};
} forEach _nearestMen;

//_enemy = _nearestEnemies select 0; //Closest?	
_enemy = _nearestEnemies call bis_fnc_selectRandom; //Or random
_attkPos = [_enemy, random 100, random 360] call BIS_fnc_relPos; 

/*
    Your move loop here.
*/ 

BTW, it's not adviced to use exitWith command to exit script.

I'm very curious, please elaborate.

Edited by Iceman77

Share this post


Link to post
Share on other sites

You can also obviously move directly to the targets position aswell. Thought the random position was a nice touch though.

Share this post


Link to post
Share on other sites

_nearestEnemies = []; 
_nearestMen = nearestObjects [getPosATL _leader, ["Man"], 1000]; 

{
   if ( (side _x getFriend (side _leader)) < 0.6 && {side _x != CIVILIAN} ) then { //filter out friendlies and animals
      _nearestEnemies = _nearestEnemies + [_x]; 
};
} forEach _nearestMen;

//_enemy = _nearestEnemies select 0; //Closest?	
_enemy = _nearestEnemies call bis_fnc_selectRandom; //Or random
_attkPos = [_enemy, random 100, random 360] call BIS_fnc_relPos; 

/*
    Your move loop here.
*/ 

I cant figure out how to incorporate this in to the original script.. I like this idea!

Share this post


Link to post
Share on other sites

Try this.

//heavily modified by iceman77

if (!isServer) exitwith {};
_side = createCenter east;
_spawns = ["north","south","east","west"];
_randomSpawn = _spawns call BIS_fnc_selectRandom;
_reconTeam = [getMarkerPos _randomSpawn, _side, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OI_reconTeam")] call BIS_fnc_spawnGroup;
_reconTeam setCombatMode "RED"; 
_reconTeam setBehaviour "AWARE";
_leader = leader _reconTeam;

_nearestEnemies = []; 
_nearestMen = nearestObjects [getPosATL _leader, ["Man"], 1000]; 

{
   if ( (side _x getFriend (side _leader)) < 0.6 && {side _x != CIVILIAN} ) then { //filter out friendlies and animals
         _nearestEnemies = _nearestEnemies + [_x]; 
   };
} forEach _nearestMen;

//_enemy = _nearestEnemies select 0; //Closest?    
_enemy = _nearestEnemies call bis_fnc_selectRandom; //Or random
_attkPos = [_enemy, random 100, random 360] call BIS_fnc_relPos; 

[_reconTeam, _attkPos] spawn {
   while {true} do {
       sleep 3;
       //The distance from a null object to any object/target is infinity? If not, then you need to check the alive group count aswell so you don't end up stacking loops.
       if ((_this select 1) distance leader (_this select 0) > 1000) exitWith {
           {
               deleteVehicle _x;
           } forEach units (_this select 0);
       };
   };
};

while {{ alive _x} count (units _reconTeam) != 0} do { //should only need to move the group to the position once, but I included a soft loop anyhow.
   {_x doMove _attkPos;} forEach units _reconTeam;
   sleep 60;
};  

I cleaned up alot of un-needed code aswell (hope you don't mind). Also, I'm not sure exactly what you have in mind as this could be done in different ways. You could scan for enemies in that soft loop before moving to a position (so the group would be changing heading / targets every so often). Or keep it like I have it now.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Thank you Iceman.

This completely changes the way the AI come at me compared to the direct approach I was using before. They are way more spread out and move much slower.

I have greatly reduced the sleep because they were moving to my spawn position and standing there doing nothing for a while.

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
Sign in to follow this  

×