GetPlayerWeaponState: Difference between revisions
Jump to navigation
Jump to search
Document upcoming 0.1.4 weapon confirmation and mouse camera APIs |
Clarify 0.1.4 weapon clearing, manual equipment and confirmation APIs |
||
| Line 1: | Line 1: | ||
= getPlayerWeaponState = | = getPlayerWeaponState = | ||
'''Since 0.1.4 (in development; not in public 0.1.3).''' | '''Since 0.1.4 (in development; not in public 0.1.3). Requires a compatible client and server.''' | ||
Server function | Server function returning separate native melee/ranged observations and pending weapon requests. | ||
See [[Weapon control]] for | <syntaxhighlight lang="lua"> | ||
table|false getPlayerWeaponState(int playerId) | |||
</syntaxhighlight> | |||
Returns <code>false</code> for an unavailable player; otherwise returns a table with: | |||
* <code>supported</code>: whether the client has sent the native weapon report. | |||
* <code>known</code>: whether both native slots could be resolved. Unknown is not empty. | |||
* <code>fresh</code>: a known observation no older than 3 seconds while alive. | |||
* <code>melee</code>, <code>ranged</code>: observed catalog keys; <code>""</code> means an empty slot when the observation is known. | |||
* <code>pending</code>: array of <code>{requestId, itemKey}</code>; a clear request uses <code>"none"</code>. | |||
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. | |||
<syntaxhighlight lang="lua"> | |||
local state = getPlayerWeaponState(playerId) | |||
if state and state.known and state.fresh then | |||
-- Save state.melee and state.ranged separately in your database. | |||
end | |||
</syntaxhighlight> | |||
See [[Weapon control]] for ownership, lifecycle, timeouts and clearing behavior. | |||
[[Category:Lua API]] | [[Category:Lua API]] | ||
[[Category:Server Functions]] | [[Category:Server Functions]] | ||
[[Category:Lua Functions]] | [[Category:Lua Functions]] | ||
Revision as of 13:42, 20 September 2026
getPlayerWeaponState
Since 0.1.4 (in development; not in public 0.1.3). 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.