Jump to content

[LE] Equivalent of custom events or callback functions?


Recommended Posts

I am stuck in a bit of a quandary here. I have mentioned in a couple other threads the teleport spell I am working on, and the help has been phenomenal. I have dynamic menus working by using Conditions and got my markers working for custom houses in other mods.

 

Now I am trying to kick it to a new level. I am trying to offload some of the custom house stuff to plugins for the mod. That way I can make a series of plugins that players can add in if they have a particular mod that adds a location or custom house and the appropriate item will be added to the teleport menu. The general structure would be as follows:

 

Base Teleport Mod
===============
Dependencies on Base Game and DLCs

GlobalVariable properties for all optional locations

Message Forms have entries for all locations possible with and without plugins with conditions set for the GlobalVariable properties to turn those menu options on or off.

Plugin Location Mod
================
Dependency on Base Teleport Mod and Mod with Custom Location to add to teleport list

OnLoadGame sets the appropriate GlobalVariable property in Base Mod to announce its presence so that the appropriate menu entry can be activated.

If needed it will add an XMarkerHeading the location where a good object to teleport to doesn't already exist.

Will have the function to perform the MoveTo(Location)

 

 

The problem I run into is that I need to be able to call the function in the Plugin Location Mod from the Base Game Mod.

 

Normally in other programming languages I would either do this by sending a pointer to the Base Mod to a callback function in the Plugin Mod, OR I would simply raise a user defined event in the Base Mod that gets handled by a event handler in the Plugin Mod.

 

Unfortunately, as far as I can tell, neither of these are possible in Papyrus with or without SKSE in Oldrim. Is there anything that can accomplish this task?

 

I don't ask to have all the code written for me, but any help is appreciated. I could sure use a good pointer.

 

Thanks

 

UPDATE:

 

One possible solution is for the Base Teleport Mod to place a series of hidden triggers or similar object somewhere in the vanilla world with dummy scripts in them with an empty MakeMyMove() function. The Plugin Mods would then modify these triggers by replacing the dummy script with the proper script that has a workable MakeMyMove() function to move the player. That way it could be referenced and called by the Base Game Mod. Seems a bit ugly and inelegant but doable. Is there a more elegant way to accomplish the same task?

Edited by MoomanFL70
Link to comment
Share on other sites

Calling a function from a secondary mod without directly linking? Doable.

 

You can use GetFormFromFile to obtain whatever record has the script containing the function you want to run. Cast it first into the appropriate record type then cast it into the script itself. From there run the function.

 

Something like:

;declare in the empty state
OtherModScriptName OMS

;define the local variable inside a function or event
OMS = (Game.GetFormFromFile(0x00123456,"SomeMod.esp") as Quest) as OtherModScriptName

;use local variable inside a function or event to use property values from the other script
If OMS.SomeProperty >= 23

;use local variable inside a function or event to call a function on the other script
OMS.SomeFunction()

You can also reverse the process if you would rather have the secondary plugin call a function or get values from a base mod script.

Link to comment
Share on other sites

Calling a function from a secondary mod without directly linking? Doable.

 

You can use GetFormFromFile to obtain whatever record has the script containing the function you want to run. Cast it first into the appropriate record type then cast it into the script itself. From there run the function.

 

The only drawbacks I see to this method is that the Base Mod MUST know about the Plugin Mod (exact file name and Form ID) meaning that any changes to the Plugin absolutely necessitates a change to the Base Mod as well. This would prevent anyone from renaming the plugin files for any reason lest they break the whole mod. While this isn't ideal, it is definitely doable, and quite possibly the best solution. My method in the UPDATE of my first post doesn't have this issue, but the drawback is placing quite possibly a large amount of hidden object clutter in the world... if it would even work. I admit that it is possible I might be overlooking something with that method that would make it unworkable.

 

Any other possible solutions? Preferably one that would keep the Base Mod blind to the plugin so that changes to the plugin would only need to be made in the plugin itself without a corresponding change the base mod?

Link to comment
Share on other sites

What if you create an activator (with no model) which the base mod spawns at the player then deletes itself. Plugins could then add their own scripts to the base object and run their logic inside OnInit() events.

 

AFAIK if the object has two scripts attached and each has an OnInit() event, both events would run concurrently, and all script functions would have to stop before it can be deleted. The base mod calls Delete() on the instantiated object, and once all scripts have stopped running it will be.

Link to comment
Share on other sites

SKSE implements a version of custom events..

 

I think I might have found what you are talking about. From Alias.psc :

; Registers a custom event callback for given event name.
; Registrations have to be refreshed after each game load.
;
;    Examples:
;        RegisterForModEvent("myCustomEvent", "MyModEventCallback")
;
;    Event signature of custom event callbacks:
;        Event MyModEventCallback(string eventName, string strArg, float numArg, Form sender)
;        endEvent
;
Function RegisterForModEvent(string eventName, string callbackName) native
Function UnregisterForModEvent(string eventName) native
Function UnregisterForAllModEvents() native

; Sends custom event with given generic parameters.
Function SendModEvent(string eventName, string strArg = "", float numArg = 0.0) native
Edited by MoomanFL70
Link to comment
Share on other sites

Not at all. Usually Google works really good to find what I need, but in this instance the only info on custom events for Skyrim returned info on the CustomEvent type which is the Fallout4/SkyrimSE version.

 

This is EXACTLY what I was looking for.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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