Garry's Mod Wiki

Revision Difference

GM:PlayerSwitchWeapon#511229

<function name="PlayerSwitchWeapon" parent="GM" type="hook">⤶ <ishook>yes</ishook>⤶ <description>Called when a player switches their weapon.</description>⤶ <realm>Shared</realm>⤶ <predicted>Yes</predicted>⤶ <args>⤶ <arg name="player" type="Player">The player switching weapons.</arg>⤶ <arg name="oldWeapon" type="Weapon">The previous weapon. Will be NULL if the previous weapon was removed or the player is switching from nothing.</arg>⤶ <arg name="newWeapon" type="Weapon">The weapon the player switched to. Will be NULL if the player is switching to nothing.&#xA;&#xA;&lt;bug issue=&quot;2922&quot;&gt;This can be NULL on the client if the weapon hasn&#x27;t been created over the network yet.&lt;/bug&gt;</arg>⤶ </args>⤶ <rets>⤶ <ret name="" type="boolean">Return true to prevent weapon switch</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>The players weapon information will be printed when the player switched weapons.</description>⤶ <code>⤶ function GM:PlayerSwitchWeapon(ply, oldWeapon, newWeapon)⤶ //GetClass() will return the weapons class as a string.⤶ MsgN("You switched weapons! Your old weapon is " .. oldWeapon:GetClass() ..".")⤶ MsgN("Your new weapon is " .. newWeapon:GetClass() .. ".");⤶ end⤶ </code>⤶ <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <output>⤶ You switched weapons! Your old weapon is gmod_camera.⤶ Your new weapon is weapon_crossbow.⤶ </output>⤶ ⤶ </example>