Jump to content
Sign in to follow this  
carlostex

Enemy Units Spawn Script based on Count -- Help!!!

Recommended Posts

Allright fellas i have this:

//////////////////////////////////////////////////////////////////
// EnemyPopulate.sqf
// Script and code by: CarlosTex
//////////////////////////////////////////////////////////////////

if (!isserver) exitWith {};

private ["_aU", "_targetUnits", "_delayCheck"];

_aUE = {alive _x && side _x == EAST} count allunits;
_aUR = {alive _x && side _x == RESISTANCE} count allunits;

_au = _aUE + _aUR;

_targetUnits = _this select 0;
_delayCheck = _this select 1;

while {true} do {
       sleep _delaycheck;
if (_aU < _targetUnits) then {
	_grpe1 = [getMarkerPos "def_spawn1", east, ["Ins_Soldier_CO", "Ins_Soldier_MG", "Ins_Soldier_AR", "Ins_Soldier_GL", "Ins_Soldier_Sniper", "Ins_Soldier_MG", "Ins_Soldier_AR", "Ins_Soldier_GL", "Ins_Soldier_AT"],[], ["CAPTAIN", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT"],[0.7,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5],[],[],round (random 360)] call BIS_fnc_spawnGroup;
               _grpe2 = [getMarkerPos "def_spawn2", resistance, ["GUE_Soldier_CO", "ACE_GUE_Soldier_Engineer", "GUE_Soldier_Sniper", "GUE_Soldier_2", "GUE_Soldier_3", "ACE_GUE_Soldier_Engineer", "GUE_Soldier_MG","GUE_Soldier_AT"],[], ["CAPTAIN", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT", "SERGEANT"],[0.7,0.5,0.5,0.5,0.5,0.5,0.5,0.5],[],[],round (random 360)] call BIS_fnc_spawnGroup;
               _grpe1s= [_grpe1,(getMarkerPos "b18"),500] execVM "BIN_taskPatrol.sqf";
               _grpe2s= [_grpe2,(getMarkerPos "b19"),500] execVM "BIN_taskPatrol.sqf";
       };

       _aUE = {alive _x && side _x == EAST} count allunits;
       _aUR = {alive _x && side _x == RESISTANCE} count allunits;

       _au = _aUE + _aUR;

       player sidechat format ["Number of enemy units is %1", _au];
};

This script i created does almost everything i need except i want it to check units only in a marker or trigger area instead of checking all map.

I can't figure out the code, total noob scripter!!

Thanks!

Share this post


Link to post
Share on other sites
_au = {alive _x AND side _x in [WEST,EAST]} count [url="http://community.bistudio.com/wiki/list"]list[/url] triggerName;

Share this post


Link to post
Share on other sites

If you want to check it without using a trigger - say distance from object named tent...

could try something like -


_list = ((position tent) nearEntities [["Man"],5]);
_num = EAST countside _list;

player sidechat format ["Number of enemy units is %1", _num];

Share this post


Link to post
Share on other sites
_au = {alive _x AND side _x in [WEST,EAST]} count [url="http://community.bistudio.com/wiki/list"]list[/url] triggerName;

This works well when i make the trigger activate as Anybody present.

Edited by CarlosTex

Share this post


Link to post
Share on other sites

I'm really happy with these scripts, work without problems single player, dedicated, you name it. Performance is also great. Didn't notice any slowdowns when units spawn.

So i'll share them.

First version simpler.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EnemyPopulateRandom.sqf
// Script and code by: CarlosTex
// How to: null = [threshold of units, time until new check, trigger with the area, enemyside, 2nd enemyside (optional)] execVM "EnemyPopulate.sqf";
// Create a trigger with the desired area and set the activation to the enemy side Present or Anybody present if you use the 2nd enemy Side
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


if (!isserver) exitWith {};

private ["_aU", "_targetUnits", "_delayCheck", "_triggerName", "_enemySide1", "_enemySide2", "_unitsWave", "_grpe1", "_grpe2", "_grpe1s", "_grpe2s","_enemies","_spawnMarkers"];

sleep 1;

_unitsWave = [5,6,7,8,9,10];
_spawnMarkers = ["infspawn1","infspawn2","infspawn3","infspawn4"];

_targetUnits = _this select 0; 
_delayCheck = _this select 1;
_triggerName = _this select 2;
_enemySide1 = _this select 3;
_enemySide2 = _this select 4;
_aU = {alive _x && side _x in [_enemySide1, _enemySide2]} count list _triggerName;
_enemies = [_enemySide1,_enemySide2];

while {true} do {
if (_aU < _targetUnits) then {
	_grpe1 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemies select (floor random count _enemies), _unitsWave select (floor random count _unitsWave)] call BIS_fnc_spawnGroup;                            
               _grpe1s= [_grpe1,(getMarkerPos "b18"),500] execVM "BIN_taskPatrol.sqf";
                sleep 0.1;                               
               _grpe2 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemies select (floor random count _enemies), _unitsWave select (floor random count _unitsWave)] call BIS_fnc_spawnGroup;
               _grpe2s= [_grpe2,(getMarkerPos "b19"),500] execVM "BIN_taskPatrol.sqf";                 
       };  
     sleep _delayCheck; 
     _aU = {alive _x && side _x in [_enemySide1,_enemySide2]} count list _triggerName;             
};

Second version more complex.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EnemyPopulateSpecific.sqf
// Script and code by: CarlosTex
// How to: null = [threshold of units, time until new check, trigger with the area, enemyside, 2nd enemyside (optional)] execVM "EnemyPopulate.sqf";
// Create a trigger with the desired area and set the activation to the enemy side Present or Anybody present if you use the 2nd enemy Side
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


if (!isserver) exitWith {};

private ["_aU", "_targetUnits", "_delayCheck", "_triggerName", "_enemySide1",
"_enemySide2", "_eGroups", "_rGroups", "_wGroups", "_grpe1", "_grpe2", "_grpe1s", "_grpe2s",
"_grpe3", "_grpe4", "_grpe3s", "_grpe4s", "_grpe5", "_grpe6", "_grpe5s", "_grpe6s", "_spawnMarkers"];

sleep 1;

_spawnMarkers = ["infspawn1","infspawn2","infspawn3","infspawn4"];
_eGroups = [
(configFile >> "CfgGroups" >> "East" >> "INS" >> "Infantry" >> "INS_InfSquad"),
(configFile >> "CfgGroups" >> "East" >> "INS" >> "Infantry" >> "INS_InfSquad_Weapons"),
(configFile >> "CfgGroups" >> "East" >> "INS" >> "Infantry" >> "INS_SniperTeam"),
(configFile >> "CfgGroups" >> "East" >> "BIS_TK" >> "Infantry" >> "TK_InfantrySquad"),
(configFile >> "CfgGroups" >> "East" >> "BIS_TK" >> "Infantry" >> "TK_InfantrySectionMG")
];
_rGroups = [
(configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfSquad"),
(configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfSquad_Weapons"),
(configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfTeam_1"),
(configFile >> "CfgGroups" >> "Guerrila" >> "PMC_BAF" >> "Infantry" >> "PMC_Field_Security_Team"),
(configFile >> "CfgGroups" >> "Guerrila" >> "PMC_BAF" >> "Infantry" >> "PMC_Security_Detail")
];
_wGroups = [
(configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> "US_RifleSquad"),
(configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> "US_WeaponsSquad"),
(configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> "US_Team"),
(configFile >> "CfgGroups" >> "West" >> "BIS_CZ" >> "Infantry" >> "ACR_SpecialForcesTeam"),
(configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry" >> "BAF_Fireteam_MTP")
];

_targetUnits = _this select 0; 
_delayCheck = _this select 1;
_triggerName = _this select 2;
_enemySide1 = _this select 3;
_enemySide2 = _this select 4;
_aU = {alive _x && side _x in [_enemySide1, _enemySide2]} count list _triggerName;

while {true} do {
if (_aU < _targetUnits) then 
 { 

           switch (_enemySide1) do 
              {
              case EAST:
              {
	_grpe1 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemySide1, _eGroups select (floor random count _eGroups)] call BIS_fnc_spawnGroup;                          
               _grpe1s= [_grpe1,(getMarkerPos "b18"),500] execVM "BIN_taskPatrol.sqf";
              };

              case RESISTANCE:
              {          
               _grpe2 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemySide1, _rGroups select (floor random count _rGroups)] call BIS_fnc_spawnGroup;
               _grpe2s= [_grpe2,(getMarkerPos "b19"),500] execVM "BIN_taskPatrol.sqf";  
              };  

              case WEST:
              {          
               _grpe3 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemySide1, _wGroups select (floor random count _wGroups)] call BIS_fnc_spawnGroup;
               _grpe3s= [_grpe3,(getMarkerPos "b19"),500] execVM "BIN_taskPatrol.sqf";  
              };

              };

       if (!isnil "_enemySide2") then 
       {     
              switch (_enemySide2) do 
              {
              case EAST:
              {
	_grpe4 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemySide2, _eGroups select (floor random count _eGroups)] call BIS_fnc_spawnGroup;                          
               _grpe4s= [_grpe4,(getMarkerPos "b18"),500] execVM "BIN_taskPatrol.sqf";
              };

              case RESISTANCE:
              {          
               _grpe5 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemySide2, _rGroups select (floor random count _rGroups)] call BIS_fnc_spawnGroup;
               _grpe5s= [_grpe5,(getMarkerPos "b19"),500] execVM "BIN_taskPatrol.sqf";  
              };  

              case WEST:
              {          
               _grpe6 = [getMarkerPos (_spawnMarkers select (floor random count _spawnMarkers)), _enemySide2, _wGroups select (floor random count _wGroups)] call BIS_fnc_spawnGroup;
               _grpe6s= [_grpe6,(getMarkerPos "b19"),500] execVM "BIN_taskPatrol.sqf";  
              };

              };

       };  
 };
     sleep _delayCheck;
     _aU = {alive _x && side _x in [_enemySide1,_enemySide2]} count list _triggerName;             
};

:D

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  

×