Jump to content
Sign in to follow this  
ben_s

Spawning Units?

Recommended Posts

Hey, is there a way I can script a helicopter or unit to spawn around me at a random point within X and X meters. Then come towards my position once spawned? Or a group?

I did a very quick search, and nothing came up as to how to do a simple spawning script. So Ive made this....

Sorry if theres already a similar thread.

---------- Post added at 12:01 AM ---------- Previous post was at 12:00 AM ----------

Oh yes, Im talking about A2, not OA. If that makes a difference. ;)

Share this post


Link to post
Share on other sites

Yeah search for bis_fnc_spawngroup. You can also try Drapers airsupport beta scripts here.

Here is a rotor-wing (CAS) that I am working on, save as cas.sqf in a notepad:

waituntil {!isnil "bis_fnc_init"};

if (casActive) exitWith {hint "Rotor-wing (CAS) is unavailable!"};

casActive = true;
publicVariable "casActive";

openMap [true,true];
["(Left click) on the map where you want the Close Air Support.",0,.1,2,0,.4] call bis_fnc_dynamictext;
_Rdrop = createMarkerLocal ["Rdrop", [0,0,0]];
_Rdrop setMarkerShapeLocal "ICON";
"Rdrop" setMarkerTypeLocal "hd_destroy";
"Rdrop" setMarkerColorLocal "ColorRed";
"Rdrop" setMarkerTextLocal "Close Air Support";
onMapSingleClick {'Rdrop' setMarkerPosLocal _pos, Rdropclick = true};
waitUntil {Rdropclick};
onMapSingleClick {};
Rdropclick = false;
openMap [false,false];

_Rdrop 		= getMarkerPos "Rdrop";
_spwn 		= getPosATL pad;
_spwndir	= getdir pad; 

_westAircraft 	= 
[
["AH64D","AH-64 Apache"],
["AH1Z","AH-1Z Cobra"]
];

_rnd = floor random count _westAircraft;

_casgrp		= createGroup West;

_veh = createVehicle [(_westAircraft select _rnd) select 0, _spwn, [], 0, "FLY"];
_veh setpos [_spwn select 0,_spwn select 1,(_spwn select 2)+50];
_veh setdir _spwndir;
_veh setVelocity [sin(_spwndir)*55,cos(_spwndir)*55,0];

[_veh, _casgrp,false,"","USMC_Soldier_Pilot"] call BIS_fnc_spawnCrew;

_picture = getText (configFile >> "cfgVehicles" >> typeof _veh >> "picture");

hint parseText format["<img size='6' image='%2'/><br/> There is a %1 (CAS) inbound to your location!",(_westAircraft select _rnd) select 1, _picture];

sleep 5;
hint "";

[_casgrp, _Rdrop, 400] call BIS_fnc_taskPatrol;


_units = units _casgrp;


waitUntil
   { 	
_checkROT = FALSE;
if (!alive _veh) then {_checkROT = TRUE} else {_checkROT = FALSE};
if (getDammage _veh >= 0.8) then {_checkROT = TRUE} else {_checkROT = FALSE};
if ((fuel _veh) <= 0.2 ) then {_checkROT = TRUE} else {_checkROT = FALSE};
	if !(isengineon _veh) then {_checkROT = TRUE} else {_checkROT = FALSE};
if (getPosATL _veh select 2 <= 1) then {_checkROT = TRUE} else {_checkROT = FALSE};
_checkROT
   };


hint format ["The %1 (CAS) has been destroyed!", (_westAircraft select _rnd) select 1];

deleteMarkerLocal "Rdrop";

sleep (60 + random 60);

{deleteVehicle _x} forEach (_units)+[_veh]; deletegroup _casgrp;

casActive = false;

hint "Close Air Support is available.";
sleep 4;
hint "";

You need to place an empty invisible helicopter pad and name it pad. Place it somewhere on the map away from your unit. Place the functions module on the map as well.

Create a radio trigger and place this in the init line: nul=[] execVM "cas.sqf"

You can also add jets and it will automatically spawn in the pilots using the bis_fnc_spawncrew

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Ok, im familiar with scripting. But this is nothing like im familiar with. :S

Will go through it... Thanks :)

Share this post


Link to post
Share on other sites

Made an error in my script above, since you are not using OA I changed the pilot to a USMC pilot. Script above corrected.

If you are interested in airsupport scripts let me know and I will send you what I have been working on.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

This isn't related to CAS, but spawning units through the BIS function spawnGroup.

I am working on a sort of hold the house kind of mission, so wave after wave of increasingly difficult enemies. I know how to get the first wave going, but after that I am unsure how to get 2, then 3, and so on.

My preferred situation is this. Lets say the 1st wave of enemies is one group of 15 Takistani soldiers. They move towards the structure being defended, and then there was a firefight, and what I would like is to use floor random in a script so that once a random 12 of those 15 units are dead, wave 2 spawns and moves in, and the same thing happens.

spawnGroup1.sqf

_pos = getmarkerPos "enemygroup1";

_skill = [0.1, 0.5];

_side = EAST;

_units = ["TK_Soldier_SL_EP1", "TK_Soldier_EP1", "TK_Soldier_EP1", "TK_Soldier_GL_EP1", "TK_Soldier_AR_EP1", "TK_Soldier_EP1", "TK_Soldier_EP1", "TK_Soldier_EP1", "TK_Soldier_GL_EP1", "TK_Soldier_AR_EP1", "TK_Soldier_EP1", "TK_Soldier_AT_EP1", "TK_Soldier_EP1", "TK_Soldier_GL_EP1", "TK_Soldier_AR_EP1"];

_EnemyGroup1 = [_pos, _side, _units, [], [], _skill] call BIS_fnc_spawnGroup;

sleep 3;

{

_x setskill ["aimingAccuracy",0.15];

_x setskill ["spotDistance",0.75];

_x setskill ["spotTime",0.85];

_x setskill ["courage",0.65];

_x setskill ["commanding",0.85];

_x setskill ["aimingShake",0.15];

_x setskill ["aimingSpeed",0.55];

} foreach units _EnemyGroup1;

_ewp1 = _EnemyGroup1 addWaypoint [getMarkerpos "enemywp", 10];

_ewp1 = setWaypointType "SAD";

_ewp1 = setWaypointSpeed "NORMAL";

_ewp1 = setWaypointFormation "STAG COLUMN";

That is my wave 1. I am just unsure as to how to set this up. If the random bit is not possible, then just somehow executing spawngroup2.sqf once all of the 1st group is dead would work.

Share this post


Link to post
Share on other sites

Not that kind of random. I've already got groups setup with specific units.

Like I said, I want it so that once any 13 enemy soldiers are dead in a group of 15, somehow execute the script for wave 2 of enemies.

Share this post


Link to post
Share on other sites

setDir doesn't quit work for troops. :( They face the right direction for a moment but they turn their bodies. Why is that?

Share this post


Link to post
Share on other sites
setDir doesn't quit work for troops. :( They face the right direction for a moment but they turn their bodies. Why is that?

setDir is just an initialization thing, so thats what is there at the start. The AI probably turns because of his leader saying something or personal action.

Share this post


Link to post
Share on other sites
setDir doesn't quit work for troops. :( They face the right direction for a moment but they turn their bodies. Why is that?

Try setting a direction with setFormDir. This will set the leader's facing, which all units in the group will copy by default. To make an individual within a group look somewhere else, you need to take him out of formation (out of follow-the-leader mode) with doStop.

Share this post


Link to post
Share on other sites

Thanks!

I have another mystery to solve though: I spawn in a cargo container, which follows the tarrain, but if I use setdir to ahnge its direction, it will not.

Share this post


Link to post
Share on other sites

Tried doing cargo_container setPos (getPos cargo_container) after using setDir?

Share this post


Link to post
Share on other sites

Another one. Can I spawn a vehicle that alrady has the crew instead of spawning the vehicle and crew separately and moving the crew into the vehicle? Its a problem because i want a helicopter to pick up person but it only works if I place non-empty heli in editor.

Share this post


Link to post
Share on other sites

Hail. :notworthy: After a day of trial and error I finally have it. :D

Edit: Can I give the vehicle a name?

I'm afraid I'm gonna need to be able to name it.

Edited by ziiip

Share this post


Link to post
Share on other sites

I must be going crazy but this doesnt work now

wildcatcrew = createGroup West;

[getMarkerPos "marker7", 125, "AW159_Lynx_BAF", wildcatcrew] call bis_fnc_spawnvehicle;

I could get it to work yesterday but not now. :confused::confused: Plz someone point out the obvious mistake in the code that only I cant see. :icon_bash:

Share this post


Link to post
Share on other sites

My fault.^^ I should have mentioned you need to place the Function Manager Module, too.

The spawnVehicle function returns an array, where the first element is the vehicle:

wildcatcrew = createGroup West;
_vehicle = [getMarkerPos "marker7", 125, "AW159_Lynx_BAF", wildcatcrew] call bis_fnc_spawnvehicle;
wildcat = _vehicle select 0;

Now your spawned vehicle would be called wildcat.

Share this post


Link to post
Share on other sites

Wow thanks. :D Even able to name it, super.

Still I SWEAR when I first used it i didnt place any module and it sill worked. It made me mad why it wasnt working today.

Share this post


Link to post
Share on other sites

I wanted to use the group spawnin function, needless to say it didnt work. I placed a functions module.

Here's the code i copy/pasted from kylania's cool website.

GroupSquad1 = [getMarkerPos "Squad1", east, ["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","TK_INS_Soldier_AR_EP1","TK_Soldier_Medic_EP1","TK_Soldier_EP1","TK_Soldier_AA_EP1","TK_INS_Soldier_TL_EP1","TK_INS_Warlord_EP1","TK_INS_Soldier_MG_EP1"]] call BIS_fnc_spawnGroup;

Share this post


Link to post
Share on other sites

If you don't have any OPFOR units on the map, or you haven't created a Center for EAST yet, that code won't work.

Either place a 0% probability of presence OPFOR unit someone on the map or use the createCenter command to initialize the OPFOR side first.

Otherwise, that code you posted works just fine for me. :)

Share this post


Link to post
Share on other sites

Damn I forgot that. Thanks. :D This function is so great, so little code, so many enemies.

Share this post


Link to post
Share on other sites
Damn I forgot that. Thanks. :D This function is so great, so little code, so many enemies.

I think thats the point of the spawn functions. :bounce3:

Share this post


Link to post
Share on other sites

I did not want to start a new thread sooo... is this used for random spawn, too. At mission start up, I want to spawn my squad at a random positon anywhere on the (marked) map. I tried USPS, but I cannot get rid of the first waypoint (and that is annoying, for me, and what I want to do, but great script, though).

EDIT: I imagine there is something more simple than what was posted earlier in the thread, that's why I am asking (and yes I have searched, :p).

Edited by CyOp

Share this post


Link to post
Share on other sites

No need for scripts for random spawn. Simply group your squad with one or more markers. You'll spawn either where you're placed in the Editor or at one of the grouped marker locations automatically.

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  

×