kibaBG 53 Posted January 18 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. 1 Share this post Link to post Share on other sites
RCA3 589 Posted January 18 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]; }]; 1 Share this post Link to post Share on other sites
kibaBG 53 Posted January 18 Splendid work, I didn't know you can remove event handlers (not just add ). 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. Share this post Link to post Share on other sites
honger 114 Posted January 18 Because your RemoveEventHandler syntax is wrong. You have a _group param, so you should write _group removeEventHandler [...], not _garrGRPB. 1 Share this post Link to post Share on other sites
kibaBG 53 Posted January 18 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
Harzach 2517 Posted January 18 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. 1 Share this post Link to post Share on other sites
kibaBG 53 Posted January 19 Tested and now spawns only one flare. 1 Share this post Link to post Share on other sites