Jump to content

Access spell script from an ability given to a reference alias


Recommended Posts

In my script that is attached to reference aliases I wish to refer to the instance of a spell script from an ability that has been given to the ref alias.

I can make that spell script a property of my refalias script thus:

dz_outfits_ability_effect_script Property	ability_effect	Auto

but I will have to set that for each refalias defined in the CK (that has the script attached) and some of those aliases will already have been filled in a save.

I want to call a function in the spell script so:

ability_effect.dz_dress_outfit(some,parameters)

Since the script is attached to the spell and not to the refalias this will not work (I assume):

myRefabilityScript = myRefAlias As dz_outfits_ability_effect_scrip

is there a better way than the above mentioned?

 

diziet

Link to comment
Share on other sites

If you have a quest that handles background stuff and runs for the entire duration of your mod (which may be the entirety of the game), placing the function on a script attached to the quest will allow both the spell's effect and the ability's effect to remotely access the same function.  It is easier to go from a specific level (a spell) to a broader level (a quest) than the other way around.

Link to comment
Share on other sites

I think I may have been unclear, I wish to access a function that is already in the ability spell script from a script that is attached to a lot of refaliases, this is in an existing mod so I don't want to rewrite from scratch, I am trying to add an edit to the refalias script such that when an event occurs an existing function in the spell script runs.

 

diziet

Link to comment
Share on other sites

Thoughts:   ModEvents

In the ability script (which extends ActiveMagicEffect) call RegisterForModEvent(eventName, "ModEventHandler")   
Then you make a function: Event  ModEventHandler(string eventName, string strArg, float numArg, Form sender) which calls whatever it is you want.

In the script attached to RefAlias:   SendModEvent(eventName,  strArg, numArg) 

I assume you want a unique pairing, where an event from a specific RefAlias invokes the function only in the ability targeting same entity as the alias.

In the ability script:

String MyModEventName

Event OnEffectStart(Actor akTarget, Actor akCaster)
	MyModEventName = "OutfitEvent_" + akTarget.GetFormID() as string
	RegisterForModEvent(MyModEventName, "OutfitEventHandler")
EndEvent

Event OnLoad()
	; from what I heard, one needs to re-register for those on a game load
	RegisterForModEvent(MyModEventName, "OutfitEventHandler") 
EndEvent

Event OutfitEventHandler(string eventName, string strArg, float numArg, Form sender)
	dz_dress_outfit() ; well, you will somehow need to find a way to pass the parameters. You get one string and one float, hopefully thats enough
EndEvent

In the ReferenceAlias script

; when wanting to invoke the function
SendModEvent("OutfitEvent_" + GetReference().GetformID() as string, strArg, numArg)

 

Link to comment
Share on other sites

That looks interesting, passing the parameters does seem to be the tricky bit, but I think I can work that out:)  Thanks.

 

diziet

edit: I am a bit confused by the OnLoad event though, this is the loading of the 3D for the refalias actor yes? So an activemagiceffect script wouldn't receive that? 

Link to comment
Share on other sites

Oh, I think I had a wrong file open.    ActiveMagicEffect  has this:

; Received immediately after the player has loaded a save game. A good time to check for additional content.
Event OnPlayerLoadGame()
EndEvent

 

Link to comment
Share on other sites

I would  move the the function out of the spell, then make the both the Spell and the Alias call the function independently, it may require some Quest Scripted (global type) Properties, but that no biggy, to keep things in accord between them, if you require that

Link to comment
Share on other sites

×
×
  • Create New...