IsPlayerInTarget: Difference between revisions
Jump to navigation
Jump to search
Synchronize Lua API documentation |
Complete Lua function catalog |
||
| Line 43: | Line 43: | ||
* This is a geometric targeting helper. It does not perform an Unreal visibility trace and does not test world occlusion. | * This is a geometric targeting helper. It does not perform an Unreal visibility trace and does not test world occlusion. | ||
[[Category:Lua Functions]] | |||
[[Category:Server Functions]] | [[Category:Server Functions]] | ||
[[Category:Player Functions]] | [[Category:Player Functions]] | ||
[[Category:Spatial Functions]] | [[Category:Spatial Functions]] | ||
Latest revision as of 09:54, 15 August 2026
isPlayerInTarget
Checks whether one player is looking towards another player within a validated distance and field of view.
Syntax
bool isPlayerInTarget(int viewerPlayerId, int targetPlayerId [, number maximumDistance = 25 [, number fieldOfView = 60]])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
viewerPlayerId |
int |
yes | The player whose position and facing direction are tested. |
targetPlayerId |
int |
yes | The player that must be inside the viewer's target cone. |
maximumDistance |
number |
no | Maximum three-dimensional distance in metres, from 0.1 to 1000; defaults to 25. |
fieldOfView |
number |
no | Total horizontal field of view in degrees, from 1 to 180; defaults to 60. |
Returns
Returns true when both players are valid and the target is inside the viewer's distance and horizontal view cone; otherwise returns false.
Examples
Allow an interaction only while the other player is in front of the caller:
addCommandHandler("inspect", function(playerId, _, targetId)
targetId = tonumber(targetId)
if targetId and isPlayerInTarget(playerId, targetId, 4.0, 50.0) then
outputChatBox("The player is in your target.", playerId)
else
outputChatBox("Look at a nearby player first.", playerId)
end
end)
Notes
- Available only in server-side resource scripts.
- The check uses authoritative server positions and the viewer's replicated yaw.
- The aliases
ifPlayerIsInTargetandifPlayerisInTargetare available for compatibility. New scripts should useisPlayerInTarget. - This is a geometric targeting helper. It does not perform an Unreal visibility trace and does not test world occlusion.