<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://g1r-mp.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Weapon_control</id>
	<title>Weapon control - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://g1r-mp.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Weapon_control"/>
	<link rel="alternate" type="text/html" href="https://g1r-mp.com/wiki/index.php?title=Weapon_control&amp;action=history"/>
	<updated>2026-09-19T15:45:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://g1r-mp.com/wiki/index.php?title=Weapon_control&amp;diff=901&amp;oldid=prev</id>
		<title>QCherry: Document upcoming 0.1.4 weapon confirmation and mouse camera APIs</title>
		<link rel="alternate" type="text/html" href="https://g1r-mp.com/wiki/index.php?title=Weapon_control&amp;diff=901&amp;oldid=prev"/>
		<updated>2026-09-19T13:53:44Z</updated>

		<summary type="html">&lt;p&gt;Document upcoming 0.1.4 weapon confirmation and mouse camera APIs&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Weapon control =&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Confirmation APIs and corrected weapon request handling: since 0.1.4 (in development). Public 0.1.3 does not expose these additions. Use the matching client and server.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Requests versus completed equipment ==&lt;br /&gt;
&amp;lt;code&amp;gt;setPlayerWeapon(playerId, itemKey)&amp;lt;/code&amp;gt; still returns boolean queue acceptance, not native completion. Melee and ranged slots are independent. A request for the already equipped item is idempotent. &amp;lt;code&amp;gt;&amp;quot;none&amp;quot;&amp;lt;/code&amp;gt; requests clearing both slots without deleting inventory. Ownership and native equipment requirements apply; the function does not grant ammunition, bypass stats, draw a weapon or change armor.&lt;br /&gt;
&lt;br /&gt;
[[getPlayerWeapon]] remains the legacy single scripted choice and is not a complete or confirmed two-slot loadout. Failed requests do not roll back that legacy choice. Use [[getPlayerWeaponState]] and [[onPlayerWeaponChangeResult]] when saving equipment or sequencing changes.&lt;br /&gt;
&lt;br /&gt;
== Confirmed state ==&lt;br /&gt;
&amp;lt;code&amp;gt;getPlayerWeaponState(playerId)&amp;lt;/code&amp;gt; returns false if unavailable, otherwise a table:&lt;br /&gt;
* &amp;lt;code&amp;gt;supported&amp;lt;/code&amp;gt;: the client has sent the new native report.&lt;br /&gt;
* &amp;lt;code&amp;gt;known&amp;lt;/code&amp;gt;: both native slots could be resolved. Unknown is not an empty slot.&lt;br /&gt;
* &amp;lt;code&amp;gt;fresh&amp;lt;/code&amp;gt;: a known observation no older than 3 seconds while the character is alive.&lt;br /&gt;
* &amp;lt;code&amp;gt;melee&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ranged&amp;lt;/code&amp;gt;: catalog keys; &amp;lt;code&amp;gt;&amp;quot;&amp;quot;&amp;lt;/code&amp;gt; means an observed empty slot.&lt;br /&gt;
* &amp;lt;code&amp;gt;pending&amp;lt;/code&amp;gt;: array of &amp;lt;code&amp;gt;{requestId, itemKey}&amp;lt;/code&amp;gt;. Clear requests use &amp;lt;code&amp;gt;&amp;quot;none&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The owning resource receives &amp;lt;code&amp;gt;onPlayerWeaponChangeResult(playerId, itemKey, ok, reason, requestId)&amp;lt;/code&amp;gt;. Completion checks actual native readback, ownership, request identity, current life revision and deadline. New requests supersede conflicting requests; opposite slots are independent. Result events are not ordinary remotely callable Lua events.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler(&amp;quot;onPlayerWeaponChangeResult&amp;quot;, resourceRoot,&lt;br /&gt;
    function(playerId, itemKey, ok, reason, requestId)&lt;br /&gt;
        local state = getPlayerWeaponState(playerId)&lt;br /&gt;
        if ok and state and state.fresh then&lt;br /&gt;
            -- Persist state.melee and state.ranged in your own database schema.&lt;br /&gt;
        end&lt;br /&gt;
    end)&lt;br /&gt;
setPlayerWeapon(playerId, &amp;quot;bow_small_01&amp;quot;) -- must already be owned&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failure and lifecycle ==&lt;br /&gt;
Typical reasons include &amp;lt;code&amp;gt;confirmed&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;superseded&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;native-equip-not-allowed&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;readback-timeout&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;client-confirmation-timeout&amp;lt;/code&amp;gt; and character/life changes. Native work is polled at 20 Hz while pending, with idle observations at 1 Hz. There is no blind replay after a native call. Client timeout is 6 seconds from native queueing; server timeout is 8 seconds from dispatch. Timeout does not prove an in-flight action had no effect: inspect current state before retrying.&lt;br /&gt;
&lt;br /&gt;
Stopping a resource discards its pending results, preventing old completions from entering a restarted script. An already issued native action may finish; stop is not rollback. Clearing settles one slot at a time without the unsafe bulk UnequipWeapons call. Its native toggle behavior must still pass retail gameplay tests; failure must report failure/timeout, not simulated success.&lt;br /&gt;
&lt;br /&gt;
== Development test ==&lt;br /&gt;
gothic_rp includes &amp;lt;code&amp;gt;/weapontest status&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;prepare&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;set &amp;amp;lt;key&amp;amp;gt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;restore&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;stop&amp;lt;/code&amp;gt;. Require a spawned/authenticated test character, enabled test tools and &amp;lt;code&amp;gt;admin.players&amp;lt;/code&amp;gt; permission. Prepare grants missing test weapons but no stats or ammunition. Start tests a sword, bows, crossbow, repeated equips, clear and two-slot combination. Restore reinstates the original slots recorded by start; granted items remain in inventory.&lt;br /&gt;
&lt;br /&gt;
Test local rendering, a second client, late join, firing with correct ammo, native requirements, clear/restore, death and resource restart. Automated tests validate policies and Lua contracts, not the full retail gameplay path.&lt;br /&gt;
[[Category:Lua API]]&lt;/div&gt;</summary>
		<author><name>QCherry</name></author>
	</entry>
</feed>