SetPlayerWeapon: Difference between revisions
Jump to navigation
Jump to search
Complete Lua function catalog |
Document upcoming 0.1.4 weapon confirmation and mouse camera APIs |
||
| Line 45: | Line 45: | ||
[[Category:Inventory Functions]] | [[Category:Inventory Functions]] | ||
[[Category:Equipment Functions]] | [[Category:Equipment Functions]] | ||
<!-- weapon-mouse014:start --> | |||
== Native confirmation since 0.1.4 (in development) == | |||
See [[Weapon control]]. setPlayerWeapon returns request acceptance, not completion. getPlayerWeapon remains the legacy single scripted choice, not the actual two-slot loadout. Use [[getPlayerWeaponState]] and [[onPlayerWeaponChangeResult]] for confirmed equipment. Matching client and server are required. | |||
<!-- weapon-mouse014:end --> | |||
Revision as of 13:53, 19 September 2026
setPlayerWeapon
Equips or clears a player's authoritative weapon slot.
Syntax
bool setPlayerWeapon(int playerId, string itemKey)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId |
int |
yes | The connected player identifier. |
itemKey |
string |
yes | A key returned by getPlayerWeaponNames, or "none" to clear the slot.
|
Returns
Returns true when the equipment change is accepted and replicated; otherwise returns false.
Examples
Example 1
Give an item and equip it in the weapon slot:
local itemKey = "1h_sword_01"
if givePlayerItem(playerId, itemKey) then
setPlayerWeapon(playerId, itemKey)
end
Example 2
Clear the weapon slot:
setPlayerWeapon(playerId, "none")
Notes
- Available only in server-side resource scripts.
- The player must own at least one copy of a non-empty item before it can be equipped.
- The selected appearance is reliably synchronized and included in late-join state.
Native confirmation since 0.1.4 (in development)
See Weapon control. setPlayerWeapon returns request acceptance, not completion. getPlayerWeapon remains the legacy single scripted choice, not the actual two-slot loadout. Use getPlayerWeaponState and onPlayerWeaponChangeResult for confirmed equipment. Matching client and server are required.