Aldo, I would strongly recommend the tried and tested method of Syncing waypoints with triggers. Always works for me.
Just set some cycling waypoints for a patrol route followed by a "Search and Destroy" waypoint after the Cycle and a move waypoint after the Search and Destroy one. Put the Search and Destroy in the centre of your defended area. Then make a trigger for [ENEMY SIDE] detected by [YOUR SIDE]. Set the activation parameters to be "BaseEnemyDetected = true" and the deactivation parameters to be "BaseEnemyDetected = false".
Then make 2 triggers, the first has the condition "BaseEnemyDetected" and the second "not BaseEnemyDetected". Press F5 (or select synchronisation) and link the first trigger to the cycle waypoint before the Search and Destroy. Then link the second trigger to the Move waypoint after the Search and Destroy.
The trigger for [ENEMY SIDE] detected by [YOUR SIDE] shouldn't be linked to anything.
Set the waypoint parameters of the first patrol waypoint to be "SAFE", and set the parameters for the Search and Destroy waypoint to be "COMBAT" and "ENGAGE AT WILL".
This method will have soldiers patrol around until enemies are spotted. Then the soldiers will spread out around the defended area to fight off the attackers.
If you can't get it working, ask, and I'll provide a demo file.
Hope that helped,
Lone-Wolf