Difference between revisions of "OnPlayerTarget"
m (→Trigger) |
m (→Remarks) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
====Remarks==== | ====Remarks==== | ||
− | '''Note:''' | + | '''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: |
+ | <nwscript> | ||
+ | SetEventScript(GetModule(), EVENT_SCRIPT_MODULE_ON_PLAYER_TARGET, "script_name"). | ||
+ | </nwscript> | ||
− | + | 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: | |
+ | <nwscript> | ||
+ | object oTarget = GetTargetingModeSelectedObject(); | ||
+ | vector vTarget = GetTargetingModeSelectedPosition(); | ||
+ | |||
+ | if (!GetIsObjectValid(oTarget) && vTarget == Vector()) | ||
+ | { | ||
+ | // The player has exited targeting mode | ||
+ | return; | ||
+ | } | ||
+ | </nwscript> | ||
====Known Bugs==== | ====Known Bugs==== | ||
Line 35: | Line 46: | ||
====Example==== | ====Example==== | ||
+ | <nwscript> | ||
+ | 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); | ||
+ | } | ||
+ | </nwscript> | ||
====See Also==== | ====See Also==== |
Latest revision as of 07:12, 11 February 2021
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)
- GetLastPlayerToSelectTarget - The player that has targeted something
- GetTargetingModeSelectedPosition - The vector in the current area targeted by the player
- GetTargetingModeSelectedObject - The object targeted by the player
Remarks
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. 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
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 |