So basically there's a couple of problems to solve with this.
<1: scripting vs dynamic detection>For any gameplay feature, there's a sort of tradeoff you have to make based on the way you're building the systems. On one hand you can program the features directly into things, like in this case giving a scenery object code to treat it as a potential piece of cover. On the other hand, you can have the game determine this stuff on the fly, like having the NPC scan the area around them looking for objects and then doing calculations based on things like hitboxes. Which version or which mix of both would work best for the project depends on a lot, including the way the game works and the way the dev team collaborates.
Bethesda games are kind of bad for either option. You don't want to program "use me as cover" into a rock scenery object, because a level designer can position that rock in a way that would make it unusable as cover, e.g. burying it mostly in the ground or placing it against/in a wall (they do this often). In those cases, the rock would be telling the AI it's valid cover and cause it to either act silly or just waste computation on invalid options. You also don't really want to have the game calculate things on the fly, since the games tend to be so full of clutter and have complex terrain meshes and broken navmeshes. You would need a more bespoke approach for that case.
<2: optimizing behavior and pathfinding>Regardless of how you determine valid cover locations, the NPC has to determine where to go and how to get there. Bethesda games are pretty notoriously bad with enemy AI and pathfinding. Part of this is lazy AI design and part of it is bad navmeshes and part of this is little awareness of the environment. Idk how exactly the AI is set up, but it appears to prioritize aggression in combat ahead of seeking cover, meaning if they're in combat with you they'll just stand there and shoot without ever trying to take cover because they just don't ever check for it. This could also be ameliorated by including behavior for both moving to a target location and shooting (suppressing fire at least).
The simplest solution for a Bethsesda game is probably something like the one implemented by this mod
https://www.nexusmods.com/skyrimspecialedition/mods/111890 where the NPC checks periodically if they are behind cover and moves to a new location if not. This is probably the most important component. You could add complexity on top of this pretty easily, like doing multiple raycasts from the NPC to the player to see where the limits on the cover are and what areas are exposed (like one for head, one for chest, etc) and determine whether they need to crouch to be protected. Another option is to have a top-level system in the combat AI that looks for available cover and then assigns it to NPCs in combat. For that you could spawn a very simple "virtual" character (invisible) at the cover locations to run the kind of checks described above to see if the cover is valid. The system could then be checked by NPCs when they lack cover to find the closest/best option (in complex environments, you would probably want to store the cover options in a quad tree to make the search as efficient as possible). A cover option should be rated based on its distance (inversely proportional, ideally based on pathfinding distance) and how effective the cover is determined to be by your virtual NPC.
>>39164Most players find it more engaging to have some kind of challenge instead of NPCs just standing in the open to be shot. There is an ideal balance between a shooting gallery and realistic tactical behavior that would be most fun, depending on the player preference and other game mechanics. You probably want at least some tactical behavior though, since it adds more ebb and flow to the combat when you have to either wait for NPCs to move into the open or you have to actively move around them to negate the cover.