Jump to content

[LE] Mod event not received by objects?


Recommended Posts

Hello,

 

I have a simple mod event set up, but it's not received by the objects I registered it for.

 

The mod event sender:

; its a player alias script
 
Event OnPlayerLoadGame()        

    int handle = ModEvent.Create("GYHUpdateBookTitles")
    if (handle)
        ModEvent.Send(handle)
        Debug.Notification("Mod event sent ")     <---- shows correctly ingame
    endIf
EndEvent

And the receivers are objectreferences in the world:

Scriptname WW42GYHCustomDynamicBookScript extends ObjectReference
 
Event OnInit()
    RegisterForModEvent("GYHUpdateBookTitles", "GYHOnBookTitleUpdate")
EndEvent
 
Event GYHOnBookTitleUpdate()
    Debug.Notification("Modevent tried")    <---- this does NOT show
EndEvent

What am I doing wrong, why don't the object references receive the mod event, sent by the player alias script upon save game load?

Link to comment
Share on other sites

First, OnPlayerLoadGame will run as soon as the game has started. If the objects to receive the mod event have not loaded yet, their OnInit events will not have run and thus never receive the mod event until a future load of the game after they have had their OnInit events run.

 

Second, your using the "complicated" custom mod event route. For something as simple as you are doing, use the "easier" method. SendModEvent.

 

Example stripped from one of my mods:

 

 

Code from script sending the event

Event OnKeyDown(Int KeyCode)
  If  KeyCode == abim_IMS_ModActKeyGV.GetValue()
    If OldMAK != KeyCode
      OldMAK = KeyCode
      SendModEvent("abim_HotKeyInitiateEvent")
;     Debug.Notification("Initiating secondary script hot key registration")
    EndIf
  UnRegisterForAllKeys()
  EndIf
EndEvent

Code from script receiving the event

Event OnInit()
  ;snip
  MaintUpdate()
EndEvent

Function MaintUpdate()
  ;snip
  RegisterForModEvent("abim_HotKeyInitiateEvent","OnHotKeyInitiate")
  ;snip
EndFunction

Event OnHotKeyInitiate(string eventName, string strArg, float numArg, Form sender)
  UnregisterForAllKeys()
  Int MAK = abim_IMS_ModActKeyGV.GetValue() as Int
  If  MAK != -1.0
    RegisterForKey(MAK)
    OnKeyDown(MAK)
  EndIf
EndEvent

 

 

Link to comment
Share on other sites

If the objects to receive the mod event have not loaded yet, their OnInit events will not have run and thus never receive the mod event until a future load of the game after they have had their OnInit events run.

 

That's already taken care of. The objects are spawned with placeatme via scripts. Then I save the game, exit, load the game back, and expect the debug messages to show then that it's running, but it doesn't :smile:

 

Thanks, I'll check it out with SendModEvent, see if that works.

 

 

EDIT: I'm afraid there's no difference.

Changed the sender to:

 

    SendModEvent("GYHUpdateBookTitles")
    Debug.Notification("event sent ")   <--- seen

 

and the receiver to:

 

Event OnInit()
    RegisterForModEvent("GYHUpdateBookTitles", "GYHOnBookTitleUpdate")
EndEvent
 
Event GYHOnBookTitleUpdate(string eventName, string strArg, float numArg, Form sender)
    Debug.Notification("Modevent tried")   <--- not seen
EndEvent

 

The objects are books, and they are in the player inventory, if this matters maybe.

Link to comment
Share on other sites

Being in the player inventory does matter. I do not think that the OnInit event will run on items spawned in the player inventory. Also don't think that items in the player inventory will receive mod events. You can try adding a notification message to the OnInit block and see if that is indeed the issue.

Link to comment
Share on other sites

I'm not giving enough info again.

They are spawned in with PlaceAtMe so that they intiialize properly, and are only moved to player inventory after that (via courier).

So OnInit() runs correctly, also putting a notification message there

 

Maybe the references need to be persistent for this?

There's this comment on this page's notes:

 

ModEvent registrations are persistent and are stored in the MCBR record of the SKSE co-save. If you mod relies on these registrations being persistent it is strongly recommended that you register for the event again after each game load, if the user deletes this file for any reason it could break your mod.

 

So I don't know, maybe refs need to be persistent as well. I'll try if using placeatme with abForcePersist = true, see if that helps.

 

Regarding being in inventory, it could still be a problem, but for now they don't seem to receive the event even if I drop them out, save and come back either.

 

EDIT: No luck with forcing it to be persistent, still no received event, neither in the inventory, nor when dropped out.

I surely have my SKSE co-saves, I'm not even touching those. :ermm:

Link to comment
Share on other sites

I don't know. My only uses have been between quest scripts, alias scripts and scripts on pre-placed containers in an unconnected cell. I have had no reason to try with items that could be picked up or otherwise change their object reference ID.

 

You could try a failsafe registration for the mod event by using the OnContainerChanged event. That way it might "refresh" after moving in and out of inventory. Grasping at straws here, sorry.

Link to comment
Share on other sites

The aim of the thing is to force a display name update maintenance.

(Not through skse's SetDisplayName, as the objects are books, and I found threads that SetDisplayName can introduce various artifacts depending on the form type it's used on, and I can confirm it breaks text replacement inside the book text. No idea why. So name updating is done through alias renamings, that works for books as well.)

 

I tried registering via an explicit function, called by the script that spawns the objects, and still nothing.

So in the end I gave up on doing this with mod events.

 

My alternative is to permanently store the spawned object references on the script that creates them, and then the saved game load can just use this script to iterate over the refs.

The advantage of the mod event would have been that then I wouldn't have had to store the spawned refs permanently, possible gaining a bit of performance.

 

But I guess having to have one ObjectReference[] array with a large size is not yet the end of the world of the CPU going up in flames and stack dumps happening for every user. (Is it?)

Link to comment
Share on other sites

Stack dumps are more associated with large quantities of individual items (not large stacks) transferring in and out of the player inventory rather quickly. There are too many alias scripts even in the base game alone that do not use an inventory event filter when tracking the player inventory for a specific object that stack dumps can occur under such a scenario. All you'd need to be concerned with is if your process is currently still running should the player do such a crazy move. And there isn't much you could do about it anyway to be honest.

 

Your "alternative" is probably the better route anyway in all honesty.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...