IsharaMeradin Posted July 28, 2019 Share Posted July 28, 2019 Well, ReDragon2013, close but not quite. Unless the intent is to only be able to send the mod event after the game has been loaded. OnPlayerLoadGame will not run the first time the quest starts when the game is started for the first time with the mod in question. Thus, the mod event will never be sent until another game load. Using the OnInit event to register for the mod event or to call a maintenance function designed to handle all things needed both on first load and subsequent loads is required for the mod event to be sent during the first play session. Something that should be remembered, for anyone reading, the registration of the mod event is required on the script receiving the mod event. The mod event itself can be sent from any number of other scripts without registration. Thus RegisterForModEvent and the custom event are always on the same script. While SendModEvent can be on a different script. Here is a working example that I had grafted into an already built mod to handle updating a hotkey assignment. The sending script: 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 The receiving script: Event OnInit() RegisterForModEvent("abim_HotKeyInitiateEvent","OnHotKeyInitiate") Event OnPlayerLoadGame() RegisterForModEvent("abim_HotKeyInitiateEvent","OnHotKeyInitiate") 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) ; Debug.Notification("Hot key registration complete") OnKeyDown(MAK) EndIf EndEvent For the curious, the issue here is that while the global variable being checked against the pressed key can be updated easily, the registration for the key to listen to is not as easily updated. Thus after the key has been changed the initial script registers for that key press and sends the mod event. The script with the primary OnKeyDown event catches the sent event, updates the registered key and then calls the OnKeyDown event directly thus giving the user a seamless experience. Link to comment Share on other sites More sharing options...
PeterMartyr Posted July 28, 2019 Share Posted July 28, 2019 @ IsharaMeradin my receiving script is ActiveMagicEffect, that not attached to player and... I went What The Hell, I can't register this for a maintenance on player load game. According to the literature it was never going to work. To my complete and utter surprise, it worked fine. I couldn't believe it. I still can't. I swear it works without a maintenance code on a Active Magic Effect, the registration (for me) is persistent between game saves. I only need it for that, and have never used any other way, so of course I would test any other implementation for persistence. But it surprise me, is all I am going say. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 28, 2019 Share Posted July 28, 2019 @PeterMartyr There very well could be undocumented features or unexpected behavior that was not written into the available documentation. Still, the registration for the mod event is on the same script as the receiving event and that is the important thing to get across. As long as the registration takes place prior, the event should be properly received. The reason I brought it up was that in ReDragon's example there was no initial registration. It relied solely on the OnPlayerLoadGame which would cause failure of the event to run if the sending was done during that initial session. Thus I shared my one and only working example which demonstrated this point. At no point did I intend to state that an ActiveMagicEffect or any other script type could not be used. Just wanted to reinforce that the registration and receiving event both needed to be on the same script. Link to comment Share on other sites More sharing options...
Aigi9 Posted September 7, 2021 Share Posted September 7, 2021 I'm not sure if you have solved it yet since it has been two years now but... I had the same problem. ModEvent.Send didn't trigger registered event in other script. SendModEvent() worked but it lacks the custom arguments other than string and float. I was desperate but then I tried to run UnregisterForModEvent("EventName") just before RegisterForModEvent("EventName", "CustomEvent") and it started to work. I hope this will help... if not to you, maybe to other desperate amateur modders struggling with the same problem. Link to comment Share on other sites More sharing options...
Recommended Posts