Difference between revisions of "NuiGetEventPayload"

From NWN Lexicon
Jump to: navigation, search
(initial creation)
 
Line 15: Line 15:
  
 
Returns JsonNull if event has no payload.
 
Returns JsonNull if event has no payload.
 
  
 
====Version====
 
====Version====
Line 23: Line 22:
  
 
====Example====
 
====Example====
{{examples needed}}
+
 
 +
This example will play a sound of clicking when player left-clicks at specific coordinates inside NUI image (as images don't have click event, but they are generating mousedown and mouseup events).
 +
<nwscript>
 +
void main()
 +
{
 +
    //Declare major variables
 +
    object oPC = NuiGetEventPlayer();
 +
    int    nToken  = NuiGetEventWindow();
 +
    string sEvent  = NuiGetEventType();
 +
    string sElem  = NuiGetEventElement();
 +
    int    nIdx    = NuiGetEventArrayIndex();
 +
    string sWndId  = NuiGetWindowId(oPC, nToken);
 +
 
 +
 
 +
    if(sWndId == "myshinygui")
 +
    {
 +
        if(sEvent == "mousedown")
 +
        {
 +
            json jPayload = NuiGetEventPayload();
 +
            json jKeys = JsonObjectKeys(jPayload);
 +
            json jButton = JsonObjectGet(jPayload,"mouse_btn");
 +
            json jCoords = JsonObjectGet(jPayload,"mouse_pos");
 +
            json jX = JsonObjectGet(jCoords,"x");
 +
            json jY = JsonObjectGet(jCoords,"y");
 +
            float fX = JsonGetFloat(jX);
 +
            float fY = JsonGetFloat(jY);
 +
            int nButton = JsonGetInt(jButton);//0 - left button, 1 - middle button, 2 - right buttons, it seems that special mouse buttons are not tracked
 +
            if(nButton == 0)
 +
            {
 +
                if(fX >= 325.0 && fX <= 340.0)
 +
                {
 +
                    if(fY >= 5.0 && fY <= 20.0)//up button
 +
                    {
 +
                        AssignCommand(oPC,PlaySound("gui_button"));
 +
                    }
 +
                    else if(fY >= 25.0 && fY <= 40.0)//down button
 +
                    {
 +
                        AssignCommand(oPC,PlaySound("gui_button"));
 +
                    }
 +
                }
 +
            }
 +
        }
 +
    }
 +
}
 +
</nwscript>
  
  
Line 33: Line 76:
 
[[:Category:NUI_Functions|NUI Functions]]
 
[[:Category:NUI_Functions|NUI Functions]]
 
|}
 
|}
 +
----
 +
----
 +
<font color="gray">  author: Shadooow</font>
  
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:NUI_Functions]]
 
[[Category:NUI_Functions]]

Revision as of 07:37, 21 November 2021

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.

Returns the event payload, specific to the event.

json NuiGetEventPayload(
);


Description

Returns the event payload, specific to the event.


Remarks

Returns JsonNull if event has no payload.

Version

This function was added in 1.85.8193.31 of NWN:EE.


Example

This example will play a sound of clicking when player left-clicks at specific coordinates inside NUI image (as images don't have click event, but they are generating mousedown and mouseup events).

void main()
{
    //Declare major variables
    object oPC = NuiGetEventPlayer();
    int    nToken  = NuiGetEventWindow();
    string sEvent  = NuiGetEventType();
    string sElem   = NuiGetEventElement();
    int    nIdx    = NuiGetEventArrayIndex();
    string sWndId  = NuiGetWindowId(oPC, nToken);
 
 
    if(sWndId == "myshinygui")
    {
        if(sEvent == "mousedown")
        {
            json jPayload = NuiGetEventPayload();
            json jKeys = JsonObjectKeys(jPayload);
            json jButton = JsonObjectGet(jPayload,"mouse_btn");
            json jCoords = JsonObjectGet(jPayload,"mouse_pos");
            json jX = JsonObjectGet(jCoords,"x");
            json jY = JsonObjectGet(jCoords,"y");
            float fX = JsonGetFloat(jX);
            float fY = JsonGetFloat(jY);
            int nButton = JsonGetInt(jButton);//0 - left button, 1 - middle button, 2 - right buttons, it seems that special mouse buttons are not tracked
            if(nButton == 0)
            {
                if(fX >= 325.0 && fX <= 340.0)
                {
                    if(fY >= 5.0 && fY <= 20.0)//up button
                    {
                        AssignCommand(oPC,PlaySound("gui_button"));
                    }
                    else if(fY >= 25.0 && fY <= 40.0)//down button
                    {
                        AssignCommand(oPC,PlaySound("gui_button"));
                    }
                }
            }
        }
    }
}


See Also

functions:

NUI Functions



author: Shadooow