nwnxee / unified

Binaries available under the Releases tab on Github
https://nwnxee.github.io/unified
GNU General Public License v3.0
131 stars 92 forks source link

NWNX_Player_StartGuiTimingBar - Add OnInterrupted script/event #439

Closed Chimerik closed 5 years ago

Chimerik commented 5 years ago

Hi guys,

I would have a request about NWNX_Player_StartGuiTimingBar.

A PC can close that window by clicking on the cross at the top right.

It would be nice if this event could be caught and allow to fire some script. It would be cleaner to cancel all actions/effects created at the start of the timing bar.

Hope you can help!

Regards, Chim

plenarius commented 5 years ago

For your case I'd do something like:

Right before you run NWNX_Player_StartGuiTimingBar, do something like SetLocalString(oPC, "current_timer_event", "afk");

On Module Load: NWNX_Events_SubscribeEvent("NWNX_ON_TIMING_BAR_CANCEL_AFTER", "event_timingbar");

event_timingbar.nss

#include "nwnx_events"

void main()
{
    object oPC = OBJECT_SELF;
    if (!GetIsPC(oPC))
        return;

    string sCurrentEvent = NWNX_Events_GetCurrentEvent();
    if (sCurrentEvent == "NWNX_ON_TIMING_BAR_CANCEL_AFTER")
    {
        string sTimerEvent = GetLocalString(oPC, "current_timer_event");
        if (sTimerEvent == "afk")
        {
            SendMessageToPC(oPC, "Cancelling AFK");
            //Do whatever else you need to do
        }
    }
}