Difference between revisions of "OnPlayerTarget"

From NWN Lexicon
Jump to: navigation, search
m (Remarks)
 
Line 12: Line 12:
 
* [[GetTargetingModeSelectedObject]] - The object targeted by the player
 
* [[GetTargetingModeSelectedObject]] - The object targeted by the player
  
====Remarks====
+
====Setup====
  
 
'''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:  
 
'''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:  
Line 18: Line 18:
 
SetEventScript(GetModule(), EVENT_SCRIPT_MODULE_ON_PLAYER_TARGET, "script_name").
 
SetEventScript(GetModule(), EVENT_SCRIPT_MODULE_ON_PLAYER_TARGET, "script_name").
 
</nwscript>
 
</nwscript>
 +
 +
====Remarks====
  
 
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.
 
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.

Latest revision as of 01:36, 24 July 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.

The script attached to this event fires when EnterTargetingMode is activated.

Trigger

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

Function(s)

Setup

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").

Remarks

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. Items in inventories can be targeted.

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 targeted object is in an inventory or if the player has manually 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
        return;
    }

Known Bugs

Version

1.80.8193.14

Example

void main()
{
    // Get the last player to use targeting mode
    object oPC = GetLastPlayerToSelectTarget();
 
    // Get the targeting mode data
    object oTarget = GetTargetingModeSelectedObject();
    vector vTarget = GetTargetingModeSelectedPosition();
 
    // If the user manually exited targeting mode without selecting a target, return
    if (!GetIsObjectValid(oTarget) && vTarget == Vector())
        return;
 
    // Save the targeting data to the PC object for later use
    location lTarget = Location(GetArea(oTarget), vTarget, 0.0f);
 
    SetLocalObject(oPC, "TARGETING_OBJECT", oTarget);
    SetLocalLocation(oPC, "TARGETING_POSITION", lTarget);
}

See Also

functions:

EnterTargetingMode GetLastPlayerToSelectTarget GetTargetingModeSelectedPosition GetTargetingModeSelectedObject