dat title X_X
I'm having trouble getting any results from this function, not sure what I'm doing wrong. http://www.creationkit.com/FindClosestReferenceOfAnyTypeInListFromRef_-_Game.
I am attempting to create a spell which will teleport the player to the nearest valid actor in a given radius. I haven't set any conditions yet because I literally started this mod 2 hours ago and I need a better understanding of what is going on before I apply any restrictions.
This is what I have:
- A primary spell - this is what the player casts to do cool stuff
- A cloak spell - this gets briefly applied to the player and returns the references of nearby actors within its radius (essentially the area of effect for the primary spell)
- An applied spell - the cloak will apply this spell to said actors given my conditions are fulfilled. Any actors hit by this spell are added into my formlist
- Two scripts - One for the primary spell, and one for the applied spell
Here is the script on the primary spell:
Scriptname FR_FlyingRaijinScript extends activemagiceffect{This script goes on the player-cast spell. Another script will handle target selection by placing actors into a formlist}ObjectReference Property MarkerLightningSky Auto{Move this reference above our caster and aim a visual effect at it}Spell Property LightningVisualSpell Auto{Shoot this spell from the player to the marker}Spell Property FlyingRaijinCloakAb Auto{Have the caster cast this cloak to return the references of all potential targets in range}Float Property MarkerHeight Auto{The z-offset for our marker location. How high above the player do we wish to move it?}Float Property CloakRadius Auto{The radius of the Flying Raijin Cloak. We can only teleport to a valid target inside this radius}Formlist Property FlyingRaijinTargetList Auto{All valid potential targets retrieved from our cloak get added to this list. Make sure to call Revert() after teleporation has occured}Actor Property PlayerRef Auto;should we check LOS somehow?? Player needs to be able to "see" target?Event OnEffectStart(Actor akTarget, Actor akCaster) If akCaster == PlayerRef ;the caster should never be anyone else but I like to check anyway (cheaters/mods/followers/etc) ;MarkerLightningSky.MoveTo(PlayerRef, 0.0, 0.0, MarkerHeight) ;this isn't working atm, come back to it. Maybe use PlaceAtMe instead? MoveTo might not be fast enough?? ; utility.wait(0.1) ;LightningVisualSpell.Cast(PlayerRef, MarkerLightningSky) ;perhaps we need a ground marker instead of the player? PlayerRef.AddSpell(FlyingRaijinCloakAb, false) utility.wait(1.0) PlayerRef.RemoveSpell(FlyingRaijinCloakAb) ;we might be better able to remove this elsewhere (with more precise duration = more responsive) endifEndEventEvent OnEffectFinish(Actor akTarget, Actor akCaster)utility.wait(1.5) ;need to give the cloak time to populate my formlist. Optimize this laterdebug.notification("finish event sent") ;cloak spell will have conditions to narrow target pool. GetDead == 0 , etc. Also, we can't allow followers/active allies to be targeted and/or added to our target formlist. Check hostility or relationship rank? Int NumTargets = FlyingRaijinTargetList.GetSize() debug.notification("Number of targets =" + NumTargets) ObjectReference FRTarget = Game.FindClosestReferenceOfAnyTypeInListFromRef(FlyingRaijinTargetList, PlayerRef, 4096.0) ;FRTarget = the closest reference to the PlayerRef inside the FlyingRaijinTargetList ;does this fail because the references are actors? We do cast them as objectReferences inside the other script before adding them into the formlist If FRTarget debug.notification("Target is" + FRTarget) ;PlayerRef.MoveTo(FRTarget, -120.0 * Math.Sin(FRTarget.GetAngleZ()), -120.0 * Math.Cos(FRTarget.GetAngleZ())) PlayerRef.MoveTo(FRTarget) elseif !FRTarget debug.notification("No Target Found") ;PlayerRef.MoveTo(FRTarget, -120.0 * Math.Sin(FRTarget.GetAngleZ()), -120.0 * Math.Cos(FRTarget.GetAngleZ())) PlayerRef.MoveTo(FRTarget) endif FlyingRaijinTargetList.Revert() ;clean list out EndEvent
Here is the script on the applied spell:
Scriptname FR_FlyingRaijinTargetScript extends activemagiceffect{This script fires when our cloak hits a potential target adding them to a formlist of targets}Formlist Property FlyingRaijinTargetList Auto{All valid potential targets retrieved from our cloak get added to this list. Make sure to call Revert() after teleporation has occured}Actor Property PlayerRef AutoObjectReference Property TargetRef Auto HiddenEvent OnEffectStart(Actor akTarget, Actor akCaster) If akTarget != PlayerRef ;conditionalise our spell accordingly TargetRef = akTarget as ObjectReference If !FlyingRaijinTargetList.HasForm(TargetRef) ;not in formlist, safe to add FlyingRaijinTargetList.AddForm(TargetRef) debug.notification("A potential target just got added to our target list" + TargetRef) endif endifEndEvent
4096 is my current search radius, this is equal to the size of a cell and exceeds the radius of my cloak (for now). I was using the CloakRadius float property but inserted a literal value for testing.
All my debug notifications give the expected information except FRTarget is always false/NONE so I always see "No Target Found" and the MoveTo never takes place.
I've been testing in Whiterun near the Gildergreen and the number of targets message always returns an accurate count. Despite my formlist having references inside it (starts empty) I haven't been able to "find" one to have the player MoveTo.
What am I doing wrong here?
Do I need to provide screenshots of my spells and magic effects in the CK?
EDIT: I fixed arCenter to be an actual ObjectReference, and not PlayerRef. No change in results
(I cast the player as an object reference, for some reason having an actor in that argument didn't cause a compiler error)