Jump to content
Sign in to follow this  
demonized

How to create random group from array?

Recommended Posts

I want to use a script to create a random sized group with random units from an array or predefined list.

Goal is to have various quarters of city(preplaced markers) to get populated by enemy and players must move through these areas.

Its intended for COOP multiplayer.

I cannot for the life of me get my head around :banghead:how to make random sized groups, or even use random unit in createUnit command.

1: How can i make an array with classnames and then call a random number, lets say 1 - 10 for this purpose?

2: How can i create a random unit from said list or array in a marker pos?

3: I assume getting group to use upsmon script as described in my script exampleunit 3-6 below works, if not, how to use either leader init line or group id to call upsmon?

4: Idea was to have one script for multiple group creations at different times, since upsmon changes grpname when activated and after they go on their patrol grpname in script is empty again for use.

Is local variabels even usable on deicated server for this purpose _grpname?

Or do i need to use grpname without lead underscore?

Any help will be much appreciated, im a mediocre or less scripter, but use other scripts, and parts of others and have a pretty ok understanding of how things works, especially with org authors helpful hints in scripts //this is how why and what because

This is what i have in my script after alot of trying and failing through various forum searches and script stealing.

// if (!isServer) exitWith {};
//is the [color="Red"],[/color] in correct place in array? is it ("classname[color="Red"]", "[/color]classname") or ("classname[color="Red"]","[/color]classname")?
//define array of class name for militia
_NNDL_unitTypesMilitia = ["TK_INS_Soldier_AA_EP1", "TK_INS_Soldier_AR_EP1", "TK_INS_Bonesetter_EP1", "TK_INS_Soldier_MG_EP1", "TK_INS_Soldier_2_EP1", "TK_INS_Soldier_EP1", "TK_INS_Soldier_4_EP1", "TK_INS_Soldier_3_EP1", "TK_INS_Soldier_AAT_EP1", "TK_INS_Soldier_AT_EP1", "TK_INS_Soldier_Sniper_EP1", "TK_INS_Soldier_TL_EP1", "TK_INS_Warlord_EP1"];


//count array taki Militia
//_cnt = count _NNDL_unitTypesMilitia;
_NNDL_randomman = _NNDL_unitTypesMilitia select (floor(random (count _NNDL_unitTypesMilitia)));
hint "ok1"
//assign spawn group
_nnAogrp = createGroup east;

//spawn group
//option1?
_unit1 = "_NNDL_randomman" createUnit [getMarkerPos "spawnhill", _nnAogrp, "_nnAogrp=This",0.5,"Sergeant"];
//option2?
_unit1 = " _NNDL_randomman" createUnit [getMarkerPos "spawnhill", _nnAogrp, "_nnAogrp=This",0.5,"Sergeant"];
//option3?
_unit1 = "_NNDL_unitTypesMilitia select (floor(random (count _NNDL_unitTypesMilitia)))" createUnit [getMarkerPos "spawnhill", _nnAogrp, "_nnAogrp=This",0.5,"Sergeant"];
_unit2 = "whatever option works" createUnit [getMarkerPos "spawnhill", _nnAogrp, "",0.4,"Corporal"];

[color="Lime"]//below method with unit3 - 6 works fine but no random unit.[/color]
//_unit3 = "TK_INS_Soldier_AT_EP1" createUnit [getMarkerPos "spawnhill", _nnAogrp, "",0.4,"Private"];
//_unit4 = "TK_INS_Soldier_3_EP1" createUnit [getMarkerPos "spawnhill", _nnAogrp, "",0.4,"Private"];
//_unit5 = "TK_INS_Soldier_AR_EP1" createUnit [getMarkerPos "spawnhill", _nnAogrp, "",0.4,"Private"];
//_unit6 = "TK_INS_Soldier_EP1" createUnit [getMarkerPos "spawnhill", _nnAogrp, "",0.4,"Private"];

//set their skill
sleep 0.5;
{_x setSkill 0.6 + (random 0.4)} forEach Units Group _nnAogrp;

//start random placement and patrol need "spawned" in call line for units by create unit command
//sleep 3;
nul=[_nnAogrp,"NNDL_ao","spawned","RANDOMDN","reinforcement"] execvm "scripts\UPSMON.sqf";
hint "end of scripts"
//END

Edited by Demonized

Share this post


Link to post
Share on other sites

bis_fnc_spawngroup will save your ass big time here, it's so easy to use.

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

Here's an example script that I made that will select one of four possible groups at random and spawn them at one of three possible spawn points. Notice the "[1,0.45]" part of the spawning array - that means a minimum group of 1 unit with a 45% chance of spawning the entire group.

BIS_fnc_spawngroup will select units at random from _units to populate the group.

_units = [];

if (isServer) then
{
_random = floor(random 3);
_spawn = [spawn1, spawn2, spawn3] select _random;

_group = floor(random 4);

switch (_group) do {
	case 0: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier",  "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
	case 1: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier",  "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
	case 2: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier",  "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
	case 3: {_units = ["UAZ_MG_CDF", "UAZ_MG_CDF", "BRDM2_CDF", "T72_CDF"];};
};

_spawngroup = [getpos _spawn, West, _units, [],[],[0.5,0.8],[],[1,0.45]] call BIS_fnc_spawnGroup;

_wp = _spawngroup addWaypoint [getpos dest, 0];
_wp setWaypointType "SAD"; 
_wp setWaypointSpeed "FULL";
_wp setWaypointBehaviour "AWARE";
_wp setWaypointFormation "LINE";
};

Share this post


Link to post
Share on other sites

I do this sort of thing all the time, and by far the easiest way is to do it in the editor. Make up the group with all units, then give each unit a chance of existing or not with the probability of presence slider. I do this to randomise units in my own group, to force me to use different tactics and approaches depending on the squad makeup.

Occasionally I need to lean the makeup toward a specific blend, while still having randomisation, so the slider comes in handy i.e. if you have a need for AT units, make the first AT guy 100%, the second 75% and the third 25%. That way you always receive at least one AT guy, probably two, and occasionally three :)

Share this post


Link to post
Share on other sites
bis_fnc_spawngroup will save your ass big time here, it's so easy to use.

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

Here's an example script that I made that will select one of four possible groups at random and spawn them at one of three possible spawn points. Notice the "[1,0.45]" part of the spawning array - that means a minimum group of 1 unit with a 45% chance of spawning the entire group.

BIS_fnc_spawngroup will select units at random from _units to populate the group.

_units = [];

if (isServer) then
{
_random = floor(random 3);
_spawn = [spawn1, spawn2, spawn3] select _random;

_group = floor(random 4);

switch (_group) do {
	case 0: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier",  "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
	case 1: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier",  "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
	case 2: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier",  "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
	case 3: {_units = ["UAZ_MG_CDF", "UAZ_MG_CDF", "BRDM2_CDF", "T72_CDF"];};
};

_spawngroup = [getpos _spawn, West, _units, [],[],[0.5,0.8],[],[1,0.45]] call BIS_fnc_spawnGroup;

_wp = _spawngroup addWaypoint [getpos dest, 0];
_wp setWaypointType "SAD"; 
_wp setWaypointSpeed "FULL";
_wp setWaypointBehaviour "AWARE";
_wp setWaypointFormation "LINE";
};

This worked nicely thank you very much :yay:

But...

i tried using

_units = [];
_side = east;
waituntil {BIS_fnc_init};

if (isServer) then
{
   _random = floor(random 3);
   _spawn = [spawn1, spawn2, spawn3] select _random;

   _group = floor(random 4);

   switch (_group) do {
       case 0: {_units = ["CDF_Soldier_TL", "CDF_Soldier_MG", "CDF_Soldier_RPG", "CDF_Soldier", "CDF_Soldier", "CDF_Soldier", "CDF_Soldier_Marksman"];};
       case 1: {_units = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_AAT_EP1","TK_INS_Soldier_MG_EP1"];};
       case 2: {_units = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_AAT_EP1","TK_INS_Soldier_MG_EP1"];};
       case 3: {_units = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_AAT_EP1","TK_INS_Soldier_MG_EP1"];};
   };

   _spawngroup = [getpos _spawn, _side, _units, [],[],[0.5,0.8],[],[1,0.45]] call BIS_fnc_spawnGroup;
   _wp = _spawngroup addWaypoint [getpos dest, 0];
   _wp setWaypointType "SAD";
   _wp setWaypointSpeed "FULL";
   _wp setWaypointBehaviour "AWARE";
   _wp setWaypointFormation "LINE";
};

in case 0 array in above spoiler, they spawn as they should but immediatly start shooting 1 or several units from their own squad, also attacks other groups spawned with same script.

after a second or so, they seem to be going to their wp and stops engaging eachother in same group, number of enemys seem to be random within group, sometimes 1, other times they kill 2 or 3 from own group, maybe they just start SAD wp and kills whatever units appear as enemy?

Also when other groups spawn after with same script they kill whole groups not same unit as east before moving on to wp.

Tried using waituntil {BIS_fnc_init}; but no change in beheavior.

I did a check with replacing your CDF units with OA taki army, worked as it should.

I figure with "call BIS_fnc_spawnGroup" you can only spawn units listed as a specific side within arma hardcode or something.

You cannot spawn a baf soldier in a east group?

1: My question: is there a way to get around that to make something like in the below spoiler, have west and east and resistance units in same spawngroup and not shoot eachother?

maybe a (disable AI targeting until all in east group) check? or something?

case 0: {_units = ["CDF_Soldier_TL", "TK_INS_Soldier_TL_EP1","TK_GUE_Soldier_AA_EP1"];};

and if so, how?

DMarkwick -

yes i do that to, but since its a big mission id like to have only needed units placed to have as little stress on server as possible, and spawns with scripts when players reach a certain point(after killing off initial enemys)

tho i use your way in some form in the script posted by fatty86, i simply place multiple units of for instance AT soldiers in the array. the script chooses from, or when i need a bigger amount of say AT soldiers i have a seperate script with no random groups, only 1 group array and random number of units with minimum of 3 or higher. half of units in grp array is AT rest or maybe only 1 or 2 is no AT.

_units = [];
_side = east;

waituntil {BIS_fnc_init};

if (isServer) then
{
   _units = ["TK_INS_Soldier_TL_EP1", "TK_INS_Soldier_4_EP1", "TK_INS_Soldier_AT_EP1", "TK_INS_Soldier_AT_EP1", "TK_INS_Soldier_AT_EP1", "TK_INS_Soldier_AT_EP1"];};

   _spawngroup = [getpos _spawn, _side, _units, [],[],[0.5,0.8],[],[3,0.50]] call BIS_fnc_spawnGroup;
   _wp = _spawngroup addWaypoint [getpos dest, 0];
   _wp setWaypointType "SAD";
   _wp setWaypointSpeed "FULL";
   _wp setWaypointBehaviour "AWARE";
   _wp setWaypointFormation "LINE";
}; 

Its not as accurate as probability of presence slider but should work ok, 3 and 50 in script stands for minimum 3 units and probability of 50% for rest, not yet tested but i assume it should work.

Also i found this site:

http://browser.dev-heaven.net/cfg_groups/config/East?=A2+OA+%28Only%29%3A+1.54&version=23&options[filter]=&options[sort_values_by]=&commit=Change

wich gives all kinds of arrays or confignames to use with call BIS_fnc_spawnGroup and others, useful to get standard groups as they are in editor.

Edited by Demonized

Share this post


Link to post
Share on other sites

-yes maybe, was hoping to keep number of scripts running to a minimum since im using UPSMON, but dling DAC 3.0c now.

Maybe better not reinventing the wheel :)

Lets see how it impacts when 500 ai units alive same time, will post back results.

Edited by Demonized
not finished coment

Share this post


Link to post
Share on other sites
-yes maybe, was hoping to keep number of scripts running to a minimum since im using UPSMON, but dling DAC 3.0c now.

Maybe better not reinventing the wheel :)

Lets see how it impacts when 500 ai units alive same time, will post back results.

Well there's 3 things that DAC will help you out with:

1. Randomisation of group makeup is easy to customise.

2. Groups can be triggered to spawn only when you need them.

3. Even groups that do exist, can reduce to one representative unit at a specified distance, saving you resources until you get closer.

And, as a bonus all groups can have their own waypoints and things to do if you'd like, rather than them simply standing about.

Share this post


Link to post
Share on other sites

At this moment ive decided to stay with UPSMON instead of DAC.

UPSMON have no or very little impact on my fps, even when lots of AI is active, this goes same to DAC, but i personally like better the functionality of UPSMON combined with spawning random groups like fatty86 descried in post above.

The reinforcement parameter especially is great feature with UPSMON imo.

Ive been a personal fan of ups since arma1 and now upsmon.

As stated in UPSMON thread, upsmon will never use more cpu than allowed by the game, thus preventing lag because of big load, only thing i noticed is that when my computer cant keep up with 100 upsmon squads starting at same time, it simply takes longer to get all groups assigned to upsmon in realtime, you can see this by activating debug in upsmoninit.

Got the idea of caching units from DMarkwick´s post about DAC, so i use this

http://www.armaholic.com/page.php?id=10102&highlight=CACHE+UNITS and it works really well.

Also combining UPSMON and Zeus AI gives great results in ways of firefight and more belivable enemys.

http://www.armaholic.com/page.php?id=8250&highlight=ZEUS

And finally here is the link to UPSMON incase anyone is interested.

http://www.armaholic.com/page.php?id=9213&highlight=UPSMON

A big thank you goes to fatty86 and DMarkwick for your help and tips.

Regards

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  

×