Jump to content
Sign in to follow this  
Fumbles88

Dynamic Spawn help

Recommended Posts

Hi guys,

I have been working on a script for the Fayshkabur map. Basically I want it to only spawn and random amount and type of enemies when BLUFOR come into the trigger area. I am executing the UPS script in the init of each of these units also which will allow for random placement within the marker areas of the towns and cities.

Basically I have been having a bit of trouble finding the error in this code - I have been tweaking now for the last few days to see if I can get it to work but I must confess and admit that I need a fresh pair of eyes to help me out.

Here is my code so far.

//Created by Mark Henderson (Pte. M. Henderson [6thAB]
//3 Oct 2012

//Script for use with Faysh Kabur only
//Spawns enemies from pool when blufor is a certain distance from marker using trigger.

//Armour chance low
//Veh + static chance medium
//Infantry chance high

//Call using nul = ["MarkerName"] execVM "Scripts\spawn.sqf";

//Version 1.10



//Declare Private variables
private ["_enemyFootPool","_enemyArmPool","_enemyVehPool","_enemyStatPool","_footNumberSpawn","_ArmNumberSpawn",
"_VehNumberSpawn","_enemyArmPoolCount","_enemyVehPoolCount","_enemyStatPoolCount","_spawnedUnit","_ArmType",
"_VehType","_StatType","_spawnedStatUnit","_i","_y","_z","_StatNumberSpawn","_FootType","_spawnedArmUnit","_location",
"_ArmUnit","_b","_spawnedVehUnit","_VehUnit","_enemyFootPoolCount"];

//Set Variable of Marker triggered

_location = _this select 0;

//Enemy pools in form of array, then counted

_enemyFootPool = ["TK_Soldier_AA_EP1","TK_Soldier_AAT_EP1","TK_Soldier_AMG_EP1","TK_Soldier_HAT_EP1",
                       "TK_Soldier_AR_EP1","TK_Commander_EP1","TK_Soldier_Crew_EP1","TK_Soldier_Engineer_EP1",
                       "TK_Soldier_GL_EP1","TK_Soldier_MG_EP1","TK_Soldier_Medic_EP1","TK_Soldier_Officer_EP1",
                       "TK_Soldier_EP1","TK_Soldier_B_EP1","TK_Soldier_LAT_EP" ,"TK_Soldier_AT_EP1"    
                       ,"TK_Soldier_Sniper_EP1", "TK_Soldier_SniperH_EP1","TK_Soldier_Sniper_Night_EP1"," 
TK_Soldier_TWS_EP1","TK_Soldier_Spotter_EP1","TK_Soldier_SL_EP1", "TK_Special_Forces_MG_EP1", "TK_Special_Forces_EP1", 
"TK_Special_Forces_TL_EP1"];

_enemyFootPoolCount = count _enemyFootPool;


_enemyArmPool = ["BMP2_TK_EP1","  BMP2_HQ_TK_EP1","BRDM2_TK_EP1","BRDM2_ATGM_TK_EP1","BTR60_TK_EP1",
"M113_TK_EP1","T34_TK_EP1","T55_TK_EP1","T72_TK_EP1","ZSU_TK_EP1"];

_enemyArmPoolCount = count _enemyArmPool;


_enemyVehPool = ["GRAD_TK_EP1","LandRover_MG_TK_EP1","LandRover_SPG9_TK_EP1","UAZ_Unarmed_TK_EP1",
"UAZ_AGS30_TK_EP1","UAZ_MG_TK_EP1"];

_enemyVehPoolCount = count _enemyVehPool;

_enemyStatPool = ["Igla_AA_pod_TK_EP1", "AGS_TK_EP1", "D30_TK_EP1", "KORD_high_TK_EP1","KORD_TK_EP1",
"Metis_TK_EP1", "2b14_82mm_TK_EP1","ZU23_TK_EP1"];

_enemyStatPoolCount = count _enemyStatPool;

//pick random number of each pool to spawn

hint "1";

//First if is for larger cities and towns

if ((_location == "Tall") || (_location == "faysh") || (_location == "mish") || (_location == "gerb"))

then {
   _footNumberSpawn = round (random 30);
   _ArmNumberSpawn = round (random 1);
   _VehNumberSpawn = round (random 3);
   _StatNumberSpawn = round (random 3);

   if (_footNumberSpawn <= 15)
   then {
       _footNumberSpawn = _footNumberSpawn + 15;
           };

   if (_VehNumberSpawn < 1)
   then {
       _VehNumberSpawn = _VehNumberSpawn + round (random 1);
           };

   if (_StatNumberSpawn < 2)
   then {
       _StatNumberSpawn = _StatNumberSpawn + round (random 1);
            };
            hint "2";
        }

//Else sets numbers for smaller towns and villages.

else {
   _footNumberSpawn = round (random 15);
   _ArmNumberSpawn = round (random 1);
   _VehNumberSpawn = round (random 2);
   _StatNumberSpawn = round (random 2);

   if (_footNumberSpawn <= 8)

   then{
       _footNumberSpawn = _footNumberSpawn + 5;
          };

   if (_ArmNumberSpawn == 1)

   then {
       _ArmNumberSpawn - round (random 1);
            };

       };

       hint "3";

       sleep 2;



if (true) then {

//Set Counter
_i = 0;

//While loop, selects random unit from pool arrays and spawns with UPS in init
while {_i < _footNumberSpawn} do {
   _FootType = _enemyFootPool select (round (random _enemyFootPoolCount));

   _spawnedUnit = [getMarkerPos _location, EAST, [_FootType]] call BIS_fnc_spawnGroup;
   {_x setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';"} forEach units _spawnedUnit;

   hint format ["3, %1, %2", _footNumberSpawn, _i];

   _i = _i + 1;
   processInitCommands;
};

hint "4";

//Count for armour
_b = 0;

//While loop now for armour

while {_b < _ArmNumberSpawn} do {
   _ArmType = _enemyArmPool select (round (random _enemyArmPoolCount));

   _spawnedArmUnit = [getMarkerPos _location, 180, _ArmType, EAST] call bis_fnc_spawnvehicle;
   _ArmUnit = _spawnedArmUnit select 0;
   {_x setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';"} forEach units _ArmUnit;

   _b = _b + 1;
   processInitCommands;
};

hint "5";

//Count for vehicles 
_y = 0;

//While loop for vehicles

while {_y < _VehNumberSpawn} do {
   _VehType = _enemyVehPool select (round (random _enemyVehPoolCount));

   _spawnedVehUnit = [getMarkerPos _location, 180, _VehType, EAST] call bis_fnc_spawnvehicle;
   _VehUnit = _spawnedVehUnit select 0;
   {_x setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';"} forEach units _VehUnit;

   _y = _y + 1;
   processInitCommands;
};

hint "6";

//Set counter for statics

_z = 0;

//While loop for statics

while {_z < _StatNumberSpawn} do {
   _StatType = _enemyStatPool select (round (random _enemyStatPoolCount));

   _spawnedStatUnit = createVehicle [_StatType, getMarkerPos _location, [], 0, "NONE"];
   _spawnedStatUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";

   nul = [_spawnedUnit, _spawnedStatUnit] execVM "Scripts\man.sqf";
   _z = _z + 1;
   processInitCommands;
};    

hint "Complete";


};

Cheers for any help that you can give me.

EDIT: This is all now solved and has gone through a few changes since. I have uploaded the latest working version so that others may learn from it, use it and improve upon it etc.

Edited by Fumbles88

Share this post


Link to post
Share on other sites

Just woke up so haven't fully read this, but don't use _x as a variable and these lines will be fail:

 _spawnedStatUnit setVehicleInit "nul = [this, _location, [color="#FF0000"]"[/color]random[color="#FF0000"]"[/color]] execVM [color="#FF0000"]"[/color]Scripts\ups.sqf[color="#FF0000"]"[/color];";

It should be like this:

 _spawnedStatUnit setVehicleInit "nul = [this, _location, 'random'] execVM 'Scripts\ups.sqf';";

or this:

 _spawnedStatUnit setVehicleInit "nul = [this, _location, ""random""] execVM ""Scripts\ups.sqf"";";

-showScriptErrors in your startup line would catch that kind of thing. You probably wouldn't even need the whole init things since you could just run ups.sqf on the spawned objects, but I dunno.

Share this post


Link to post
Share on other sites
Just woke up so haven't fully read this, but don't use _x as a variable and these lines will be fail:

 _spawnedStatUnit setVehicleInit "nul = [this, _location, [color="#FF0000"]"[/color]random[color="#FF0000"]"[/color]] execVM [color="#FF0000"]"[/color]Scripts\ups.sqf[color="#FF0000"]"[/color];";

It should be like this:

 _spawnedStatUnit setVehicleInit "nul = [this, _location, 'random'] execVM 'Scripts\ups.sqf';";

or this:

 _spawnedStatUnit setVehicleInit "nul = [this, _location, ""random""] execVM ""Scripts\ups.sqf"";";

-showScriptErrors in your startup line would catch that kind of thing. You probably wouldn't even need the whole init things since you could just run ups.sqf on the spawned objects, but I dunno.

Hi,

Cheers for your response; I've tried what you recommended and I'm now getting an error on line 56 - which is

if ((_location = "Tall") || (_location = "faysh") || (_location = "mish") || (_location = "gerb"))

Can anyone see what is wrong here? It gives the generic 'missing )' error but I can't see what I'm missing.

Cheers again guys.

Share this post


Link to post
Share on other sites

Those would want to be _localtion == "Tall" instead of just =. == is "is equal to" while = is "set this value".

You could also limit that by doing:

if (_location in ["Tall", "faysh", "mish", "gerb"]) then { // blah };

Just make sure _location is a string.

Share this post


Link to post
Share on other sites
Those would want to be _localtion == "Tall" instead of just =. == is "is equal to" while = is "set this value".

You could also limit that by doing:

if (_location in ["Tall", "faysh", "mish", "gerb"]) then { // blah };

Just make sure _location is a string.

Fantastic, can't believe I'd overlooked that. It's great to have a fresh set of eyes who can see your silly errors haha.

Thank you so much for your time and assistance, the script is up and running now.

For anyone who may wish to use this for learning or tweaking etc, here is the final code.

//Created by Mark Henderson (Pte. M. Henderson [6thAB]
//3 Oct 2012

//Script for use with Faysh Kabur only
//Spawns enemies from pool when blufor is a certain distance from marker using trigger.

//Armour chance low
//Veh + static chance medium
//Infantry chance high

//Call using nul = ["MarkerName"] execVM "Scripts\spawn.sqf";

//Version 1.01



//Declare Private variables
private ["_enemyFootPool","_enemyArmPool","_enemyVehPool","_enemyStatPool","_footNumberSpawn","_ArmNumberSpawn","_VehNumberSpawn","_enemyFootPoolCount","_enemyArmPoolCount","_enemyVehPoolCount","_enemyStatPoolCount","_spawnedUnit","_ArmType","_VehType","_spawnedVehUnit","_StatType","_spawnedStatUnit","_i","_y","_z","_StatNumberSpawn","_FootType","_spawnedArmUnit","_location","_b","_grp"];

//Set Variable of Marker triggered

_location = _this select 0;

//Enemy pools in form of array, then counted

_enemyFootPool = ["TK_Soldier_AA_EP1","TK_Soldier_AAT_EP1","TK_Soldier_AMG_EP1","TK_Soldier_HAT_EP1",
                       "TK_Soldier_AR_EP1","TK_Commander_EP1","TK_Soldier_Crew_EP1","TK_Soldier_Engineer_EP1",
                       "TK_Soldier_GL_EP1","TK_Soldier_MG_EP1","TK_Soldier_Medic_EP1","TK_Soldier_Officer_EP1",
                       "TK_Soldier_EP1","TK_Soldier_B_EP1","TK_Soldier_LAT_EP" ,"TK_Soldier_AT_EP1"    
                       ,"TK_Soldier_Sniper_EP1", "TK_Soldier_SniperH_EP1","TK_Soldier_Sniper_Night_EP1"," 
TK_Soldier_TWS_EP1","TK_Soldier_Spotter_EP1","TK_Soldier_SL_EP1", "TK_Special_Forces_MG_EP1", "TK_Special_Forces_EP1", "TK_Special_Forces_TL_EP1"];

_enemyFootPoolCount = count _enemyFootPool;


_enemyArmPool = ["BMP2_TK_EP1","  BMP2_HQ_TK_EP1","BRDM2_TK_EP1","BRDM2_ATGM_TK_EP1","BTR60_TK_EP1",
"M113_TK_EP1","T34_TK_EP1","T55_TK_EP1","T72_TK_EP1","ZSU_TK_EP1"];

_enemyArmPoolCount = count _enemyArmPool;


_enemyVehPool = ["GRAD_TK_EP1","LandRover_MG_TK_EP1","LandRover_SPG9_TK_EP1","UAZ_Unarmed_TK_EP1",
"UAZ_AGS30_TK_EP1","UAZ_MG_TK_EP1"];

_enemyVehPoolCount = count _enemyVehPool;

_enemyStatPool = ["Igla_AA_pod_TK_EP1", "AGS_TK_EP1", "D30_TK_EP1", "KORD_high_TK_EP1","KORD_TK_EP1",
"Metis_TK_EP1", "2b14_82mm_TK_EP1","ZU23_TK_EP1"];

_enemyStatPoolCount = count _enemyStatPool;

//pick random number of each pool to spawn

hint "1";

//First if is for larger cities and towns

if ((_location == "Tall") || (_location == "faysh") || (_location == "mish") || (_location == "gerb"))

then {
   _footNumberSpawn = round (random 30);
   _ArmNumberSpawn = round (random 1);
   _VehNumberSpawn = round (random 3);
   _StatNumberSpawn = round (random 3);

   if (_footNumberSpawn <= 15)
   then {
       _footNumberSpawn = _footNumberSpawn + 15;
           };

   if (_VehNumberSpawn < 1)
   then {
       _VehNumberSpawn = _VehNumberSpawn + round (random 1);
           };

   if (_StatNumberSpawn < 2)
   then {
       _StatNumberSpawn = _StatNumberSpawn + round (random 1);
            };
            hint "2";
        }

//Else sets numbers for smaller towns and villages.

else {
   _footNumberSpawn = round (random 10);
   _ArmNumberSpawn = round (random 1);
   _VehNumberSpawn = round (random 2);
   _StatNumberSpawn = round (random 2);

   if (_footNumberSpawn <= 5)

   then{
       _footNumberSpawn = _footNumberSpawn + 5;
          };

   if (_ArmNumberSpawn == 1)

   then {
       _ArmNumberSpawn - round (random 1);
            };

       };

       hint format ["3 %1", _footNumberSpawn];

       sleep 2;
//Set Counter

_i = 0;

//While loop, selects random unit from pool arrays and spawns with UPS in init
while {_i < _footNumberSpawn} do {
   _FootType = _enemyFootPool select (round (random _enemyFootPoolCount));
   _grp = createGroup east;

   _spawnedUnit = _grp createUnit [_FootType, getMarkerPos _location, [], 0, "NONE"];
   _spawnedUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
   processInitCommands;

   _i + 1;
};

hint "4";

sleep 2;
//Count for armour
_b = 0;

//While loop now for armour

while {_b < _ArmNumberSpawn} do {
   _ArmType = _enemyArmPool select (round (random _enemyArmPoolCount));

   _spawnedArmUnit = createVehicle [_ArmType, getMarkerPos _location, [], 0, "NONE"];
   _spawnedArmUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
   processInitCommands;

   _b + 1;

};

sleep 2;
hint "5";

//Count for vehicles 
_y = 0;

//While loop for vehicles

while {_y < _VehNumberSpawn} do {
   _VehType = _enemyVehPool select (round (random _enemyVehPoolCount));

   _spawnedVehUnit = createVehicle [_VehType, getMarkerPos _location, [], 0, "NONE"];
   _spawnedVehUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
   processInitCommands;

   _y + 1;

};

sleep 2;
hint "6";

//Set counter for statics

_z = 0;

//While loop for statics

while {_z < _StatNumberSpawn} do {
   _StatType = _enemyStatPool select (round (random _enemyStatPoolCount));

   _spawnedStatUnit = createVehicle [_StatType, getMarkerPos _location, [], 0, "NONE"];
   _spawnedStatUnit setVehicleInit "nul = [this, _location, 'Random'] execVM 'Scripts\ups.sqf';";
   processInitCommands;

   _z + 1;

};    

sleep 2;
hint "Complete";

Edited by Fumbles88
Updated script

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  

×