GetCameraState

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 23:50, 8 September 2026 by QCherry (talk | contribs) (Document scripted camera API and events available from G1R:MP 0.1.3)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

getCameraState

AVAILABLE FROM UPDATE 0.1.3
This function is available in G1R:MP 0.1.3 and later. The contract below includes the compatibility guarantees introduced in that update.

Returns the complete last acknowledged camera-state snapshot cached for this client resource.

Syntax

table|false getCameraState()

Parameters

This function does not accept parameters.

Returns

A flat table containing x,y,z,pitch,yaw,roll,fov,playerX,playerY,playerZ,ready,active,moving,sampleTimeMs, or false when no snapshot is cached. Always check ready before using pose values.

Examples

Client-side: request a fresh snapshot and read it inside the matching callback.

-- Client-side: run after the local world and player camera are ready.
local query
addEventHandler("onClientCameraCommandResult", resourceRoot,
    function(requestId, ok, phase, errorText, stateJson)
        if requestId ~= query then return end
        query = nil
        if not ok or phase ~= "state" then
            outputDebugString("Camera query failed: " .. tostring(errorText), 2)
            return
        end
        local state = getCameraState()
        if not state or not state.ready then return end
        local actual = getCameraState()
        if actual then
            outputDebugString("Scripted camera active: " .. tostring(actual.active))
            outputDebugString("Camera moving: " .. tostring(actual.moving))
        end
    end)
query = requestCameraState()
if not query then outputDebugString("Camera query was not queued", 2) end

Notes

  • Client-side resource scripts only. Equivalent PascalCase spelling: GetCameraState. There is no server-side version.
  • This getter reads a per-resource cache, not the engine synchronously. requestCameraState refreshes it asynchronously without taking camera ownership.
  • A validated response updates the cache before onClientCameraCommandResult is dispatched. The cache is invalidated on lifecycle/connection changes.
  • A command's immediate applied/completed snapshot can precede the next rendered camera update. Request state after another frame or short timer to observe the updated view. See Scripted camera for field meanings and timing.