Stoll

Spawn units with script

4 posts in this topic

Heya folks!

I have a problem which really drive my nuts.
I spawn a weapon box with a script at a random position. Works fine.
I want 4 units spawn next to it.
For that I placed them in Eden Editor, converted the data to M3Editor and used Silent Map Converter to get the code I need:

 

Quote


_group0 = createGroup east;
	_unit1 = _group0 createUnit ["O_diver_TL_F",_randPos,[],0,"FORM"];
		if (isNull _unit1) then {
			_unit1 = createVehicle ["O_diver_TL_F",_randPos,[],0,"FORM"];
 			createVehicleCrew _unit1;
		};
		(group _unit1) selectLeader _unit1;
		_unit1 setPosATL _randPos;
		_unit1 setSkill 0.4;
_group1 = createGroup east;
	_unit2 = _group1 createUnit ["O_diver_exp_F",[(_randPos select 0)+1,(_randPos select 1)-1,0],[],0,"FORM"];
		if (isNull _unit2) then {
			_unit2 = createVehicle ["O_diver_exp_F",[(_randPos select 0)+1,(_randPos select 1)-1,0],[],0,"FORM"];
 			createVehicleCrew _unit2;
		};
		(group _unit2) selectLeader _unit2;
		_unit2 setPosATL [(_randPos select 0)+1,(_randPos select 1)-1,0];
		_unit2 setSkill 0.4;
_group2 = createGroup east;
	_unit3 = _group2 createUnit ["O_diver_F",[(_randPos select 0)-2,(_randPos select 1)-1,0],[],0,"FORM"];
		if (isNull _unit3) then {
			_unit3 = createVehicle ["O_diver_F",[(_randPos select 0)-2,(_randPos select 1)-1,0],[],0,"FORM"];
 			createVehicleCrew _unit3;
		};
		(group _unit3) selectLeader _unit3;
		_unit3 setPosATL [(_randPos select 0)-2,(_randPos select 1)-1,0];
		_unit3 setSkill 0.4;
_group3 = createGroup east;
	_unit4 = _group3 createUnit ["O_diver_F",[(_randPos select 0)-1,(_randPos select 1)-3,0],[],0,"FORM"];
		if (isNull _unit4) then {
			_unit4 = createVehicle ["O_diver_F",[(_randPos select 0)-1,(_randPos select 1)-3,0],[],0,"FORM"];
 			createVehicleCrew _unit4;
		};
		(group _unit4) selectLeader _unit4;
		_unit4 setPosATL [(_randPos select 0)-1,(_randPos select 1)-3,0];
		_unit4 setSkill 0.4;

 

First I tried one group with 4 units and ended up with 4 groups and each 1 unit in it...however...

The issue now is....all 4 units spawn in, but only 1 will stay alive. All others die instantly!
The script is packed in a PBO, the same for packing additional map content.
I also tried to call it from the init.sqf with the same result.

Why the hell are the 3 units dying ??
Maybe there is a better solution for spawning AI with a script?
Played around with BIS_fnc_spawnGroup, but wasn't able to get this working.

Damn :swear:

 

1 person likes this

Share this post


Link to post
Share on other sites

You need to set them all to have the same faction / side or they will kill each other. Which is what I suspect is happening. 

https://community.bistudio.com/wiki/Side_relations

This example below would force all _units or whatever variable you used to define the units to join the same group as everyone else. This should stop them killing each other if that's what's going on.

[_unit] joinSilent _group;

 

2 people like this

Share this post


Link to post
Share on other sites
Advertisement

That worked!
I LOVE YOU! xD

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.