Jump to content
Moon_chilD

Add Eventhandler to every spawned unit in a specific faction

Recommended Posts

Hey,
I want to have a Module in my mission that when its placed adds an eventhandler to every unit in a specific faction. So far that shouldn't be to hard, however what I don't manage to think of right now is, how do I make sure that even units placed by Zeus get this Eventhandler?

So the code should be something like this: 

if ((faction _unit) in _factionList) then {
 CODE TO ADD EVENTHANDLER
};

Does anyone have an idea how I could make it so that even units placed by Zeus that are in a faction found in _factionList get this eventhandler. 
If it helps: CBA is an option.

Thanks in advance
Moony

Share this post


Link to post
Share on other sites
40 minutes ago, Moon_chilD said:

even units placed by Zeus

 

Hello there Moon_chilD !

 

This is an example on how to make your code work also with the spawned units , with an exlude list.

 

-add a unique Var (variable )

GF_ARL = { code , your eventhandler };

[] spawn {
	while {true} do {		
		{		
		if (
		((alive _x)) 
		&& (!(_x getVariable ["Var_GF_ARL",false])) 
		&& (!((typeOf _x) in GF_ARL_Exclude_List)) 
		
		/*
		//________________	You can filter the side here	________________	
		&& {((side group _x) == west || 
			(side group _x) == east || 
			(side group _x) == independent || 
			(side group _x) == civilian)}
		*/
		
		//	&& (side group _x == playerSide)
		//	&& (!(side group _x == playerSide))
		
		) then {
			
			_x spawn GF_ARL;
			
			};						
			_x setVariable ["Var_GF_ARL",true];
			{waitUntil {!alive _x};
			_x setVariable ["Var_GF_ARL",false];		 
			};
		}forEach allUnits;
		sleep 5;
	};
};		

 

Share this post


Link to post
Share on other sites
On 2/24/2019 at 5:23 PM, Moon_chilD said:

how do I make sure that even units placed by Zeus get this Eventhandler?

MCD_factionsList = [ /*...*/ ];

{
	//Add event to curator module for when an object is placed
	_x addEventHandler [ "CuratorObjectPlaced", {
		params[ "", "_object" ];
		
		if ( typeOf _object isKindOf "CAManBase" && { faction _object in MCD_factionsList } ) then {
			//CODE TO ADD EVENTHANDLER
		};
		
		//CuratorObjectPlaced does not fire for crewed units
		//If its a vehicle
		if ( _object in vehicles ) then {
			//Add event for each crew member
			{
				//CODE TO ADD EVENTHANDLER
			}forEach ( crew _object select { faction _x in MCD_factionsList } );
		};
	}];
}forEach allCurators;
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks Larrow !

 

This is only for the spawned units with zeus right ?

It's not also about the scripted spawns , is it ?

Share this post


Link to post
Share on other sites
2 hours ago, GEORGE FLOROS GR said:

This is only for the spawned units with zeus right ?

Correct.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you aswell @Larrow. In my case though a universal approach was actually a good idea since I also wanted script spawned units to be affected. (Though I never knew there was a eventhandler for Zeus Spawned units, so....the more you know xD)

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

×