SetPlayerWeapon: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Document upcoming 0.1.4 weapon confirmation and mouse camera APIs
Release 0.1.4 BUILD133 / Protocol 36 and document authenticated event origin
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<!-- This page is generated automatically from the function definition: setPlayerWeapon. -->
= setPlayerWeapon =
= setPlayerWeapon =
Equips or clears a player's authoritative weapon slot.
'''Updated behavior since 0.1.4. This is an existing server function; the confirmation behavior below requires the matching 0.1.4 client and server. The current public release is 0.1.4 / Protocol 36.'''
 
Requests a native weapon equipment change for a player. Melee and ranged slots are independent; equipping one does not request clearing the other.


== Syntax ==
== Syntax ==
Line 14: Line 15:
| <code>playerId</code> || <code>int</code> || yes || The connected player identifier.
| <code>playerId</code> || <code>int</code> || yes || The connected player identifier.
|-
|-
| <code>itemKey</code> || <code>string</code> || yes || A key returned by <code>getPlayerWeaponNames</code>, or <code>"none"</code> to clear the slot.
| <code>itemKey</code> || <code>string</code> || yes || A supported weapon key from [[getPlayerWeaponNames]] or [[getPlayerRangedWeaponNames]], or <code>"none"</code> to request clearing both weapon slots.
|}
|}


== Returns ==
== Returns ==
Returns <code>true</code> when the equipment change is accepted and replicated; otherwise returns <code>false</code>.
In 0.1.4, <code>true</code> means the request was accepted for processing, not that the weapon is already equipped or its model displayed. <code>false</code> means the request was not accepted. Await [[onPlayerWeaponChangeResult]] and inspect [[getPlayerWeaponState]] for native confirmation.


== Examples ==
== Examples ==
=== Example 1 ===
=== Equip an owned bow ===
Give an item and equip it in the weapon slot:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua" line>
-- The player must own the item and satisfy its native requirements.
local itemKey = "1h_sword_01"
setPlayerWeapon(playerId, "bow_small_01")
if givePlayerItem(playerId, itemKey) then
    setPlayerWeapon(playerId, itemKey)
end
</syntaxhighlight>
</syntaxhighlight>
=== Example 2 ===
=== Clear both equipped weapons ===
Clear the weapon slot:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua" line>
-- Remove both equipped weapons without deleting owned inventory items.
setPlayerWeapon(playerId, "none")
setPlayerWeapon(playerId, "none")
</syntaxhighlight>
</syntaxhighlight>
These are independent examples; wait for the result before sequencing dependent equipment changes. A newer conflicting request supersedes the older pending request.


== Notes ==
== Notes ==
* Available only in server-side resource scripts.
* 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.
* Ownership and native equipment requirements apply. This function does not grant items/ammunition, increase stats, draw the weapon or change armor/identity.
* The selected appearance is reliably synchronized and included in late-join state.
* A request for the already equipped item is idempotent.
* Clearing requires a settled idle character with weapons sheathed and no active interaction. Confirmed clear includes native inventory and carry-visual cleanup.
* The updated server commits confirmed empty equipment to replication and late-join state. This is not a continuing lock: subsequent manual equipment changes remain allowed.
* Queue acceptance is not completion. Failure/timeout does not prove that no native change occurred; read current state before retrying.
* [[getPlayerWeapon]] is a legacy single server-side key, not a confirmed two-slot loadout.


See [[Weapon control]] for lifecycle, confirmation fields and failure handling.
[[Category:Lua Functions]]
[[Category:Lua Functions]]
[[Category:Server Functions]]
[[Category:Server Functions]]
Line 45: Line 49:
[[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 -->

Latest revision as of 20:41, 21 September 2026

setPlayerWeapon

Updated behavior since 0.1.4. This is an existing server function; the confirmation behavior below requires the matching 0.1.4 client and server. The current public release is 0.1.4 / Protocol 36.

Requests a native weapon equipment change for a player. Melee and ranged slots are independent; equipping one does not request clearing the other.

Syntax

bool setPlayerWeapon(int playerId, string itemKey)

Parameters

Name Type Required Description
playerId int yes The connected player identifier.
itemKey string yes A supported weapon key from getPlayerWeaponNames or getPlayerRangedWeaponNames, or "none" to request clearing both weapon slots.

Returns

In 0.1.4, true means the request was accepted for processing, not that the weapon is already equipped or its model displayed. false means the request was not accepted. Await onPlayerWeaponChangeResult and inspect getPlayerWeaponState for native confirmation.

Examples

Equip an owned bow

-- The player must own the item and satisfy its native requirements.
setPlayerWeapon(playerId, "bow_small_01")

Clear both equipped weapons

-- Remove both equipped weapons without deleting owned inventory items.
setPlayerWeapon(playerId, "none")

These are independent examples; wait for the result before sequencing dependent equipment changes. A newer conflicting request supersedes the older pending request.

Notes

  • Available only in server-side resource scripts.
  • Ownership and native equipment requirements apply. This function does not grant items/ammunition, increase stats, draw the weapon or change armor/identity.
  • A request for the already equipped item is idempotent.
  • Clearing requires a settled idle character with weapons sheathed and no active interaction. Confirmed clear includes native inventory and carry-visual cleanup.
  • The updated server commits confirmed empty equipment to replication and late-join state. This is not a continuing lock: subsequent manual equipment changes remain allowed.
  • Queue acceptance is not completion. Failure/timeout does not prove that no native change occurred; read current state before retrying.
  • getPlayerWeapon is a legacy single server-side key, not a confirmed two-slot loadout.

See Weapon control for lifecycle, confirmation fields and failure handling.