iceman77 18 Posted October 29, 2013 (edited) Example Mission: Usage: /* FILE :: fn_spawnGroup.sqf :: AUTHOR :: Iceman77 :: DESCRIPTION :: - Spawn a random group of a given type (infantry, motorized, armored, mechanized) from the config :: -Things to note :: - The group itself will ALWAYS be random - The group pool type can be predefined with a number ( see paramaters ) - Alternatively, the pool can be randomly selected :: :: :: PARAMETERS :: _this select 0 <SIDE> :: (optional - nil) SIDE TO SPAWN eg; WEST, EAST, INDEPENDENT :: - Supported Sides :: - west, - blufor, - east, - opfor, - resistance, - independent, - sideUnknown :: _this select 1 <ARRAY, OBJECT, STRING> :: SPAWN POSITION OF THE GROUP - CAN BE AN OBJECT, ARRAY IN POSITION FORMAT, OR A MARKER STRING :: _this select 2 <ARRAY, OBJECT, STRING> :: (optional) GROUP DESTINATION CENTER ( POSITION ) - CAN BE AN OBJECT, ARRAY IN POSITION FORMAT, OR A MARKER STRING :: _this select 3 <NUMBER> :: (optional) Group Type :: - 0=INFANTRY TYPE >> RANDOM GROUP - 1=MOTORIZED TYPE >> RANDOM GROUP - 2=MECHANIZED TYPE >> RANDOM GROUP - 3=ARMORED TYPE >> RANDOM GROUP - 4=RANDOM TYPE >> RANDOM GROUP :: :: _this select 4 <NUMBER> :: (optional) Group Mode :: - 0=PATROL - 1=DEFEND - 2=ATTACK - 3=RANDOM :: :: _this select 5 <NUMBER> :: (optional) GROUP RESPAWN AMOUNT :: _this select 6 <BOOL> :: (optional) DEBUG MARKERS :: :: RETURNS :: NOTHING :: USAGE EXAMPLES :: :: [ sideUnknown, [5000, 3450, 0], "mrk2", 4, 3, 15] spawn IOAI_fnc_spawnGroup; :: [ west, pad1, nil, 0, 0, 0] spawn IOAI_fnc_spawnGroup; :: [ east, "mrk1", "mrk2", 2, 0, 5] spawn IOAI_fnc_spawnGroup; :: [ resistance, "mrk1", pad2, 1, 2, 25] spawn IOAI_fnc_spawnGroup; :: [ west, "mrk1", pad2, 1, 2, 5, true] spawn IOAI_fnc_spawnGroup; :: [ west, pad1, nil, nil, nil, nil, true ] spawn IOAI_fnc_spawnGroup; :: [ west, pad1 ] spawn IOAI_fnc_spawnGroup; :: [ nil, pad1 ] spawn IOAI_fnc_spawnGroup; :: */ Code: if ( !( isServer ) ) exitWith {}; private [ "_side","_spawnPos","_patPos","_patType","_patMode","_respawnCount","_west","_east", "_independent","_sideArray","_faction","_typeArray","_sideSTR","_grpArray","_randomType","_cfgArray", "_randomGrp","_grp","_IOAI_EH","_patModeHandle","_debugHandle","_spawnDir" ]; _side = [_this, 0, sideUnknown, [sideUnknown]] call BIS_fnc_param; _spawnPos = [_this, 1, [0,0,0], ["",objNull,[]], [2,3]] call BIS_fnc_param; _patPos = [_this, 2, _spawnPos, ["",objNull,[]], [2,3]] call BIS_fnc_param; _patType = [_this, 3, 4, [-1]] call BIS_fnc_param; _patMode = [_this, 4, 0, [-1]] call BIS_fnc_param; _respawnCount = [_this, 5, 0, [-1]] call BIS_fnc_param; _debug = [_this, 6, false, [true]] call BIS_fnc_param; if ( { side _x == east } count allUnits == 0 ) then {_east = createCenter east;}; if ( { side _x == west } count allUnits == 0 ) then {_west = createCenter west;}; if ( { side _x == independent } count allUnits == 0 ) then {_independent = createCenter independent;}; if ( _side == sideUnknown ) then { _sideArray = [west,east,independent]; _side = _sideArray select floor random count _sideArray; }; _faction = switch ( _side ) do { case west:{"BLU_F";}; case blufor:{"BLU_F";}; case east:{"OPF_F";}; case opfor:{"OPF_F";}; case resistance:{"IND_F";}; case independent:{"IND_F";}; default {"BLU_F";}; }; _spawnDir = switch ( typeName _spawnPos ) do { case "STRING":{markerDir _spawnPos;}; case "OBJECT":{getDir _spawnPos;}; case "ARRAY":{random 360;}; default {random 360;}; }; _spawnPos = switch ( typeName _spawnPos ) do { case "STRING":{getMarkerPos _spawnPos;}; case "OBJECT":{getPos _spawnPos;}; case "ARRAY":{_spawnPos;}; default {_spawnPos;}; }; _patPos = switch ( typeName _patPos ) do { case "STRING":{getMarkerPos _patPos;}; case "OBJECT":{getPos _patPos;}; case "ARRAY":{_patPos;}; default {_patPos;}; }; _typeArray = switch _patType do { case 0:{ ["Infantry"]; }; case 1:{ if ( _faction == "OPF_F" ) then { ["Motorized_MTP"]; } else { ["Motorized"]; }; }; case 2:{ ["Mechanized"]; }; case 3:{ ["Armored"]; }; case 4:{ if ( _faction == "OPF_F" ) then { ["Motorized_MTP","Infantry","Mechanized", "Armored"]; } else { ["Motorized","Infantry","Mechanized", "Armored"]; }; }; default { ["Infantry"]; }; }; _sideSTR = if ( _side in [ blufor, opfor, independent, resistance ] ) then { switch _side do { case blufor:{"west";}; case opfor:{"east";}; case independent:{"indep";}; case resistance:{"indep";}; }; } else { str _side; }; _grpArray = []; _randomType = ( _typeArray select floor random count _typeArray ); _cfgArray = "_grpArray pushBack (configName _x)" configClasses (configfile >> "CfgGroups" >> _sideSTR >> _faction >> _randomType); _randomGrp = ( _grpArray select floor random count _grpArray ); _grp = [ _spawnPos, _side, ( configFile >> "CfgGroups" >> _sideSTR >> _faction >> _randomType >> _randomGrp ), nil, nil, nil, nil, [2,random 1], _spawnDir ] call BIS_fnc_spawnGroup; IOAI_BD = { sleep 60; deleteVehicle ( _this select 0 ); }; _IOAI_EH = { { _x addEventhandler ["killed", {_this spawn IOAI_BD;}]; } forEach ( units _grp ); }; _patModeHandle = { switch _patMode do { case 0:{[_grp, _patPos, 50 + random 150] call bis_fnc_taskPatrol;}; case 1:{[_grp, _patPos] call BIS_fnc_taskDefend;}; case 2:{[_grp, _patPos] call BIS_fnc_taskAttack;}; case 3:{ [ [_grp, _patPos, 50 + random 150] call bis_fnc_taskPatrol, [_grp, _patPos] call BIS_fnc_taskDefend, [_grp, _patPos] call BIS_fnc_taskAttack ] call BIS_fnc_selectRandom; }; default {[_grp, _patPos, 50 + random 150] call bis_fnc_taskPatrol;}; }; if ( true ) exitWith {}; }; _debugHandle = { if ( _debug ) then { [_grp] spawn { private ["_markerArray", "_mrk", "_grp","_color"]; _grp = _this select 0; _markerArray = []; _color = [side (leader _grp), true] call BIS_fnc_sideColor; { _mrk = createMarker [ format ["marker%1", random 10000], getPosATL _x]; _mrk setMarkerShape "ICON"; _mrk setMarkerType "mil_dot"; _mrk setMarkerColor _color; _markerArray pushBack [_mrk, _x]; } forEach ( units _grp ); while { true } do { { if ( alive ( _x select 1 ) ) then { ( _x select 0 ) setMarkerPos getPosATL ( _x select 1 ); } else { deleteMarker ( _x select 0 ); _markerArray deleteAt _foreachIndex; }; } forEach _markerArray; if ( count _markerArray == 0 ) exitWith {}; sleep 0.1; }; }; }; if ( true ) exitWith {}; }; _nul = call _patModeHandle; _nul = call _debugHandle; _nul = call _IOAI_EH; if ( _respawnCount > 0 ) then { for "_i" from 0 to _respawnCount - 1 do { waitUntil { sleep 5; { alive _x } count units _grp == 0;}; _grp = [ _spawnPos, _side, ( configFile >> "CfgGroups" >> _sideSTR >> _faction >> _randomType >> _randomGrp ), nil, nil, nil, nil, [2,random 1], _spawnDir ] call BIS_fnc_spawnGroup; _nul = call _patModeHandle; _nul = call _debugHandle; _nul = call _IOAI_EH; }; }; if ( true ) exitWith {}; Edited November 3, 2014 by Iceman77 Rewrote the entire function Share this post Link to post Share on other sites
iceman77 18 Posted October 29, 2013 Updated example mission to spawn the hunter group in a different location than the patrol group. As to avoid potential explosions! Share this post Link to post Share on other sites
iceman77 18 Posted December 3, 2013 Major overhaul. Easier to use (less parameters required). Share this post Link to post Share on other sites
anthonyfromtheuk 6 Posted December 4, 2013 Works like a charm, thanks for sharing! Share this post Link to post Share on other sites
akm74 1 Posted December 4, 2013 amazing, thanks man Share this post Link to post Share on other sites
iceman77 18 Posted December 4, 2013 Thanks guys. Does anyone know how to get rid of the word wrap when I'm posting code here in php? ---------- Post added at 09:50 ---------- Previous post was at 09:04 ---------- Small update. Side parameter isn't even required now. Only a spawn marker (string) & patrol radius (number) are required. The side that is spawned will be based off of the color of the spawn marker. Acceptable marker colors are: - ColorWEST (Editor >> Color: BLUFOR) - ColorEAST (Editor >> Color: OPFOR) - ColorGUER (Editor >> Color: Independent) Share this post Link to post Share on other sites
Guest Posted December 4, 2013 New version frontpaged on the Armaholic homepage. Simple Patrol Script ================================================ We have also "connected" these pages to your account on Armaholic. This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have. When you have any questions already feel free to PM or email me! Share this post Link to post Share on other sites
iceman77 18 Posted December 7, 2013 Updated: - Added in optional SAD mode (moves group to a given area instead of patrolling) - Defining the side is required again. After some thought, I think it's better this way. ---------- Post added at 10:30 ---------- Previous post was at 10:05 ---------- oops, small hot fix: added missing argument to the cycle mode spawn. Share this post Link to post Share on other sites
3lockad3 11 Posted December 7, 2013 I like this one. So when they are dead they are dead ? I do not have to step on grid ? Can they be triggered ? Share this post Link to post Share on other sites
iceman77 18 Posted December 7, 2013 (edited) Yeah you can spawn the function anywhere, including triggers. There is also a cycle mode, where if the group dies, it will automatically recreate another random group. You can read the listed parameters and the usage examples in the comment to gain an better understanding. Edited December 7, 2013 by Iceman77 Share this post Link to post Share on other sites
Guest Posted December 7, 2013 Thanks for the headsup about the update ;cool: New version frontpaged on the Armaholic homepage. Simple Patrol Script v1.2 ================================================ We have also "connected" these pages to your account on Armaholic. This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have. When you have any questions already feel free to PM or email me! Share this post Link to post Share on other sites
3lockad3 11 Posted December 8, 2013 Ya I spent a couple hrs playing with it and I love it! I have a pretty good idea how to implement it in my missions. Nicely done! Now to play with the pools! :D Share this post Link to post Share on other sites
DaViSFiT 21 Posted December 8, 2013 Will be Headless client implemented in a future release? :P Share this post Link to post Share on other sites
major woody 11 Posted January 18, 2014 This is indeed a very nice script - however I try to make mechInf units board the vehicle before moving, but with no luck, the group just stops and freezes :( - any idea what's wrong...? _loadWp = _grp addWaypoint [getMarkerPos _spawnPos, 0]; _loadWp setWaypointType "LOAD"; _infWp = _grp addWaypoint [getMarkerPos _movePos, 0]; _infWp setWaypointType "SAD"; _infWp setWaypointBehaviour "AWARE"; _infWp setWaypointCombatMode "RED"; _infWp setWaypointSpeed "FULL"; Share this post Link to post Share on other sites
iceman77 18 Posted January 18, 2014 Never really messed with the load waypoint, but I believe units will automatically board any vehicle in the group based on the distance of their waypoint. Share this post Link to post Share on other sites
major woody 11 Posted January 19, 2014 I believe units will automatically board any vehicle in the group based on the distance of their waypoint. As did I - but that's not the fact - It would be very sweet to have both Motorized and Mechanized units embarking their vehicles before they move on... Share this post Link to post Share on other sites
major woody 11 Posted January 20, 2014 So far I'm very impressed with this script - however, would it be possible having several groups spawning at several markers at the beginning - like so: [EAST, "spawnMarker1", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker2", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker3", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker4", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker5", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker6", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker7", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker8", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker9", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos [EAST, "spawnMarker10", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos This is an ugly way (I know) - would there be any smarter way...? :) Share this post Link to post Share on other sites
iceman77 18 Posted January 20, 2014 What's wrong with the way you've called the functions? :confused: Share this post Link to post Share on other sites
major woody 11 Posted January 21, 2014 It only spawns at spawnMarker1 - never spawns the rest ... [EAST, "spawnMarker1", "moveMarker1", false, true, true] call TAG_Grp_Spawn; // patrol mode disabled, group will move to marker pos Share this post Link to post Share on other sites
iceman77 18 Posted January 21, 2014 I'll have a look ... Share this post Link to post Share on other sites
iceman77 18 Posted October 28, 2014 Rewrote this very old patrol script. Cheers. Share this post Link to post Share on other sites
epicgoldenwarrior 11 Posted October 30, 2014 Assuming it shouldnt be that different, can you do one with unarmed civilians (civ faction) and civ cars? It would be great to be able to fill a city this easily and have it animated. Share this post Link to post Share on other sites
jshock 513 Posted October 30, 2014 Assuming it shouldnt be that different, can you do one with unarmed civilians (civ faction) and civ cars? It would be great to be able to fill a city this easily and have it animated. Or use this: http://www.armaholic.com/page.php?id=23644 Share this post Link to post Share on other sites
epicgoldenwarrior 11 Posted October 30, 2014 Curious, would that work on custom maps? Btw looks great, thanks Share this post Link to post Share on other sites
jshock 513 Posted October 30, 2014 You would have to go in and change a few lines of code around, I tried way back a few months ago, but whatever. In any case, sorry for stealing your thread Iceman, this will be the last off-topic post :p. Share this post Link to post Share on other sites