From NWN Lexicon
Revision as of 07:01, 11 February 2021 by Tinygiant (talk | contribs) (Remarks)
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 EnterTargetingMode is activated.


When EnterTargetingMode is used and the player either selects a target or manually exits targeting mode.



Note: A script for the OnPlayerTarget 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_TARGET, "script_name").

Upon entering targeting mode by using EnterTargetingMode, a player can target any game object or position, as limited by the EnterTargetingMode object type parameter. Once an object or position is targeted, of if the player manually exits targeting mode, the OnPlayerTarget event will be signalled.

The return values from the event data access functions will vary depending on the type of object selected. Generally, a player can only target a visible game object or position. DMs can target triggers if the "Show Triggers" option is selected.

GetTargetingModeSelectedObject will return the targeted object, or if targeting a position, it will return the area object where the position is located. If the player has exited targeting mode, this function will return an invalid object. For invalid objects, GetIsObjectValid will return FALSE and GetTargetingModeSelectedObject() == OBJECT_INVALID will evaluate to TRUE.

GetTargetingModeSelectedPosition will return the vector position of the targeted object. If the target is large, such as a placeable, the returned position is the approximate center point of the object. If the target is a trigger, the returned position is the coordinates of the first point of the trigger (as designed in the toolset). If the targeted object is OBJECT_TYPE_TILE, the returned position is the coordinates of the targeted position. If the player has exited targeting mode, the returned position is invalid and GetTargetingModeSelectedPosition == Vector() will evaluate to TRUE.

Since a player can successfully target the origin (0.0, 0.0, 0.0) of the area, the most reliable way to determine if the player has exited targeting mode without selecting a target is to test for object validity and vector value:

    object oTarget = GetTargetingModeSelectedObject();
    vector vTarget = GetTargetingModeSelectedPosition();
    if (!GetIsObjectValid(oTarget) && vTarget == Vector())
        // The player has exited targeting mode

Known Bugs




See Also


EnterTargetingMode GetLastPlayerToSelectTarget GetTargetingModeSelectedPosition GetTargetingModeSelectedObject