GM:PlayerSwitchWeapon

From Garry's Mod
Jump to: navigation, search
 GM:PlayerSwitchWeapon( )

Contents

Description

Called when a player switches their weapon.

NOTE This hook is predicted. This means that in singleplayer, it will not be called in the Client realm.

Arguments

Player player

The player switching weapons.

Arguments

Weapon oldWeapon

The previous weapon.

Arguments

Weapon newWeapon

The weapon the player switched to.

Returns

boolean

Return true to prevent weapon switch

Examples

Example

The players weapon information will be printed when the player switched weapons.

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

Output:

You switched weapons! Your old weapon is gmod_camera.
Your new weapon is weapon_crossbow.
Personal tools
Navigation