I spent days racking my brain in the CDK trying to force these bastards to fire exclusively at a specific squad via filt
I spent days racking my brain in the CDK trying to force these bastards to fire exclusively at a specific squad via filtering. The challenge was twofold: the SAMs had to ignore squad members who hadn't met the condition yet (hadn't entered the zone), while also completely ignoring unrelated targets that were already inside the zone but didn't belong to the squad.
Here is how the Attack & Safe Zone logic works... (Triggers 1, 2, 3)
This system ensures that SAM sites open fire only when a target enters the danger zone, and cease fire as soon as it leaves.
Important: At the start of the mission, the entire Players_squad has the targetableByAi:b=no parameter forcibly disabled (via the addTextToUnit trigger). Because of this, SAMs and AI units completely ignore the player and target drones until they cross the engagement zone border.
Trigger 1 (Entering the engagement zone - area_02)
• Condition (unitWhenInArea): Checks every second if any alive unit from Players_squad has entered area_02.
• Action 1 (unitSetVar): Assigns the variable 512 = 1 to that specific unit (using the trigger filter useForTriggerFiltered).
• Action 2 (playHint): Displays the warning "Attention! Rocket attack." for visual confirmation.
• Action 3 (unitSetProperties): Enables targetableByAi:b=yes for the unit that entered, allowing the AI to lock onto it.
Trigger 2 (Patriot fire control)
• Condition (unitWhenStatus): Checks if there are any alive targets in Players_squad with the variable status 512 = 1.
• Actions (if a target is in the zone): Switches PATRIOT launchers to free-fire mode (fire_at_will). Note that fire_at_will is applied directly to the PATRIOT unit without a filter—the actual filtering happens on the targets' side.
• Else (else_actions): If no one is in the zone, switches PATRIOT back to dont_aim.
Trigger 3 (Exiting into the safe zone - area_03)
• Condition (unitWhenInArea): Checks if a unit with the variable 512 = 1 has entered the safe zone area_03.
• Action 1 (unitSetVar): Resets the variable back to 512 = 0.
• Action 2 (unitSetProperties): Sets targetableByAi:b=no again so the SAMs immediately lose lock and stop firing.
2. Attack triggers for the remaining SAM batteries (Categories TYPE_03 and C300)
They work on the exact same principle as Trigger 2 for the Patriot, checking for the 512 = 1 variable:
• Category TYPE_03 -> Trigger type03:
• If there is a target with 512 = 1 in the zone, switches the type03 launcher units to fire_at_will. If there are no targets, switches them to dont_aim.
• Category C300 -> Trigger C300_01:
• Similarly switches the C300 launchers to fire_at_will when a target is present, and back to dont_aim when clear.
3. Manual activation and deactivation of SAM batteries (Hotkeys)
To avoid overloading the map and to test the systems one by one, each battery is bound to the Action Bar hotkeys (ID_ACTION_BAR_ITEM):
(Note: You can list your hotkeys 1–2, 6–7, 8–9 here if needed)
Important!
Why unitAttackTarget is disabled and how target filtering actually works:
All SAMs are set to a neutral army (army:i=0), so by default they will shoot at anything that flies.
If you hardcode the dont_aim restriction into a launcher (like PATRIOT), it won't fire. Initially, I had a unitAttackTarget action in Trigger 2, but the catch is that a hardcoded dont_aim cannot be overridden by unitAttackTarget because the restriction itself hasn't been lifted.
• You can only remove a hardcoded dont_aim via unitSetProperties by setting attack_type:t="fire_at_will".
HOWEVER! Once you give it that parameter, the launcher will start spraying missiles at everything in sight, completely ignoring unitAttackTarget (even if you specify attack_target and set the target to Players_squad, they will ignore it because the previously set fire_at_will in unitSetProperties takes higher priority).
Therefore... The unitAttackTarget action is set to Disable, and target filtering is shifted onto the targets themselves. At mission start, Players_squad has targetableByAi:b=no, and it only flips to yes for those specific squad members who enter the engagement zone.
The setup works, and I have two test groups in the mission to prove it:
(Tu-4 flight): Flies in circles as a background AI bot and is NOT part of Players_squad. Its targetableByAi:b=no stays off, so the SAMs completely ignore it even when given the fire_at_will order—proving they don't just shoot at everything blindly.
(Spitfire pair): Belongs to Players_squad and starts outside the danger zone (area_02). When woken up, it crosses into area_02, gets 512 = 1 and targetableByAi:b=yes—and the SAMs immediately open fire on it.
#224