Garry's Mod Wiki

CUserCmd

A class used to store the player inputs, such as mouse movement, view angles, IN enum buttons pressed and analog movement, the data from this class is then transfered to a CMoveData during actual movement simulation.

Can be modified during GM:CreateMove, GM:StartCommand and used in read only with GM:SetupMove and Player:GetCurrentCommand.

Methods

CUserCmd:AddKey( number key )
Adds a single key to the active buttons bitflag. See also CUserCmd:SetButtons.
CUserCmd:ClearButtons()
Removes all keys from the command. If you are looking to affect player movement, you may need to use CUserCmd:ClearMovement instead of clearing the buttons.
CUserCmd:ClearMovement()
Clears the movement from the command. See also CUserCmd:SetForwardMove, CUserCmd:SetSideMove and CUserCmd:SetUpMove.
Returns an increasing number representing the index of the user cmd. The value returned is occasionally 0 inside GM:CreateMove and GM:StartCommand. It is advised to check for a non-zero value if you wish to get the correct number.
number CUserCmd:GetButtons()
Returns a bitflag indicating which buttons are pressed.
The speed the client wishes to move forward with, negative if the clients wants to move backwards.
number CUserCmd:GetImpulse()
Gets the current impulse from the client, usually 0. See impulses list and some GMod specific impulses.
Returns the scroll delta as whole number.
number CUserCmd:GetMouseX()
Returns the delta of the angular horizontal mouse movement of the player.
number CUserCmd:GetMouseY()
Returns the delta of the angular vertical mouse movement of the player.
number CUserCmd:GetSideMove()
The speed the client wishes to move sideways with, positive if it wants to move right, negative if it wants to move left.
number CUserCmd:GetUpMove()
The speed the client wishes to move up with, negative if the clients wants to move down.
Angle CUserCmd:GetViewAngles()
Gets the direction the player is looking in.
boolean CUserCmd:IsForced()
When players are not sending usercommands to the server (often due to lag), their last usercommand will be executed multiple times as a backup. This function returns true if that is happening. This will never return true clientside.
boolean CUserCmd:KeyDown( number key )
Returns true if the specified button(s) is pressed.
CUserCmd:RemoveKey( number button )
Removes a key bit from the current key bitflag. For movement you will want to use CUserCmd:SetForwardMove, CUserCmd:SetUpMove and CUserCmd:SetSideMove.
CUserCmd:SelectWeapon( Weapon weapon )
Forces the associated player to select a weapon. This is used internally in the default HL2 weapon selection HUD. This may not work immediately if the current command is in prediction. Use input. SelectWeapon to switch the weapon from the client when the next available command can do so. This is the ideal function to use to create a custom weapon selection HUD, as it allows prediction to run properly for WEAPON:Deploy and GM:PlayerSwitchWeapon
CUserCmd:SetButtons( number buttons )
Sets the buttons as a bitflag. See also CUserCmd:GetButtons. If you are looking to affect player movement, you may need to use CUserCmd:SetForwardMove instead of setting the keys.
CUserCmd:SetForwardMove( number speed )
Sets speed the client wishes to move forward with, negative if the clients wants to move backwards. See also CUserCmd:ClearMovement, CUserCmd:SetSideMove and CUserCmd:SetUpMove.
CUserCmd:SetImpulse( number impulse )
Sets the impulse command to be sent to the server. Here are a few examples of impulse numbers: 100 toggles their flashlight 101 gives the player all Half-Life 2 weapons with sv_cheats set to 1 200 toggles holstering / restoring the current weapon When holstered, the EF_NODRAW flag is set on the active weapon. 154 toggles noclip See full list
CUserCmd:SetMouseWheel( number speed )
Sets the scroll delta.
CUserCmd:SetMouseX( number speed )
Sets the delta of the angular horizontal mouse movement of the player. See also CUserCmd:SetMouseY.
CUserCmd:SetMouseY( number speed )
Sets the delta of the angular vertical mouse movement of the player. See also CUserCmd:SetMouseX.
CUserCmd:SetSideMove( number speed )
Sets speed the client wishes to move sidewards with, positive to move right, negative to move left. See also CUserCmd:SetForwardMove and CUserCmd:SetUpMove.
CUserCmd:SetUpMove( number speed )
Sets speed the client wishes to move upwards with, negative to move down. See also CUserCmd:SetSideMove and CUserCmd:SetForwardMove. This function does not move the client up/down ladders. To force ladder movement, consider CUserCMD:SetButtons and use IN_FORWARD from IN enum.
CUserCmd:SetViewAngles( Angle viewAngle )
Sets the direction the client wants to move in. For human players, the pitch (vertical) angle should be clamped to +/- 89° to prevent the player's view from glitching. For fake clients (those created with player. CreateNextBot), this functionally dictates the 'move angles' of the bot. This typically functions separately from the colloquial view angles. This can be utilized by CUserCmd:SetForwardMove and its related functions.
number CUserCmd:TickCount()
Returns tick count since joining the server. This will always return 0 for bots. Returns 0 clientside during prediction calls. If you are trying to use CUserCmd:Set*() on the client in a movement or command hook, keep doing so till TickCount returns a non-zero number to maintain prediction.