Jump to content
tissue901

Spawning units on a specific team

Recommended Posts

I have created a script that will randomly spawn units, give them a random spawn point within a radius from a marker, and then add 4 random waypoints to randomly walk around. My issue is that all the units I create are showing to be on the team of the player which makes no sense. I would like them to fight back when I give them a gun.

 

Here is part of my code:

// Ensure all sides are setup
createCenter resistance;
sleep 5;

// Loop through each spawn and create civilians
{
	// Make sure we have 3 parameters
	if(count _x == 3) then {
		_spawnName = _x select 0;
		_spawnRadius = _x select 1;
		_spawnNumber = _x select 2;
		
		for "_civId" from 0 to _spawnNumber do {
	
			// Create a new group for every civilian
			_grp = createGroup resistance;
			
			// Make them fire at will
			_grp setCombatMode "RED";
			
			_isCC = random 1 > 1 - CC_PROBABILITY;
			
			_randomSpawnPoint = [getMarkerPos _spawnName, _spawnRadius, random 360] call BIS_fnc_relPos;
			
			// Create the unit at the random position on the insurgents side
			_unitType = if(_isCC) then [{"I_G_Soldier_F"}, {"I_G_Soldier_lite_F"}];
			_civilian = _grp createUnit [_unitType, _randomSpawnPoint,[],1,""];

			[_civilian] join _grp;
			
			_grp selectLeader _civilian;
			
			if(_isCC) then {
				_civilian setVariable ["_shotsBeforeDrawing", random CC_MAX_SHOTS, true];
			};
			
			// Generate some random waypoints so they walk around aimlessly
			for "_waypointId" from 0 to NUM_WAYPOINTS do {
				_waypoint = _grp addWaypoint [[_civilian, random _spawnRadius, random 360] call BIS_fnc_relPos,0];
			
				_waypoint setWaypointBehaviour "AWARE";
				_waypoint setWaypointSpeed "LIMITED";
				_waypoint setWaypointType "MOVE";
				
				if(NUM_WAYPOINTS == _waypointId) then {
					_waypoint setWaypointType "CYCLE";
				}
			};
			
			// Remove defaults
			removeAllWeapons _civilian;
			removeAllItems _civilian;
			removeAllAssignedItems _civilian;
			removeUniform _civilian;
			removeVest _civilian;
			removeBackpack _civilian;
			removeHeadgear _civilian;
			removeGoggles _civilian;
			
			// Assign Random Clothes
			_civilian forceAddUniform selectRandom _cuniforms;
			
			if(random 1 > .5) then {
				_civilian addHeadgear selectRandom _cheadgear;
			};
			
			if(random 1 > .5) then {
				_civilian addGoggles selectRandom _cgoggles;
			};
			
			{
				_x globalChat format["side %1 %2", side _civilian];
			} forEach allPlayers;
		};
	}

} forEach _civilianSpawn;

I have a globalPrint statement in here and it seems to report the correct side for the _civilian variable. Issue is later I get all objects in a radius from me, and that shows that they are on my team. I also believe they are on my team because they dont shoot back at me, I can be standing right next to them, and they will just run away.

 

if !(isServer) exitWith {};
_player = _this select 0;
_list = position _player nearObjects ["I_G_Soldier_F", 25];

if(count _list > 0) then {
	{
		{
			_x globalChat format["side %1 %2", side _x, side _player];
		} forEach allPlayers;
	} forEach _list;
};

 

Edited by tissue901

Share this post


Link to post
Share on other sites

You are using resistance as the enemy and I assume blufor as your team? Have you checked that resistance is actually set as enemy to blufor in the mission settings?

Share this post


Link to post
Share on other sites

@tissue901 As mrcurry mentioned you need to set the resistance (independent) as Blufor's NME's. You can easily do this in the Eden editor at top menu, go to multiplayer settings and you will be able to change it there

Share this post


Link to post
Share on other sites

Sorry I forgot to mention that I do have them set to enemy. Originally I was setting it in code to change the team relations based on certain events:

if([resistance, west] call BIS_fnc_sideIsFriendly) then {
    resistance setFriend [west, 0];
    west setFriend [resistance, 0];
};

Even if I spawn them as EAST, and the player as WEST, they all come up on the WEST team and wont fight me back.

 

Here is my updated code:

 

init.sqf

if !(isServer) exitWith {};

NUM_WAYPOINTS = 4;
CC_PROBABILITY = 1;
CC_MAX_SHOTS = 15;

shotsFired = 0;

// Specify where spawns are and how many citizens [name, radius, # civs]
_civilianSpawn = [["civspawn1",30,20]];

// Setup citizen clothing
_cuniforms = ["TRYK_SUITS_BLK_F","U_C_Poor_1","U_PMC_GrnPolo_BgPants","U_PMC_WhtPolo_BgPants","U_PMC_RedPlaidShirt_DenimCords","U_PMC_BrnPolo_BluPants","U_PMC_BluePlaidShirt_BeigeCords","U_PMC_BluTShirt_SJeans","U_PMC_BlckPolo_BluPants","U_PMC_BlckPolo_BgPants","U_PMC_BgPolo_GrnPants","TRYK_SUITS_BR_F","TRYK_U_B_Denim_T_BK","TRYK_U_B_RED_T_BR","TRYK_U_B_BLK_T_BK","TRYK_U_pad_j","TRYK_U_denim_jersey_blk","TRYK_shirts_DENIM_od","TRYK_shirts_DENIM_WHB","TRYK_shirts_DENIM_WH","TRYK_shirts_DENIM_RED2","TRYK_shirts_DENIM_R","TRYK_shirts_DENIM_BWH","TRYK_shirts_DENIM_BK","TRYK_shirts_DENIM_ylb","TRYK_U_B_PCUGs_gry","TRYK_U_B_PCUGs_OD_R","TRYK_U_B_BLK_TAN_2","TRYK_U_B_C02_Tsirt","U_C_Man_casual_5_F","U_C_Man_casual_4_F","U_C_Man_casual_6_F","U_C_man_sport_2_F","U_C_man_sport_3_F","U_C_man_sport_1_F","U_Rangemaster","U_Marshal","U_C_Journalist","U_OrestesBody","U_BG_Guerilla2_3","U_BG_Guerilla2_1","U_BG_Guerilla2_2","U_Competitor","U_C_Poloshirt_tricolour","U_C_Poloshirt_stripped","U_C_Poloshirt_salmon","U_C_Poloshirt_redwhite","U_C_Poloshirt_burgundy","U_C_Poloshirt_blue","U_C_Man_casual_1_F","U_C_Man_casual_3_F","U_C_Man_casual_2_F","U_I_C_Soldier_Bandit_5_F","U_I_C_Soldier_Bandit_2_F","U_I_C_Soldier_Bandit_1_F","U_I_C_Soldier_Bandit_4_F","rhs_uniform_df15_tan","rhs_uniform_df15"];
_cgoggles = ["G_Aviator","murshun_cigs_cig2","G_Shades_Black","G_Shades_Blue","G_Spectacles","G_Sport_Red","G_Sport_Greenblack","G_Squares_Tinted","G_Spectacles_Tinted","TRYK_Beard_BK","TRYK_Beard_BW","TRYK_Beard3"];
_cheadgear = ["VSM_Beanie_Black","VSM_Beanie_OD","VSM_Beanie_Tan","H_Bandanna_gry","H_Bandanna_blu","H_Bandanna_surfer","rhsgref_bcap_specter","H_Capbw_pmc","H_Cap_pmc","H_Booniehat_rgr","H_Booniehat_khk","H_Cap_grn_BI","H_Cap_blk","H_Cap_blu","H_Cap_blk_CMMG","H_Cap_grn","H_Cap_blk_ION","H_Cap_red","H_Cap_surfer","H_Cap_usblack","H_Cap_tan","H_Hat_blue","H_Hat_brown","H_Hat_tan","H_Hat_checker","H_StrawHat","H_Capbw_tan_pmc","TRYK_r_cap_blk_Glasses","TRYK_r_cap_od_Glasses","TRYK_r_cap_tan_Glasses"];

sleep 1;

// Ensure all sides are setup
createCenter resistance;

// Loop through each spawn and create civilians
{
	// Make sure we have 3 parameters
	if(count _x == 3) then {
		_spawnName = _x select 0;
		_spawnRadius = _x select 1;
		_spawnNumber = _x select 2;
		
		for "_civId" from 0 to _spawnNumber do {
	
			// Create a new group for every civilian
			_grp = createGroup resistance;
			
			// Make them fire at will
			_grp setCombatMode "RED";
			
			_isCC = random 1 > 1 - CC_PROBABILITY;
			
			_randomSpawnPoint = [getMarkerPos _spawnName, _spawnRadius, random 360] call BIS_fnc_relPos;
			
			// Create the unit at the random position on the insurgents side
			_unitType = if(_isCC) then [{"I_G_Soldier_F"}, {"I_G_Soldier_lite_F"}];
			_civilian = _grp createUnit [_unitType, _randomSpawnPoint,[],1,""];

			[_civilian] joinSilent _grp;
			
			_grp selectLeader _civilian;
			
			if(_isCC) then {
				_civilian setVariable ["_shotsBeforeDrawing", random CC_MAX_SHOTS, true];
			};
			
			// Generate some random waypoints so they walk around aimlessly
			for "_waypointId" from 0 to NUM_WAYPOINTS do {
				_waypoint = _grp addWaypoint [[_civilian, random _spawnRadius, random 360] call BIS_fnc_relPos,0];
			
				_waypoint setWaypointBehaviour "AWARE";
				_waypoint setWaypointSpeed "LIMITED";
				_waypoint setWaypointType "MOVE";
				
				if(NUM_WAYPOINTS == _waypointId) then {
					_waypoint setWaypointType "CYCLE";
				}
			};
			
			// Remove defaults
			removeAllWeapons _civilian;
			removeAllItems _civilian;
			removeAllAssignedItems _civilian;
			removeUniform _civilian;
			removeVest _civilian;
			removeBackpack _civilian;
			removeHeadgear _civilian;
			removeGoggles _civilian;
			
			// Assign Random Clothes
			_civilian forceAddUniform selectRandom _cuniforms;
			
			if(random 1 > .5) then {
				_civilian addHeadgear selectRandom _cheadgear;
			};
			
			if(random 1 > .5) then {
				_civilian addGoggles selectRandom _cgoggles;
			};
			
			{
				_x globalChat format["SPAWN CITIZEN | side %1 faction %2", side _civilian, faction _civilian];
			} forEach allPlayers;
		};
	}

} forEach _civilianSpawn;

if(!isDedicated) then {
	{
		_x addEventHandler ["fired", {_this execVM "concealCarry.sqf"}];
	} forEach allPlayers;
};

 

concealCarry.sqf

if !(isServer) exitWith {};

_player = _this select 0;

_list = position _player nearObjects ["I_G_Soldier_F", 25];

_cguns = [["RH_g17","RH_17Rnd_9x19_g17"],["rhsusf_weap_m9","rhsusf_mag_15Rnd_9x19_JHP"],["hgun_Rook40_F","16Rnd_9x21_Mag"],["rhs_weap_makarov_pm","rhs_mag_9x18_8_57N181S"],["RH_p226","RH_15Rnd_9x19_SIG"],["RH_fn57","RH_20Rnd_57x28_FN"]];

if(count _list > 0) then {

	if([resistance, west] call BIS_fnc_sideIsFriendly) then {
		resistance setFriend [west, 0];
		west setFriend [resistance, 0];
	};
	
	{
		private _shotsBeforeDrawing = _x getVariable "_shotsBeforeDrawing";
		
		if(!isNil "_shotsBeforeDrawing") then {
		
			{
				_x globalChat format["NEAR OBJECTS | side civ %1 faction civ %2 | side player %3 faction player %4", side _x, faction _x, side _player, faction _player];
			} forEach allPlayers;
			
			if(_shotsBeforeDrawing > 0) then {
				if(_this select 3 == "Single") then {
					_x setVariable ["_shotsBeforeDrawing", _shotsBeforeDrawing - .5, true];
				} else {
					_x setVariable ["_shotsBeforeDrawing", _shotsBeforeDrawing - .1, true];
				};
			} else {
				_gunInfo = selectRandom _cguns; 
				_pistol = _gunInfo select 0;
				_ammo = _gunInfo select 0;
				_x addWeapon _pistol;
				_x addItemToUniform _ammo;
				
				_grp = group _x;
				
				{
					deleteWayPoint _x;
				} forEach waypoints _grp;
				
				_wp = _grp addWaypoint [position _x, 100];
				_wp setWaypointType "HOLD";
				_wp setWaypointStatements ["true", ""];
				_wp setWaypointSpeed "limited"; 
				_wp setWaypointBehaviour "COMBAT";
				
				// Make em a little quicker
				_x setSkill ["aimingspeed", 0.3];
				_x setSkill ["spotdistance", 1];
				_x setSkill ["aimingaccuracy", 0.2];
				_x setSkill ["aimingshake", 0.1];
				_x setSkill ["spottime", 1];
				_x setSkill ["commanding", 0.2];
				_x setSkill ["general", 1];
				_x setSkill ["courage", 1];
				
				_x allowFleeing 0;
			};
		};
		
	} forEach _list;
};

 

Basically this makes civilians have the chance of drawing a pistol if they are shot at enough which is working. Its just they wont fight back and appear to be on my team.

 

In the init.sqf you'll see I have a globalChat call that prints the side of the civilian spawned. Here it is correct:

init.png

 

But later on, when I fire my gun it shows that the citizen is on the same team as me, and in the picture he is running away from me. 

concealcarry.png

 

 

I'm pulling my hair out of this because it doesnt make any sense to me. I can follow them as much as I want and they never fire back. 

Share this post


Link to post
Share on other sites
7 minutes ago, tissue901 said:

I'm pulling my hair out of this because it doesnt make any sense to me. I can follow them as much as I want and they never fire back. 

 

Hi

sorry if this is obvious question but what side are you?

 

Share this post


Link to post
Share on other sites

Just tested this, player as blufor rifleman, resistance set to enemy against blufor and opfor with the editor settings under Attributes -> General -> Misc.

Spawned units were hostile to me.

 

Cheers

Share this post


Link to post
Share on other sites
3 minutes ago, tissue901 said:

I am bluefor. Spawning an independent with a gun through the editor and they will shoot at me, but the civilians will just stare at me:

http://zyphox.com/arma/bluefor.png

http://zyphox.com/arma/stare.png

 

Civilians are usually neutral and they would never fire on anyone, however you can try and shoot two or 3 civs and see how the others react to you

Share this post


Link to post
Share on other sites

Im not spawning them in the civilian group, they are being created under resistance and I just am changing their loadout to look like a civilian.

createCenter resistance;
_grp = createGroup resistance;

 

Also if I killed 15 of them the other ones just still sit there staring at me... I just don't get what is going on at all. I could upload my mission file if someone with APEX could take a look at it.

Share this post


Link to post
Share on other sites
Just now, tissue901 said:

Im not spawning them in the civilian group, they are being created under resistance and I just am changing their loadout to look like a civilian.

in this case, the last possibility I can come up with is they react this way due to the firearm they are using compared to yours since I do see you have given them ammunition it is definitely not lack of ammunition.

 

Best Regards,

Share this post


Link to post
Share on other sites

Do you have any mods installed that may be interfering?

Do you have any other scripts running (like maybe an incognito/stealth script) that may be interfering with side alliances?

It sounds like a 'fired' handler is changing the friendliness of resistance and altering the behavior you see in your script.

Have you tried running just this code in an isolated test case?

 

Another thing comes to mind - are the ai fleeing / surrendering?

 

I believe that when ai are captive they change sides. It would be a good idea to check if the ai is not your captive / is fleeing / is surrendered

Share this post


Link to post
Share on other sites
5 minutes ago, BlacKnightBK said:

in this case, the last possibility I can come up with is they react this way due to the firearm they are using compared to yours since I do see you have given them ammunition it is definitely not lack of ammunition.

 

Best Regards,

 

Hmm, interesting I give them the same weapon as me then they will fire back so I think you're correct on that. Is there anyway I can disable their decision making of this "hey this other guy has a better gun"? Maybe with disableAI?

Share this post


Link to post
Share on other sites

I'm really dumb... When I was picking which pistol to give them, I never actually gave them ammo as I tried assigning the pistol as the ammo:

_pistol = _gunInfo select 0;
_ammo = _gunInfo select 0;

This is what you get for trying to code at 4am. Thanks for helping me narrow it down!

 

Share this post


Link to post
Share on other sites
43 minutes ago, tissue901 said:

I'm really dumb... When I was picking which pistol to give them, I never actually gave them ammo as I tried assigning the pistol as the ammo:


_pistol = _gunInfo select 0;
_ammo = _gunInfo select 0;

This is what you get for trying to code at 4am. Thanks for helping me narrow it down!

 

 

And what you get for me answering while ill, sleepy and in 8 pm class. I never noticed you were not exactly giving them ammo, you just initialized a variable ammo. I am sorry man My bad

  • 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

×