Vetril Posted April 18, 2016 Share Posted April 18, 2016 Hi, I'm writing a maintenance script responsible for registering events to a list of tracked actors and restore some changes that are supposed to persist through saves. I have coded this with a quest and an activemagiceffect attached to a spell which is assigned to the tracked actors. The code: ; rnpc_RandomizerEffect.psc ... rnpc_RandomizationQuest property rfqRandomization auto ... event OnPlayerLoadGame() rfqRandomization.NotifyAll() endEvent event OnRandomize(string sName, string sArg, float fArg, Form fSender) Actor aTarget = GetTargetActor() string[] sValues = new string[5] GetRandomization(aTarget, sValues) ApplyRandomization(aTarget, sValues) endEvent ------------------------------------------------------- ; rnpc_RandomizationQuest.psc ... FormList property RandomizedActors auto ... function NotifyAll() ... if (!bRandomizedActorsLock) bRandomizedActorsLock = true int nSize = RandomizedActors.GetSize() int i = 0 Actor a = None while (i < nSize) a = RandomizedActors.GetAt(i) as Actor if (a != None) a.RegisterForModEvent("Randomize", "OnRandomize") endIf i += 1 endWhile SendModEvent("Randomize") endIf ... endFunction The actors register for the events correctly, but OnRandomize is never called. My solution assumes that ModEvents registered for actors are also passed to the active magic effects (which I guess is not the case), as it happens for the regular events; I guess this isn't true?I can't attach the script directly to the actors in the CK as pretty much all of them belong to a leveled list.I thought about tracking the ActiveMagicEffect instances directly, and register the mod event on them, but there is no support for an ActiveMagicEffect list as its type does not extend Form.I'd like to avoid registering each actor for an update as that will trigger all the scripts that hook into the update event, be they from the vanilla game or from mods.I could maybe get away with removing the spell and reapplying it on each actor but I'd have to restructure the effect script.Isn't there a better way to code this? Can you get a handle to a specific ActiveMagicEffect instance, given the Actor it is running on?Thank you. Link to comment Share on other sites More sharing options...
sohel33 Posted April 28, 2016 Share Posted April 28, 2016 Hi I have the same issue with a smaller code scriptName MyScript extends Quest hidden event OnInit() RegisterForModEvent("EpicEvent", "OnEpicEvent") Run() endevent Event OnPlayerLoadGame() RegisterForModEvent("EpicEvent", "OnEpicEvent") Run() endEvent function Run() Debug.notification("pre call") SendModEvent("EpicEvent", "data") endfunction event OnEpicEvent(string eventname, string mydata) Debug.notification("Event match !!!") endevent I can see "pre call" but never event match message. Link to comment Share on other sites More sharing options...
lofgren Posted April 28, 2016 Share Posted April 28, 2016 Maybe it takes some amount of time for the registration to occur? Try sending the event after a 5 second delay. Link to comment Share on other sites More sharing options...
sohel33 Posted April 28, 2016 Share Posted April 28, 2016 Nope, i made Utility.Wait(20) And it doesn't work. Link to comment Share on other sites More sharing options...
UBCToad Posted October 18, 2016 Share Posted October 18, 2016 Although I am not certain of this information, I tend to find "RegisterForModEvent()" does not work when called too quickly after loading a game. Although this only seems to be true sometimes.Try waiting for 20+ seconds (a minute or two) before you register for the event.For me I find a delay of about 15 seconds works but others may need a longer delay.If you have an options menu make a debug option to re-register for all Mod Events. Link to comment Share on other sites More sharing options...
Recommended Posts