Jump to content
BeaniePope.

Getting units to spawn on marker through function

Recommended Posts

Heyo!

Here's the plan:

I would like units to spawn on a marker via a function call during initServer.
Spawning works!
The units do spawn, but they spawn at 0, 0. why? Because the script doesn't recognize the "_markerCordon" marker from the mission, and returns the default value when getMarkerPos is called-

I would love if someone could let me know how exactly I'm supposed to pass my marker (or at least my marker position) to my function, assuming I can- thank you!

initServer

(this works fine)

call AZN_fnc_spawnMutantsCordon;



fn_spawnMutantsCordon below

don't mind the commenting, this is made to be plug and play for a friend. Base units for testing and one modded unit also for testing.
 

_mutantGroup = ["B_Soldier_F", "B_Pilot_F", "B_Survivor_F", "armst_blinddog2"];

private _marker = "_markerCordon";
private _mutantCount = 3; // Counting starts from 0 ex: _mutantCount = 3 spawns 4 mutants

// -- DO NOT TOUCH BELOW THIS CON -- //
private _finalPosition = [0,0,0];
private _markerPosition = [0, 0, 0];

//Gets Marker
_markerPosition = getMarkerPos _marker;
_markerPositionX =  _markerPosition select 0;
_markerPositionY =  _markerPosition select 1;

//Randomizes pos
_randomX = [-100, 100] call BIS_fnc_randomInt;
_randomY = [-100, 100] call BIS_fnc_randomInt;
_finalPosition set [0 , _markerPositionX  + _randomX];
_finalPosition set [1 , _markerPositionY  + _randomY];


   

//Spawns units
for "_i" from 0 to _mutantCount do 
{ 
	private _cordonMutants = createGroup [west, true]; 
	_unit = _mutantGroup select _i;
	_position = _finalPosition;
	_positionX = _position select 0;
	_positionY = _position select 1;
	_position set [0, _positionX + _i];
	_position set [1, _positionY + _i];
	_unit createUnit [_position, _cordonMutants];
};

 

Share this post


Link to post
Share on other sites

Hi, this might help:

private _spawnPoint = getMarkerPos "_markerCordon"; //The midpoint (marker) at which units are spawned.
private _amount = 3; //The amount of units to spawn.
private _radius = 30; //The radius in which the units are spawned (from the midpoint).
private _unitTypes = ["B_Soldier_F", "B_Pilot_F", "B_Survivor_F", "armst_blinddog2"]; //the types(classnames) of units to be spawned (see CfgVehicles e.g. https://community.bistudio.com/wiki/Arma_3:_CfgVehicles_EAST)
//You can see the class name in the editor if you hover over the unit in the list on the left.
//or you get the class name with "typeOf" e.g.: typeOf player
private _group = createGroup east; //The group into which the units are spawned.(Determines the side)

for [{private _i = 0}, {_i < _amount}, {_i = _i + 1;}] do {
	private _randomTyp = selectRandom _unitTypes; //the typ of Unit to be spawned
	private _myAI = _group createUnit [_randomTyp, [0,0,0], [], 0, "NONE"]; //spawn the unit at the first available free position nearest to [0,0,0]
	private _randomPos = (_spawnPoint getPos [_radius * sqrt random 1, random 4000]);
	_myAI setPosATL (_randomPos); //sets the position relative to the terrain.
	[_myAI, (random 360)] remoteExec ["setDir"]; //set a random dir
};

 

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, Joshua9797 said:

Hi, this might help:


private _spawnPoint = getMarkerPos "_markerCordon"; //The midpoint (marker) at which units are spawned.
private _amount = 3; //The amount of units to spawn.
private _radius = 30; //The radius in which the units are spawned (from the midpoint).
private _unitTypes = ["B_Soldier_F", "B_Pilot_F", "B_Survivor_F", "armst_blinddog2"]; //the types(classnames) of units to be spawned (see CfgVehicles e.g. https://community.bistudio.com/wiki/Arma_3:_CfgVehicles_EAST)
//You can see the class name in the editor if you hover over the unit in the list on the left.
//or you get the class name with "typeOf" e.g.: typeOf player
private _group = createGroup east; //The group into which the units are spawned.(Determines the side)

for [{private _i = 0}, {_i < _amount}, {_i = _i + 1;}] do {
	private _randomTyp = selectRandom _unitTypes; //the typ of Unit to be spawned
	private _myAI = _group createUnit [_randomTyp, [0,0,0], [], 0, "NONE"]; //spawn the unit at the first available free position nearest to [0,0,0]
	private _randomPos = (_spawnPoint getPos [_radius * sqrt random 1, random 4000]);
	_myAI setPosATL (_randomPos); //sets the position relative to the terrain.
	[_myAI, (random 360)] remoteExec ["setDir"]; //set a random dir
};

 

For whatever reason, this works! Thank you!

  • Like 1

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

×