Jump to content
kibaBG

EnemyDetected Group Event Handler fires multiple times

Recommended Posts

The problem is very strange ... I am trying to script so defenders of a building use a flare to "call reinforcements" (spawn reinforcements) at some distance and then send then against the attacking players. 
 

_garrGRPA = [(position structA), independent, ["rhsgref_cdf_reg_squadleader","rhsgref_cdf_reg_machinegunner","rhsgref_cdf_reg_grenadier_rpg","rhsgref_cdf_reg_marksman","rhsgref_cdf_reg_specialist_aa"]] call BIS_fnc_spawnGroup;
[_garrGRPA, (position structA)] call BIS_fnc_taskDefend;
{_x linkItem "rhs_1PN138"; _x setUnitPos "UP"; _x disableAI "PATH";} forEach units _garrGRPA;
(leader _garrGRPA) addWeaponGlobal "rhs_weap_rsp30_green";
_garrGRPA addEventHandler ["EnemyDetected", {
(leader _garrGRPA) forceWeaponFire ["rhs_weap_rsp30_green", "Single"];
_sposReinfGRPA = [(position structA), 100, 300] call BIS_fnc_findSafePos;
_reinfGRPA = [_sposReinfGRPA, independent, (configfile >> "CfgGroups" >> "Indep" >> "rhsgref_faction_cdf_ground" >> "rhsgref_group_cdf_para_infantry" >> "rhsgref_group_cdf_para_infantry_squad")] call BIS_fnc_spawnGroup;
_reinfGRPA deleteGroupWhenEmpty true;
}];

First problem is Sl of defenders don't fire the flare straight up, second problem is the event handler fires multiple times with no end spawning so many groups the mission becomes unplayable. My intent is to spawn only one wave of reinforcements, not whole China. 

  • Haha 1

Share this post


Link to post
Share on other sites
2 hours ago, kibaBG said:

First problem is Sl of defenders don't fire the flare straight up

I can't help you with this part. Maybe some math expert can.

 

2nd problem with proper indentation 😛

Just added removeEventHandler and params.

_garrGRPA = [
  (position structA), independent,["rhsgref_cdf_reg_squadleader","rhsgref_cdf_reg_machinegunner","rhsgref_cdf_reg_grenadier_rpg","rhsgref_cdf_reg_marksman","rhsgref_cdf_reg_specialist_aa"]
] call BIS_fnc_spawnGroup;

[_garrGRPA, (position structA)] call BIS_fnc_taskDefend;

{
	_x linkItem "rhs_1PN138";
	_x setUnitPos "UP";
	_x disableAI "PATH";
}forEach units _garrGRPA;

(leader _garrGRPA) addWeaponGlobal "rhs_weap_rsp30_green";

_garrGRPA addEventHandler ["EnemyDetected", {
	params ["_group", "_newTarget"];
	(leader _garrGRPA) forceWeaponFire ["rhs_weap_rsp30_green", "Single"];
	_sposReinfGRPA = [(position structA), 100, 300] call BIS_fnc_findSafePos;
	_reinfGRPA = [_sposReinfGRPA, independent, (configfile >> "CfgGroups" >> "Indep" >> "rhsgref_faction_cdf_ground" >> "rhsgref_group_cdf_para_infantry" >> "rhsgref_group_cdf_para_infantry_squad")] call BIS_fnc_spawnGroup;
	_reinfGRPA deleteGroupWhenEmpty true;
	_group removeEventHandler [_thisEvent, _thisEventHandler];
}];
  • Like 1

Share this post


Link to post
Share on other sites

Splendid work, I didn't know you can remove event handlers (not just add :icon_biggrin:). Now only one reinforcements group spawns. 
 

_garrGRPB addEventHandler ["EnemyDetected", {
	params ["_group", "_newTarget"];
	_flarePos = [(position structB), random 100, random 360] call BIS_fnc_relPos;
	_flare = createVehicle ['F_20mm_Red', _flarePos, [], 0, 'NONE'];
	_flare setPosATL [getPosATL _flare select 0, getPosATL _flare select 1, 150 + (random 75)];
	_flare setVelocity [0,0,-0.1];
	_sposReinfGRPB = [(position structB), 200, 400] call BIS_fnc_findSafePos;
	_reinfGRPB = [_sposReinfGRPD, independent, (configfile >> 'CfgGroups' >> 'Indep' >> 'rhsgref_faction_cdf_ground' >> 'rhsgref_group_cdf_para_infantry' >> 'rhsgref_group_cdf_para_infantry_squad')] call BIS_fnc_spawnGroup;
	_reinfGRPB deleteGroupWhenEmpty true;
	_reinfGRPB allowFleeing 0; 
	_reinfGRPB setCombatMode 'RED';
	_stalking = [_reinfGRPD, ghost] spawn BIS_fnc_stalk;
	_garrGRPB removeEventHandler [_thisEvent, _thisEventHandler];
}];

The only problem now it spawns multiple flares without end. :headscratch: 

Share this post


Link to post
Share on other sites

Because your RemoveEventHandler syntax is wrong. You have a _group param, so you should write _group removeEventHandler [...], not _garrGRPB.

  • Like 1

Share this post


Link to post
Share on other sites

Tested couple of times with the right syntax, only two flares and one group are spawned. I have the feeling it takes some time to spawn the group and then remove the event handler and by that time it spawns one additional flare ...

Share this post


Link to post
Share on other sites
2 hours ago, kibaBG said:

it takes some time to spawn the group and then remove the event handler

 

So remove the EH first. The rest of your code will still run.

  • Like 1

Share this post


Link to post
Share on other sites

Tested and now spawns only one flare. :don11:  

  • 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

×