OnPlayerGuiEvent

From NWN Lexicon
Revision as of 04:31, 24 July 2021 by Jasperre (talk | contribs)
Jump to: navigation, search
Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.

The script attached to this event fires when the player clicks on a particular GUI interface. It must be set using SetEventScript (for instance in OnModuleLoad).

Trigger

When a particular GUI is clicked on / opened / closed as applicable.

Function(s)

Setup

Note: A script for the OnPlayerTileAction event cannot be specified in module properties. There is no default script for this event, so no action will be taken unless a script is assigned to this event. To assign a script to this event, use this code:

SetEventScript(GetModule(), EVENT_SCRIPT_MODULE_ON_PLAYER_GUIEVENT, "script_name").

Remarks

This new EE event allows some interactions with the player with particular GUI events (not all of them!). Note there are also now more GUI panels you can open with PopUpGUIPanel and you can also disable most panels with SetGuiPanelDisabled which can trigger the GUIEVENT_DISABLED_PANEL_ATTEMPT_OPEN event type.

For specific uses see the different functions, which return different data based on how the event was triggered.

Note: interpreting a "proper" event versus one the game does automatically, such as GUIEVENT_MINIMAP_CLOSE, where the minimap automatically hides if more larger panels open on top of it, can be difficult. Make sure you test things a lot!

Of particular interest may be:

  • GUIEVENT_EFFECTICON_CLICK - You could display what spells and their durations are remaining attached to that particular effect icon
  • GUIEVENT_DEATHPANEL_WAITFORHELP_CLICK - You can do additional actions - you could even rename the button to be something more apt than "Wait for help".
  • GUIEVENT_MINIMAP_MAPPIN_CLICK - Apart from displaying further information, you could teleport a player to the pin
    • Note it won't work on custom pins. However you could detect the opening or closing event. You can then use the custom map pins for text input purposes (they get created as waypoints on the server)
  • GUIEVENT_PARTYBAR_PORTRAIT_CLICK - You can perhaps show additional information about a party member, associate or summoned creature, or allow a previous event to take into account the choice (eg; "Choose which party members to apply this buff to")
  • GUIEVENT_CHARACTERSHEET_FEAT_CLICK and GUIEVENT_CHARACTERSHEET_SKILL_CLICK could activate the given feats or skills in some additional way.
    • Possibly useful for adding more active custom feats and skills (skills more so since "Active skills" cannot be added to the game presently. EG: If you pick your newly made skill "Profession" it perhaps opens an appropriate conversation on what you want to do. Existing skills could be expanded this way as well - although generally non-combat ones!).
    • Could also display to the player some information about the current skill or feat, for instance, if SKILL_SPELLCRAFT is chosen it tells the player what bonuses versus spells their saves get. Or if you choose FEAT_BARD_SONGS you get a list of what effects would be applied with your current level and perform skill.


Known Bugs

Version

This event was added in 1.84.8193.29 of NWN:EE.


Example

// Simple example to use OnPlayerGuiEvent to display effect information or a variable from a party member
void main()
{
    // Event variables
    object oPlayer = GetLastGuiEventPlayer();
    int nEventType = GetLastGuiEventType();
    int nEventInteger = GetLastGuiEventInteger();
    object oEventObject = GetLastGuiEventObject();
 
    // Based on event type we do something
    switch(nEventType)
    {
        case GUIEVENT_EFFECTICON_CLICK:
        {
            // Report a quick bit of effect icon info if armor
            if(nEventInteger == EFFECT_ICON_AC_INCREASE)
            {
                effect eCheck = GetFirstEffect(oPlayer);
                string sReport;
                while(GetIsEffectValid(eCheck))
                {
                    if(GetEffectType(eCheck) == EFFECT_TYPE_AC_INCREASE)
                    {
                        sReport = "[AC increase] Type: " + IntToString(GetEffectInteger(eCheck, 0)) +
                                               " Amount: " + IntToString(GetEffectInteger(eCheck, 1)) +
                                               " Creator: " + GetName(GetEffectCreator(eCheck));
                        if(GetEffectDurationType(eCheck) == DURATION_TYPE_TEMPORARY)
                        {
                            sReport = sReport + " Duration remaining: " + IntToString(GetEffectDurationRemaining(eCheck)) + " seconds.";
                        }
                        SendMessageToPC(oPlayer, sReport);
                    }
                    eCheck = GetNextEffect(oPlayer);
                }
            }
        }
        break;
        case GUIEVENT_PARTYBAR_PORTRAIT_CLICK:
        {
            // We store a custom "Like you" factor, which we report
            string sReport = GetName(oEventObject) + " currently ";
            switch(GetLocalInt(oEventObject, "LIKE_FACTOR"))
            {
                // 0 would be perhaps another player or someone who doesn't have a "LIKE_FACTOR"
                case 0: return; break;
                case 1: sReport = sReport + " really likes you."; break;
                case 2: sReport = sReport + " neither likes or disklikes you."; break;
                case 3: sReport = sReport + " hates you."; break;
            }
            SendMessageToPC(oPlayer, sReport);
        }
        break;
    }
}

See Also

functions:

GetLastGuiEventPlayer GetLastGuiEventType GetLastGuiEventInteger GetLastGuiEventObject