Is there a way to test if there are enemies nearby?

Post » Fri Jun 22, 2012 4:00 am

I'm pretty sure fHostileActorInteriorDistance and fHostileActorExteriorDistance are what the engine uses to tell the player they cannot sleep because enemies are nearby, etc, but what would be the scripting equivalents so I can create conditions in my scripts to test these?
User avatar
ShOrty
 
Posts: 3392
Joined: Sun Jul 02, 2006 8:15 pm

Post » Thu Jun 21, 2012 8:06 pm

This is for that "stalk your player character in their bed" mod, right? :D

Hrrrrrrrrrrm.

Possibly not the best solution, but - and this reflects the fact that I've only done work with spell scripting! - you could force the player to cast a custom spell with the radius you want, the spell having a condition of Target GetShouldAttack == 1. If any targets are affected, the spell fires a script that increments a global variable by 1. If the global variable is non-zero, the script will not progress further and let you know that enemies want to Do Things To Your Dead Body. Then it resets the variable to zero in anticipation of the next test the player performs.
User avatar
KRistina Karlsson
 
Posts: 3383
Joined: Tue Jun 20, 2006 9:22 pm

Post » Thu Jun 21, 2012 10:32 pm

Yes, findclosestactor then ishostiletoplayer, that will give you closest actors that are hostile towards you.
User avatar
michael danso
 
Posts: 3492
Joined: Wed Jun 13, 2007 9:21 am

Post » Thu Jun 21, 2012 8:26 pm

FindClosestActor wouldn't work:

1) It will return the player if the player is the closest.
2) Even if it didn't, if you had one friendly person close to you and then like seven enemies a few yards away, that check would fail to catch the hostiles.
User avatar
Katie Pollard
 
Posts: 3460
Joined: Thu Nov 09, 2006 11:23 pm

Post » Thu Jun 21, 2012 11:19 pm

True, try it with random and keep looping it, sometimes it will catch friends but other times it will get foes.
User avatar
Bigze Stacks
 
Posts: 3309
Joined: Sun May 20, 2007 5:07 pm

Post » Thu Jun 21, 2012 6:57 pm

AstralFire's suggestion should work. The quest/alias alternative would be to start a quest with an alias set to be filled with the nearest hostile actor, and then check 1) if the quest has started and 2) if the distance to that alias is within the appropriate game setting.
User avatar
cheryl wright
 
Posts: 3382
Joined: Sat Nov 25, 2006 4:43 am

Post » Thu Jun 21, 2012 6:59 pm

I wonder if IsInCombat on the player would work? When enemies are nearby is the player considered IsInCombat?
User avatar
Emma Copeland
 
Posts: 3383
Joined: Sat Jul 01, 2006 12:37 am

Post » Thu Jun 21, 2012 6:56 pm

I wonder if IsInCombat on the player would work? When enemies are nearby is the player considered IsInCombat?

That's a good idea. I do know that just having a dragon arrive makes it so a player cannot get on the carriage as it says "Can't board while in combat."
User avatar
SaVino GοΜ
 
Posts: 3360
Joined: Mon Sep 17, 2007 8:00 pm

Post » Fri Jun 22, 2012 2:59 am

I wonder if IsInCombat on the player would work? When enemies are nearby is the player considered IsInCombat?

I don't try waiting very often, but it seems to me that that would work any time the enemies are showing up as red dots already, and IIRC Wait has more stringent restrictions than simply not having red dots on the radar.
User avatar
Kaylee Campbell
 
Posts: 3463
Joined: Mon Mar 05, 2007 11:17 am

Post » Fri Jun 22, 2012 2:09 am

I'm pretty sure functions like IsInCombat are only used for AI, because a combat state is something the AI goes into, while the player has no such detection (since you can have your weapon out and swing but not really be "in combat"). I assume then, IsInCombat simply checks for that state on the AI.

Of course I could be wrong.
User avatar
Isaiah Burdeau
 
Posts: 3431
Joined: Mon Nov 26, 2007 9:58 am

Post » Thu Jun 21, 2012 1:07 pm

Edit: Guess I lied :P just looked at my perk again and I'm using GetCombatState == 0

IsInCombat works on the player. I believe it should return true if there is an enemy actively engaged in combat with the player (red marks on the compass, exciting battle music, etc.)

My testing has been limited, however.
I'm using it in an allow dual cast perk to keep the player from dual casting certain things in combat.
User avatar
Maria Leon
 
Posts: 3413
Joined: Tue Aug 14, 2007 12:39 am

Post » Thu Jun 21, 2012 1:52 pm

I tried IsInCombat for player and it worked.
Although the player would have to 'knows' when he is attacked (like red dots appeared on compass)

IsInCombat is quite handy when you want to include sneak-check on your script
User avatar
sunny lovett
 
Posts: 3388
Joined: Thu Dec 07, 2006 4:59 am


Return to V - Skyrim