Jump to content

OnPackageStart/End/Change Events Never Called


Recommended Posts

Thanks everyone for contributing to the discussion! So it seems that the package events are bugged. That's very unfortunate.

 

I can see a couple of workaround solutions to this issue.

  1. Use a timer and poll for package changes via GetCurrentPackage().
  2. Attach a proxy script to a package, which will forward the events to some kind of propagator script, which in turn will raise events for any interested subscribers.

Since I have full control over my custom packages and I really don't like polling, I ended up implementing the second solution. It's a bit more complex than using a timer, but it doesn't use polling and I receive events only from the packages I want. Here is an example:

 

 

Proxy Script

Scriptname SomeNS:PackageEventProxyScript extends Package
{This script is a part of the workaround solution to the package events bug when package events are not called
in ReferenceAlias or ActiveMagicEffect. Attach this script to a package from which you want to receive events
and set the EventPropagatorScript property. The EventPropagatorScript is the other script in the solution.
See its documentation comment for more information.}

SomeNS:EventPropagatorScript Property EventPropagatorScript Auto Const

Event OnChange(Actor akActor)
    Debug.Trace("This package finished or was preempted on " + akActor)
    EventPropagatorScript.PropagatePackageChange(akActor, self)
EndEvent

Event OnStart(Actor akActor)
    Debug.Trace("This package started on " + akActor)
    EventPropagatorScript.PropagatePackageStart(akActor, self)
EndEvent

Event OnEnd(Actor akActor)
    Debug.Trace("This package finished on " + akActor)
    EventPropagatorScript.PropagatePackageEnd(akActor, self)
EndEvent

Propagator Script

Scriptname SomeNS:EventPropagatorScript extends Quest
{This script is a part of the workaround solution to the package events bug when package events are not called
in ReferenceAlias or ActiveMagicEffect. Attach this script to a quest, which will serve as an event propagator.
Packages that you are interested to receive the events from, should contain the PackageEventProxyScript script
(see PackageEventProxyScript documentation comment for more information).
Then, in any script you can register for custom events defined here and the relevant events will be propagated
to that script.}

CustomEvent OnPropagatePackageChange
CustomEvent OnPropagatePackageStart
CustomEvent OnPropagatePackageEnd

Function PropagatePackageChange(Actor akActor, Package akPackage)
    Var[] args = new Var[2]
    args[0] = akActor
    args[1] = akPackage
    sendCustomEvent("OnPropagatePackageChange", args)
EndFunction

Function PropagatePackageStart(Actor akActor, Package akPackage)
    Var[] args = new Var[2]
    args[0] = akActor
    args[1] = akPackage
    sendCustomEvent("OnPropagatePackageStart", args)
EndFunction

Function PropagatePackageEnd(Actor akActor, Package akPackage)
    Var[] args = new Var[2]
    args[0] = akActor
    args[1] = akPackage
    sendCustomEvent("OnPropagatePackageEnd", args)
EndFunction

EventPropagatorScript Function GetEventPropagatorScript() global
    ; Set the quest's FormID and the mod file name to valid values.
    Return (Game.GetFormFromFile(0x000000, "<ModName>.esp") as Quest) as EventPropagatorScript
EndFunction

Sample Subscriber Script

Scriptname SomeNS:SubscriberScript extends ObjectReference

import SomeNS:EventPropagatorScript
SomeNS:EventPropagatorScript kEventPropagatorScript

Function OnInit()
    kEventPropagatorScript = GetEventPropagatorScript()
    RegisterForCustomEvent(kEventPropagatorScript, "OnPropagatePackageEnd")
EndFunction

Event SomeNS:EventPropagatorScript.OnPropagatePackageEnd(SomeNS:EventPropagatorScript akSender, Var[] args)
    Debug.Trace("OnPropagatePackageEnd fired. args = " + args)
    Actor packageActor = args[0] as Actor
    Package finishedPackage = args[1] as Package
EndEvent
Link to comment
Share on other sites

It's possible those functions now only work on the actor with packages, and not a reference alias with an alias package.

If that's the case, it would be possible to set up a RegisterForRemoteEvent call on the actor.

Link to comment
Share on other sites

 

It's possible those functions now only work on the actor with packages, and not a reference alias with an alias package.

If that's the case, it would be possible to set up a RegisterForRemoteEvent call on the actor.

 

Well, someone was on the right track :P

 

I dug into my scripts to double-check but yeah, the only one which actually returned is GetCurrentPackage(), it's almost as if we were missing some RegisterForPackage(Actor akActor, Package akPackage) function!.. Don't use that, ok, that function doesn't exist!..

 

Have you tried attaching a script directly on the package itself?

Link to comment
Share on other sites

It's possible those functions now only work on the actor with packages, and not a reference alias with an alias package.

If that's the case, it would be possible to set up a RegisterForRemoteEvent call on the actor.

Did anyone try either of these solutions? RegisterForRemoteEvent or attaching directly to Actor?

Edited by z4x
Link to comment
Share on other sites

...

 

I also tried to register for package events using RegisterForRemoteEvent() from a different script, but got the same result: OnCommandModeGiveCommand() was called but OnPackageXXX() were not.

 

As I already mentioned, RegisterForRemoteEvents() didn't work for me.

I haven't tried to attach a script directly to an Actor, since it would be impractical for my mod.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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