dizietemblesssma Posted December 3, 2023 Share Posted December 3, 2023 I'm trying to get my head around these, in this page: https://ck.uesp.net/wiki/ModEvent_Script things seem quite clear, a function ModEvent.Create creates an event and other functions decide what parameters it will have and then the script sends the event (I presume the ModEvent.Send(handle) could be also sent from outside the function that creates the event?) Those functions on that page are apparently 'Global', does this mean the created event can be received by anything? Or the event created by anything? However, this page: https://ck.uesp.net/wiki/SendModEvent is confusing. Does it send events created by the ModEvent script functions? If so is the SendModEvent adding/able to add more parameters to the event - SendModEvent(string eventName, string strArg = "", float numArg = 0.0) This page: https://ck.uesp.net/wiki/RegisterForModEvent_-_Form RegisterForModEvent(string eventName, string callbackName) explains: eventName: The name of the event sent by SendModEvent. callbackName: The name by which you can catch the event. but why does there need to be two 'names' for the event, it is custom so surely all it needs is a unique name? diziet Link to comment Share on other sites More sharing options...
dylbill Posted December 3, 2023 Share Posted December 3, 2023 To your second question, SendModEvent is different than ModEvent.Send. SendModEvent has pre defined parameters. if you look in Form.psc it's this: ; Sends custom event with given generic parameters. Function SendModEvent(string eventName, string strArg = "", float numArg = 0.0) native ModEvent.Send is for custom parameter types and amounts. You can have custom amounts of bool, int, float, string or form params, but make sure that the params in your event line up in the order that you push them to your handle. To make things easy, you could write a wrapper global function that you can use from any other script. Example: Scriptname MyCustomEvents Hidden Function SendMyCustomEvent(Form SomeForm, Int SomeInt) Global int handle = ModEvent.Create("MyModPrefix_MyCustomEvent") if (handle) ModEvent.PushForm(handle, SomeForm) ModEvent.PushInt(handle, SomeInt) ModEvent.Send(handle) endIf EndFunction then in another script: Event OnInit() RegisterForModEvent("MyModPrefix_MyCustomEvent", "OnMyCustomEvent") Actor playerRef = Game.GetPlayer() MyCustomEvents.SendMyCustomEvent(playerRef, playerRef.GetLevel()) EndEvent event OnMyCustomEvent(Form SomeForm, Int SomeInt) Debug.MessageBox(SomeForm + " " + SomeInt) EndEvent Link to comment Share on other sites More sharing options...
IsharaMeradin Posted December 3, 2023 Share Posted December 3, 2023 To answer one of your questions: The created mod event can be received by any other script so long as that script has registered for that particular event. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted December 3, 2023 Author Share Posted December 3, 2023 Thankyou both:) questions that arise: 1. Is the SendModEvent simply a convenience for ActiveMagicEffect Script, Alias Script and Form Script etc. or do you need it instead of ModEvent.Send for those script types? 2. Can an event be created by ModEvent.Create in a script and then sent multiple times from that script? i.e. does ModEvent.Send(handle) need to be sent from the same function that includes int handle = ModEvent.Create("MyModPrefix_MyCustomEvent") etc.? 3. Does the term 'release': Bool Send(Int handle) Sends the ModEvent and releases it. (Return value indicates whether it was successfully sent). mean that the event need to be recreated or simply that it can be resent (would answer point 2)? And apropos nothing, why am I a 'mentor' on this board?:) I have 12/14 but 14 what? If it is just volume of posts then I'm not sure asking a gazillion questions is an achievement to be proud of; answering them on the other hand, like you two, fair enough.:) diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted December 4, 2023 Share Posted December 4, 2023 I do not know the forum's ranking system. Especially since the forums recently went through an upgrade. SendModEvent and ModEvent.Send are two different things. The first, as dylbill stated, uses pre-set parameters that can be used to pass information along to the script(s) receiving the event. The second can be considered a "custom" mod event where one can explicitly state what parameters they want to send with the event. Use one or the other for a given event. SendModEvent does not tap into the ModEvent script functions. I have not used ModEvent.Send. Thus I have no new information to share in that regard. Here is a working example usage of SendModEvent: In my Inventory Management System mod for SSE there are interactions with merchants, crafting stations and other things that transfer stored items to the player inventory. Since these items are on formlists used by inventory event filters on several player alias scripts, each item would trigger the OnItemAdded event. This would cause unneeded processing. To avoid this, a mod event is sent using SendModEvent. The player alias scripts have registered for the event and receive the event where they clear the inventory event filter and add a new filter using a mod provided item. When the transfer of items is complete, a second mod event using SendModEvent ultimately tells the player alias scripts to re-instate the inventory event filters. Within an OnKeyUp event SendModEvent("abim_ClearFiltersEvent") CallWorkstationPrep(Ref) SendModEvent("abim_RestoreFiltersEvent") Within an OnUpdate event on the player alias script(s) RegisterForModEvent("abim_ClearFiltersEvent","ClearFilters") RegisterForModEvent("abim_RestoreFiltersEvent","RestoreFilters") On the player alias script: Event ClearFilters(string eventName, string strArg, float numArg, Form sender) RemoveAllInventoryEventFilters() AddInventoryEventFilter(TheRepItem) ; Debug.Trace("IMS:"+TheRepItem.GetName()+" ran ClearFilters event.") EndEvent Event RestoreFilters(string eventName, string strArg, float numArg, Form sender) If abim_IMS_ASGV.GetValue() != 0.0 If Game.GetModByName("IMS_Patch.esp") != 255 If RepItemIndex == 4 If abim_IMS_StationItemList != None AddInventoryEventFilter(abim_IMS_StationItemList) EndIf If abim_IMS_TemperAStationItemList != None AddInventoryEventFilter(abim_IMS_TemperAStationItemList) EndIf If abim_IMS_TemperWStationItemList != None AddInventoryEventFilter(abim_IMS_TemperWStationItemList) EndIf Else If abim_IMS_StationItemList != None AddInventoryEventFilter(abim_IMS_StationItemList) Else AddInventoryEventFilter(abim_IMS_ItemList) EndIf EndIf Else AddInventoryEventFilter(abim_IMS_ItemList) EndIf EndIf ; Debug.Trace("IMS:"+TheRepItem.GetName()+" ran RestoreFilters event.") EndEvent Link to comment Share on other sites More sharing options...
xkkmEl Posted December 4, 2023 Share Posted December 4, 2023 Once you have called "ModEvent.send", you cannot resend it. "and release it", means you don't need to worry about the handle any longer. Global script functions are just functions you call directly on the script (i.e. ModEvent.send, or Game.getPlayer); you do not need the script to be attached to a DB object. Link to comment Share on other sites More sharing options...
Recommended Posts