IsPlayerInTarget

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 09:54, 15 August 2026 by QCherry (talk | contribs) (Complete Lua function catalog)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 ifPlayerIsInTarget and ifPlayerisInTarget are available for compatibility. New scripts should use isPlayerInTarget.
  • This is a geometric targeting helper. It does not perform an Unreal visibility trace and does not test world occlusion.