GetPlayerWeaponState

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search

getPlayerWeaponState

Since 0.1.4. Requires a compatible client and server.

Server function returning separate native melee/ranged observations and pending weapon requests.

table|false getPlayerWeaponState(int playerId)

Returns false for an unavailable player; otherwise returns a table with:

  • supported: whether the client has sent the native weapon report.
  • known: whether both native slots could be resolved. Unknown is not empty.
  • fresh: a known observation no older than 3 seconds while alive.
  • melee, ranged: observed catalog keys; "" means an empty slot when the observation is known.
  • pending: array of {requestId, itemKey}; a clear request uses "none".

This function observes inventory state, not global rendering completion. Empty slots can be observed even when a request later fails during carry-visual cleanup. For scripted completion, also await onPlayerWeaponChangeResult. Manual changes can make the current state differ from an earlier completed request.

local state = getPlayerWeaponState(playerId)
if state and state.known and state.fresh then
    -- Save state.melee and state.ranged separately in your database.
end

See Weapon control for ownership, lifecycle, timeouts and clearing behavior.