Detecting a nearby NPC reference - not working?

Post » Sun Jun 16, 2013 10:47 am

One of our long standing bugs on the USKP tracker is for civil war camps that spawn wounded soldiers long after everyone else in the camp is dead, though the camp itself is still there. Rather than edit the properties on 54 individual references, I tried a slightly fancier approach. This altered script is the result:

Scriptname CWFortSoldierWoundedScript extends Actor  int Property PercentChanceToAppear = 75 Auto{Default: 75; What percentage of the time should this actor be loaded?}ObjectReference Property CampEnableMarker Auto{MANDATORY!!! Pointer to the camp's enable marker}FormList Property USKPCampCOList Auto{Added by USKP 1.3.3 - If the camp's Legate is dead, stop spawning wounded soldiers}Event OnCellLoad()    disable()        ObjectReference LegateRef = Game.FindClosestReferenceOfAnyTypeInListFromRef(USKPCampCOList, CampEnableMarker, 8000.0)    if( LegateRef == None )        debug.messagebox( "I didn't find anything here" )        Return    EndIf        Actor Legate = LegateRef as Actor        if( CampEnableMarker.IsEnabled() && Utility.RandomInt(1, 100) <= PercentChanceToAppear )        if( !Legate.IsDead() )            Enable()            SetRestrained()        EndIf    EndIfEndEvent

However, it does not work. The debug messagebox pops up all the time even when the Legate at the camp is still alive and well within the 8000 unit radius.

The formlists have been populated correctly with the base NPC records of each Legate and/or Stormcloak. The wounded soldier base records have the proper settings, and I've confirmed they're propagating down to the individual references. Approaching a camp nets me 3 debug message boxes, which is what I'd expect from a camp with a dead leader.

Does FindClosestReferenceOfAnyTypeInListFromRef() simply not work or am I doing this wrong?

User avatar
Bryanna Vacchiano
 
Posts: 3425
Joined: Wed Jan 31, 2007 9:54 pm

Post » Sun Jun 16, 2013 3:50 pm

I can confirm that the function does work--I use it several times successfully to look for things like the nearest bed furniture to my follower, with code that looks similar to yours. What exactly is in your formlist--it sounds like you have the 18 individual actor records? I wonder if the multiple levels of base actor inheritance with them might be causing problems.
User avatar
Kieren Thomson
 
Posts: 3454
Joined: Sat Jul 21, 2007 3:28 am

Post » Sun Jun 16, 2013 10:53 pm

There's two formlists. The Stormcloak one has the 9 Stormcloak field commanders in it. The Imperial one has the 9 Legates in it.

Base NPC CWFortSoldierImperialWounded has the Imperial formlist, CWFortSoldierSonsWounded has the Stormcloak formlist.

Papyrus logs no errors with this script.

User avatar
CRuzIta LUVz grlz
 
Posts: 3388
Joined: Fri Aug 24, 2007 11:44 am

Post » Sun Jun 16, 2013 12:46 pm

Just a suggestion for an alternative, could you cast a large aoe explosion at the player or put on a cloak for a few seconds? Then, you could use the OnEffectStart event to determine if one of your targets is a legate. It probably isn't the most elegant solution but I think it would work.

User avatar
Cathrin Hummel
 
Posts: 3399
Joined: Mon Apr 16, 2007 7:16 pm


Return to V - Skyrim