GetPlayerItemCount: Difference between revisions
Automatyczna aktualizacja dokumentacji funkcji |
Release 0.1.9 / BUILD264 / Protocol42: availability and download setup; preserve experimental limits |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= getPlayerItemCount = | = getPlayerItemCount = | ||
Returns the | <div style="background:#fff5f5; border:1px solid #d13b3b; border-left:5px solid #d13b3b; color:#111111; padding:0.85rem 1rem; margin:0.75rem 0 1rem;"> | ||
<div style="color:#111111; font-weight:bold; letter-spacing:0.04em;">IMPROVED FROM UPDATE 0.1.2</div> | |||
<div style="color:#111111; margin-top:0.25rem;">This function is available in earlier releases and has corrected or expanded behavior in G1R:MP 0.1.2 and later. The contract below describes the updated behavior.</div> | |||
</div> | |||
Returns the quantity of a known inventory item in the player's authoritative server runtime cache. | |||
== Syntax == | == Syntax == | ||
| Line 31: | Line 35: | ||
== Notes == | == Notes == | ||
* Available only in server-side resource scripts. | * Available only in server-side resource scripts. | ||
* Inventory is server-authoritative. | * Inventory is server-authoritative. The runtime cache is updated by accepted native world-item pickups and drops, completed native consumable uses, and successful Lua inventory mutations. | ||
[[Category:Lua Functions]] | |||
[[Category:Server Functions]] | [[Category:Server Functions]] | ||
[[Category:Player Functions]] | [[Category:Player Functions]] | ||
[[Category:Inventory Functions]] | [[Category:Inventory Functions]] | ||
<!-- customkeys019:start --> | |||
'''Available from 0.1.9. Use matching updated server and clients.''' | |||
== Registered custom keys == | |||
This existing API also accepts the canonical item string from [[registerKeyDefinition]] in 0.1.9. Server registration, active definition and appropriate presentation readiness are required for mutations; use [[isPlayerKeyDefinitionReady]]. Do not pass the donor model alias as the custom item identity. Existing call shapes and limits remain; [[spawnItem]] creates one world item per call, whereas give/remove counts can manage copies. See [[Custom keys]] for safe server-side issuance, drop, pickup and persistence. | |||
<!-- customkeys019:end --> | |||
Latest revision as of 13:27, 20 October 2026
getPlayerItemCount
Returns the quantity of a known inventory item in the player's authoritative server runtime cache.
Syntax
int|false getPlayerItemCount(int playerId, string itemKey)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId |
int |
yes | The connected player identifier. |
itemKey |
string |
yes | A rune, armor, or melee weapon key from the server catalog. |
Returns
Returns the item quantity, including 0 when the player owns none, or false for an invalid player or item key.
Examples
Check how many copies of a sword a player owns:
local count = getPlayerItemCount(playerId, "1h_sword_01")
if count and count > 0 then
outputChatBox("Sword available", playerId)
end
Notes
- Available only in server-side resource scripts.
- Inventory is server-authoritative. The runtime cache is updated by accepted native world-item pickups and drops, completed native consumable uses, and successful Lua inventory mutations.
Available from 0.1.9. Use matching updated server and clients.
Registered custom keys
This existing API also accepts the canonical item string from registerKeyDefinition in 0.1.9. Server registration, active definition and appropriate presentation readiness are required for mutations; use isPlayerKeyDefinitionReady. Do not pass the donor model alias as the custom item identity. Existing call shapes and limits remain; spawnItem creates one world item per call, whereas give/remove counts can manage copies. See Custom keys for safe server-side issuance, drop, pickup and persistence.