Defend

Defend (displayed as Help defend (Location Name)) is a miscellaneous quest $$ There are many variations of the quest using the same script, with the only difference being the attacking party.

Detailed walkthrough
A settlement owned by the Sole Survivor can be attacked by many groups, including raiders, Super Mutants, feral ghouls, synths, and Gunners. When an attack is imminent, the Sole Survivor will receive a miscellaneous objective on their Pip-Boy pointing to the settlement. The Sole Survivor can travel to the settlement and deal with the attackers, or leave the settlement to deal with it themselves. Either way, the objective disappears once the attack is resolved. No reward is given for a successful defense, but a failed defense will result in damage to the settlement.

Bugs

 * Sometimes the quest objective might mark itself as completed before all enemies are killed.
 * Sometimes the quest doesn't complete.
 * Search inside and outside of the settlement for enemies that have not been killed and kill them.
 * Open the console. Target a dead enemy (by clicking on their corpse). Enter the command, exit console and kill the resurrected enemy. This will help in case the kill-counter is missing a kill.
 * If on arrival you find your settlers have killed a synth infiltrator you may also find there is no attack incoming. Open the console, and enter the command . The quest will complete.
 * When defending a settlement against an invasion of synths, the quest may become stuck and uncompletable if the first synth is killed before more can spawn.
 * Loading a save before killing the first synth will fix the quest.
 * Use console command to list all currently active quests, and find the appropriate quest ID, such as, and then use  to complete the quest.
 * After completing one of these quests, some settlers may get stuck in the "thank you" mode, i.e. constantly thanking you when you try to talk to them, locking out all other options such as trading and bartering.
 * This can be fixed by talking to a settler or shop owner from another settlement.
 * Also can be fixed by using the console. The bug is triggered when settlers are not correctly removed from the WorkshopAttackDialogueFaction faction by the appropriate script. This faction has the editor id . To solve it, open the console, select a settler then enter command