dizietemblesssma Posted January 14 Share Posted January 14 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 More sharing options...
IsharaMeradin Posted January 14 Share Posted January 14 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 More sharing options...
dizietemblesssma Posted January 14 Author Share Posted January 14 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 More sharing options...
scorrp10 Posted January 14 Share Posted January 14 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 More sharing options...
dizietemblesssma Posted January 14 Author Share Posted January 14 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 More sharing options...
scorrp10 Posted January 15 Share Posted January 15 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 More sharing options...
PeterMartyr Posted January 15 Share Posted January 15 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 More sharing options...
dizietemblesssma Posted February 26 Author Share Posted February 26 Thanks to both, it's been a while since I had time to go back to this and my problem is thus: the activemagiceffect that I was going to put the RegisterForModEvent function on is a fire and forget spell, thus the effect finishes before the script can register for the mod event and even so wouldn't be running anyway when needed. I didn't realise this because I stupidly called the magic effect a name with the word 'ability' in! So if I instead change the spell to an ability, put it on each of the refaliases already made in my quest and then added NPCs and removed NPCs from those aliases as the game plays, woud this be effectively giving each of the NPCs the ability? in which case I suspect that scorrp10's code: 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 would work? Would that code register the NPC as akTarget in Event OnEffectStart(Actor akTarget, Actor akCaster), or would it be the refalias and I would need to use getref etc in other functions that currently use akTarget? diziet Link to comment Share on other sites More sharing options...
Sphered Posted February 26 Share Posted February 26 No it simply makes the ActiveMagicEffect register that event, with no knowledge of caster/target, unless you do string chaining like it looks like you are playing with, which means you will need a resolve routine on the other end, etc... And TBH your approach looks more hectic than it needs to be, but you could make it work for sure Side opinion: ActiveMagicEffect tends to be a good relayer for sending mod events, not listening. It can do both but yeah. Like if you want the target to send a mod event: GetTargetActor().SendModEvent("WhateverItsCalled") Where above is listened for from a quest or alias etc and you know who called the event. Anyway, that sucks if your npc's aren't keeping their assigned outfits. Suppose you may be doing a dynamic thing PS: The OnLoad() Event will not perform as you hope in regards to loading the game. You need OnPlayerLoadGame() for reload routines, and it has to be a script running from the player. Usually an alias script Link to comment Share on other sites More sharing options...
dizietemblesssma Posted February 26 Author Share Posted February 26 I'm tired and I completely miswrote, what I mean to write was if the activemagiceffect script was put on a spell/ability that is attached to the refalias in the CK thus: https://i.imgur.com/2DHRO5N.png diziet Link to comment Share on other sites More sharing options...
Recommended Posts