Need help tracking the objects a cloak spell affects.

Post » Tue Jan 14, 2014 4:15 pm

Alright, basically what I'm trying to do is track actors that are affected by my cloak spell, and store their reference in an array which can be manipulated durring the course of the cloak.

The cloak is going to be a concentrated effect, durring which actors inside it's radius will be stored in the array, and periodically things will happen to them (Every 1 - 2 seconds). What I'm needing help doing is figuring out how to add / remove actors from the array. I am figuring that this would be done with OnEffectStart() and OnEffectFinish() on the spell that is applied to each one by the cloak, updating the cloak's script itself. As an example (And I know this is not how to do it, at least I would be surprised if it was):

//########### The script that exists on the cloak magic effect itselfScriptname coreCloakEffectScript extends ActiveMagicEffectActor[] Property trackedActorList AutoEvent OnEffectStart(Actor target, Actor caster)		RegisterForUpdate(2.0)EndEventEvent OnUpdate()	// Do stuff to the actors in the affectedListEndEvent// Returns the tracked actor indexint function TrackActor(Actor t)	// array logicEndFunction// Removes the actor from being trackedFunction StopTracking(int index)    // array logicEndFunction //########### The script that exists on the magic effect that gets put on affected actors in range.Scriptname coreCloakActorEffectScript extends ActiveMagicEffectcoreCloakEffectScript Property cloakScript AutoInt trackIndexEvent OnEffectStart(Actor target, Actor caster)		If (!target.IsDead())		trackIndex = cloakScript.TrackActor(target)	EndIf	EndEventEvent OnEffectFinish()	cloakScript.StopTracking(trackIndex)EndEvent// I'm not actually sure if this event is neededEvent OnDying()    cloakScript.StopTracking(trackIndex)EndEvent

So, what basically happens, in order:

For the duration of my concentrating the cloak, the following:
1) The actor moves within range of the cloak spell, applying a separate magic effect to him.

2) The magic effect applied registers the target for tracking

3) Every 2 seconds, something happens to tracked actors.

4) The actor goes out of range, or dies, and is unregistered for tracking.

Any help or suggestions on how this can be accomplished will be greatly appreciated :smile:

(Note: I did do a search, and the best I can find is something to do with making a quest which will contain the shared variables and methods, but I haven't been able to find a good resource on how to actually do this).

(Side not: I know // is not the proper comment for papyrus, but it's easier to read than ; on here imo. This is just an example script I wrote up in notepad.)

User avatar
Niisha
 
Posts: 3393
Joined: Fri Sep 15, 2006 2:54 am

Post » Tue Jan 14, 2014 10:49 am

You're on the right track, but you'll need to use something like a Quest instead of the Cloak Effect to track the actors. The reason is, every newly applied cloak is a separate instance of coreCloakEffectScript. You can't fill the property of an activeMagicEffect-type script in the CK, because activeMagicEffect scripts only exist at runtime. (and by "you can't", I mean "you can but it won't work as expected")

I would suggest having a quest that is either Start-Game Enabled or else you could start it from the main Cloak Effect script. Then include some kind of track or report function in the quest which your actors can report to. This will work better because you CAN fill a quest property in the CK (and use it in the script that affects each actor) and it will work properly.

I wrote a script that does pretty much what you're aiming to do a while back, so I'll post it here. You will need to edit it to your needs of course, but perhaps it will give you an idea or two. Feel free to ask if anything is unclear.

Spoiler
Scriptname trackActorScript extends ActiveMagicEffect;this script assumes you've already added conditions to the cloak effect,;making sure that it wont apply this to any actors unless they are hostile;to the player, currently alive, and don't have this effect on them already.ObjectReference property epicenter auto ;could replace "Epicenter" with "playerRef" if it will always be the player you measure  fromstasisQuestScript property mothership autoObjectReference actorSelffloat fRadius ;must be set in UNITS - vs the cloak effect radius, which must be set in FEET. you can take FEET * 21.33 to approximate equivalent UNITSEvent onEffectStart(Actor akTarget, Actor akCaster)  actorSelf = akTarget as objectReference  Mothership.report(actorSelf) ;small function in MainQuest that adds this actor to an array, etc.  RegisterForSingleUpdate(5.0)EndEventEvent onUpdate()  if (epicenter.getDistance(actorSelf) > fRadius) or (actorSelf.isDead) or (!actorSelf.isHostileToActor(Player))    Mothership.detach(actorSelf) ;function that will remove actor from main tracking array if they die or get too far from the cloaked actor.    dispel() ;ends this effect  else    registerForSingleUpdate(5.0)  endifEndEvent

Spoiler
Scriptname stasisQuestScript extends QuestandromedaActorScript property Andromeda autoObjectReference[] property nearbyActors auto hiddenint actorThreshold = 5 ;set this to the number of actors that need to be nearbyint curIndex = 0 ;this will be kept equal to the index of the next blank entry in the arrayEvent onInit()   nearbyActors = ObjectReference[40] ;I'd recommend setting this to about double the threshold # of actors you want nearby before the spell triggersEndEventFunction report(objectReference victim)  nearbyActors[curIndex] = victim  curIndex += 1  if curIndex == actorThreshold    Andromeda.castStasis()    ;you could either pass the actor references to andromeda in this function call, or you can have Andromeda    ;access the nearbyActors[] array from her own script and choose them randomly there.  endifEndFunctionFunction detach(objectReference victim)  int vIndex = nearbyActors.Find(victim)  curIndex -= 1  nearbyActors[vIndex] = nearbyActors[curIndex]  nearbyActors[curIndex] = noneEndFunction
User avatar
xxLindsAffec
 
Posts: 3604
Joined: Sun Jan 14, 2007 10:39 pm


Return to V - Skyrim