Jump to content

[LE] Trying to get ModEvents working between two mods


Recommended Posts

I could really use some help here. (Big surprise :laugh:)

 

In trying to get my teleport spell mod working, I decided to offload the code for some of the locations into separate mods that will act as plugins to the main mod. As per a previous thread here I decided the best way to accomplish what I wanted was to put all menu codes for all supported locations in the Base Mod, but only include the MoveTo code of the vanilla and DLC locations there. The MoveTo code for all custom locations would be in separate mods meant as a plugin to the Base Mod. Communication between the two would be accomplished through the ModEvent functions (SendModEvent, RegisterForModEvent). That way I could have the Base Mod blind (not dependent on a specific reference) to the plugin but still trigger an event.

 

After further research I found that the plugin side of the scripts should be attached to a quest, and this is where I have run into a problem.

 

I did the following things:

 

  1. Added a SendModEvent to my Base Plugin code at the spot that I wanted.
  2. Created a new mod to be my test plugin.
  3. Changed by Base Mod's flag to ESM temporarily while editing my plugin mod
  4. Used Wrye Bash to add a dependency to the Base Mod to my plugin mod
  5. Added a new empty quest to the plugin and gave it a reference ID
  6. On the Quest Stages tab I added a new Index (0) and checked "Start Up Stage"
  7. On the Quest Aliases I added a new reference alias
  8. I gave it a reference ID
  9. Under "Fill Type" I selected Unique Actor and set it to "Player"
  10. I then added a script to the reference and gave it the following code:
Scriptname _000MoomanPlayerTestALIASSCRIPT extends ReferenceAlias

Function OnInit()
	; My code runs here ...
	RegisterForModEvent("MyEvent", "OnMyMenuItemClicked")
	Debug.MessageBox("Alias Loaded")
EndFunction

Event OnMyMenuItemClicked()

	Debug.MessageBox("My Button Clicked")

endEvent

I compiled and saved the script. Clicked "OK" to close out all boxes and saved the mod. When I run the game however, I get the "Alias Loaded" message at startup on loading a save, but when I cast the spell and click on the menu option that fires the event, nothing happens. The spell effect visibly fires, but I don't get the "My Button Clicked" message.

 

I am sure I have gotten something wrong, but I have no idea where. Any help is appreciated.

Link to comment
Share on other sites

Try a new game rather than a save file. It could be possible that changes made to the base mod's script are not being reflected and thus not sending the event as expected.

 

Since it is not posted, double check and ensure that the SendModEvent is written properly with the correct data in the correct parameters.

Link to comment
Share on other sites

Try a new game rather than a save file. It could be possible that changes made to the base mod's script are not being reflected and thus not sending the event as expected.

 

Since it is not posted, double check and ensure that the SendModEvent is written properly with the correct data in the correct parameters.

 

I know that the changes to the Base Mod took effect because previously I had code in that spot that did the teleport directly, however at the same time that I put the SendModEvent code in, I commented out the teleport code. When I use the spell and choose that menu option no teleport happens as it did previously... but I don't get a result from the event either. The only parameter I used was the name of the event, and I copied and pasted it between the mods.

 

I will still try (tomorrow) with a new save, but seeing as the other change I made at the same time took effect I am doubting that this is the problem. I suspect I don't have something right with how I have the quest set up, or I am missing something else.

Link to comment
Share on other sites

It says on the CK wiki that you must register for mod events after every game load. So you would need an event handler to re-bind your event on player game load, in addition to init.

Edited by npdogg
Link to comment
Share on other sites

That is what RegisterForModEvents("MyEventName") does, correct? If so then I can confirm that the function carrying that code fired before I tried using the event, and I still did not get the result.

 

If not then I don't understand what you mean. Could you be more specific.

Link to comment
Share on other sites

You didn't reply to IsharaMeradin request so....

 

Where are your Handles? What are you Pushing? If you expect help where is the primary script that creates the Event?

 

All you showing is the receiving one, so we have no way of seeing what you doing wrong.

 

What that is, as I stated no one can see.

 

Your using a Magic Effect & and a Reference Alias, no clean save require at all. And I can tell, the Alias is filled correctly to.

 

Show us how you create and release the Event that you say isn't working? If you seriously expect help?

 

Script 1

Function CreateDispellEvent(Form Sender)

	Int handle = ModEvent.Create("FDQ_CustomDispel")
	If handle
		ModEvent.PushForm(handle, Sender)
		ModEvent.Send(handle)
	EndIf
EndFunction
OnCustomDispel(self)

Script 2

Self.RegisterForModEvent("FDQ_CustomDispel", "OnCustomDispel") 
Event OnCustomDispel(Form sender)

	; ....
EndEvent 

That one of mine, there not much too it, but changing the parameters on a dirty save? Don't do it. But you shouldn't have any problems at First Time Run Time. I never have.

 

Edit

 

Of course you can have extra custom parameters, I only needed one.

Link to comment
Share on other sites

You didn't reply to IsharaMeradin request so....

ÃÃÃÂ

Where are your Handles? What are you Pushing? If you expect help where is the primary script that creates the Event?

ÃÃÃÂ

All you showing is the receiving one, so we have no way of seeing what you doing wrong.

ÃÃÃÂ

What that is,ÃÃÃÂ as I stated no one can see.

ÃÃÃÂ

Your using a Magic Effect & and a Reference Alias, no clean save require at all. And I can tell, the Alias is filled correctly to.

ÃÃÃÂ

Show us how you create and release the Event that you say isn't working? If you seriously expect help?ÃÃÃÂ

ÃÃÃÂ

Script 1

Function CreateDispellEvent(Form Sender)

	Int handle = ModEvent.Create("FDQ_CustomDispel")
	If handle
		ModEvent.PushForm(handle, Sender)
		ModEvent.Send(handle)
	EndIf
EndFunction
OnCustomDispel(self)
Script 2
Self.RegisterForModEvent("FDQ_CustomDispel", "OnCustomDispel")ÃÃÃÂ 
Event OnCustomDispel(Form sender)

	; ....
EndEventÃÃÃÂ 
That one of mine, there not much too it, but changing the parameters on a dirty save? Don't do it. But you shouldn't have any problems at First Time Run Time. I never have.

ÃÃÃÂ

Edit

ÃÃÃÂ

Of course you can have extra custom parameters, I only needed one.

IsharaMeridan's request was that I double check my parameters to make sure they were correct. I did that. There is only one parameter in my SendModEvent function as follows.

 

SendModEvent("MyEvent")

This is a little different than your code. Mine is in Alias.psc along with RegisterForModEvent. It is detailed here and seems to only require the event name per the example on this page.

 

https://www.creationkit.com/index.php?title=SendModEvent

 

I wasn't familiar with your method but I will give it a try.

 

UPDATE: I gave your code a try and it worked great. Thank you. One thing I noticed though that caused a side question. How do you pass a reference to the sending form. I notice you have the declaration "Form Sender" in your function header. In the example code for the ModEvent class they use:

ModEvent.PushForm(handle, self)

I would expect this to work based off of the behavior of most form based programming languages. However when I tried to compile it with the parameter of "self" it kicked back an error. What is the proper way to send the reference?

Edited by MoomanFL70
Link to comment
Share on other sites

Armmmm What are you trying to Push? These are the Variables

Function PushBool(int handle, bool value) global native
Function PushInt(int handle, int value) global native
Function PushFloat(int handle, float value) global native
Function PushString(int handle, string value) global native
Function PushForm(int handle, Form value) global native

Glad it work you, remember it wasn't design to be copied verbatim, just point you in the right direction

Link to comment
Share on other sites

With SKSE you will find

ModEvent.psc

Read it, use the wikki to Clarify your understand of what you are reading. To better understand what it does. In regard to what you are pushing, the answer is what you trying to communicate between the two Mods. Or Validate. So if this or that with a ElseIf. This really depends on what you are trying to achieve???? and what your needs are.. Be imaginative, there is no set way in coding. Make it happen.

 

Good luck you have all the information you need. Good Modding.

Link to comment
Share on other sites

I am not really familiar with such kind of event handling. Next sample code should you explain how to does it work.

Scriptname xyzSampleModEventAliasScript extends ReferenceAlias
; runs on the player alias that need a new quest created by you
; https://forums.nexusmods.com/index.php?/topic/7847383-trying-to-get-modevents-working-between-two-mods/

; -- EVENTs -- SKSE required !!!

; https://www.creationkit.com/index.php?title=RegisterForModEvent_-_Form
; https://www.creationkit.com/index.php?title=SendModEvent

EVENT OnInit()
    Debug.Trace("OnInit() has been reached for.. " +self)        ; log info only
    RegisterForModEvent("MyEvent", "OnMenuItemClicked")    ;* edited caused of IsharaMeradin
ENDEVENT

EVENT OnPlayerLoadGame()        ; You must register for ModEvents after every game load!
; eventName    = "MyEvent"
; callbackName = "OnMenuItemClicked"
    OnInit()                                               ;* edited caused of IsharaMeradin
ENDEVENT


EVENT OnCellLoad()                ; this is only a sample to trigger the send function
    SendModEvent("MyEvent")        ; send the event without any parameters, next custom event should be called immediately
ENDEVENT


; -- Custom EVENT --  mod event can be here or in any other script like ActiveMagicEffect for example

EVENT OnMenuItemClicked(String eventName, String strArg, Float numArg, Form sender)
IF (eventName == "MyEvent")
    Debug.MessageBox("My button has been clicked!")
ENDIF
ENDEVENT
Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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