Jump to content

Is Enemy Sighted under crosshair under (x) distance?

Recommended Posts

So I've been googling for about an hour, but apparently the search algorithms think that enemy ai and enemy behavior and all kinds of things unrelated to my search are more important than what I'm actually searching for. I tried peaking into some mods that do this, but none of them have source released so I can't check out the script sources of those.


This is what I ideally want:

- When possible, and the player targets an enemy, a popup key (like E for 'pacify') is shown in the HUD. But this one has my shortcut in there.


This is what I think I can make in a much easier fashion, without needing F4SE:

- The player has a consumable with a magic effect, with a script.

- When the player has an enemy targeted and uses the consumable, a thing happens (e.g. a scene is called from a quest).

- This THING happens only when the player has an enemy in his direct line of sight.


So what I think I need to know:

- What script command checks if the player has an enemy sighted (not just if the enemy is visible, it needs to be in the direct targeted sight)

- How to get the 'handle' to the enemy sighted in the scope (or from the hip) so I can check the target distance.

Link to comment

Sorry buddy... only way to do this is to make the mod reliant on the LLFP, a component of AAF.


It has a script function in it that allows you to pull the actor currently under the player's crosshair, which of course you can then get an actor ref to do the base script .IsHostileToPlayer() or .IsInCombat() and then of course the .GetDistance(PlayerREF). But without making the mod require AAF/LLFP, this cannot be done. I tried it with .IsInIronSights(), but this doesn't work reliably in any way. And the story manager event for InIronSights doesn't work at all - I tried it too, without any conditions on it, and it never once fired. Sorry to bear bad news. :(

Link to comment

Thanks. I was trying to look at the Push Companions/NPC's mod. That adds an R to the selected NPC, which is what I was looking for basically. You can also set the measure length there. So I guess technically it should be possible somehow (they managed). I'm not sure if he's using FSE functions, that could make Ivy dependent on FSE (something I've actively tried to avoid). I'll do some more digging, otherwise it's fine as it is now. :)

Link to comment

I figured out what they did, sort of. The scripts are hidden, source unavailable. They piggy-backed onto the hacking of Robotics Expert and the player alias, even overwriting the activation distance of the perk. I'll drop them a message on Nexus to see if I can find another clue, but it looks kind of nasty and not like it'll suit my purposes.



Link to comment



Well, what you are talking about is easy. I do it in Crime and Punishment for holdups.


Create a perk. Give it an entry level. Put a GetDistance check in the TARGET panel, and also an InCombat == 1 and IsInIronSights [TARGET] == 1 <-- leave it as TARGET, so that it will pick up anyone under crosshairs when zoomed in/aiming and in a combat state. Just note, there is no mechanism for 'from the hip' in FO4, you will need to force the player to actively be aiming in iron sights for this to work at all...


Just be aware that doing this, while it will definitely work, will conflict with the Intimidation Perk and any other mod, like Crime and Punishment, that has similar IronSights entry levels on their perks. I avoid this by making the player hold in their ACTIVATE key for 4 seconds to enable HOLDUP mode, which then allows it to take priority over everything else. And when that mode is disabled, Intimidation Perk can do its thing. You may want to consider something similar. Although... Intimidation and CAP's holdup functions dont work when in combat state, so you may be okay, provided you really only want this to function when actually in combat, The good thing about CAP is that it is combat state aware, so if the player is in HOLDUP MODE and then combat state begins, CAP will automatically exit Holdup Mode, so there's that too...


Last step, once you create the perk, you need to add it to the player at the time your mod first starts up.


Here's Crime and Punishment in action - once the iron sights is picked up for qualifying voicetype NPCs, the holdup scene automatically starts - player has to do nothing but ensure they are in holdup mode and then aim at someone. The mod does the rest... no need for a keypress.



Step by step:


1. Create the perk. Ensure it is set to HIDDEN and playable is unchecked (meaning, it cannot be leveled up via the Perk Chart).




2. Where it shows the Entry Point at the bottom, right click and select NEW. Which opens the Entry Point. Set it up as follows:




3. Define the parameter conditions on the TARGET TAB that tell the game when this function is available to add the secondary action item to the hud.




You need to ensure the target section is set precisely as shown (subject, subject, player) in order for this to work.


4. Once you have all of this done, you create the perk fragment, which tells the game what to do when the player selects the secondary action key.


And thats all there is to it, aside from obviously adding the perk to the player. Best method for that is on your MAIN script, in your OnQuestInit(), as follows:


If PlayerRef.HasPerk(Reginald_DemoPerk) == False




In this way, it will only add the perk if they dont have it. Ensures no problems if they monkey with load order or try to do a quick uninstall / reinstall.


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...