# usercmd

{% hint style="info" %}
One packet can contain multiple usercmd's. Each representing input for a frame.\
\
**Example Calculation:**

Suppose you have set `cl_maxpackets` to 30.\
This means per second, 30 packets are being sent to the server.\
In other words every 33ms.&#x20;

If your fps were also set to 30fps that means 1 usercmd is being sent per packet.\
Likewise 60fps would send 2 usercmd's per packet and so on.
{% endhint %}

### Available Properties

* <mark style="color:purple;">`serverTime`</mark>
* <mark style="color:purple;">`buttons`</mark>
* <mark style="color:purple;">`weapon`</mark>
* <mark style="color:purple;">`offHandIndex`</mark>
* <mark style="color:purple;">`forwardMove`</mark>
* <mark style="color:purple;">`sideMove`</mark>

### Methods

* [shoot](#shoot)
* [jump](#jump)
* [isInMenu](#isinmenu)
* [isLeaning](#isleaning)
* [isForward](#isforward)
* [isOnlyForward](#isonlyforward)
* [goForward](#goforward)
* [isBackward](#isbackward)
* [isA](#isa)
* [isD](#isd)
* [isAorD](#isaord)
* [isWA](#iswa)
* [isWD](#iswd)
* [isWAorWD](#iswa-1)
* [hasMovement](#hasmovement)
* [setForwardMove](#setforwardmove-forwardmove)
* [setSideMove](#setsidemove-sidemove)
* [walk](#walk)
* [sprint](#sprint)
* [setButtons](#setbuttons-button)
* removeButton
* [getViewAngles](#getviewangles)

### <mark style="color:green;">`shoot()`</mark>

Set shoot input for this command (frame).

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.shoot() -- Same as left clicking for this jump
```

### <mark style="color:green;">`jump()`</mark>

Set shoot input for this command (frame).

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.shoot() -- Same as left clicking for this frame
```

### <mark style="color:green;">`isInMenu()`</mark>

Returns true if you're in a menu or chatting.

**Example:**

```lua
local cmd = engine.getUserCmd()
print("in menu: " .. cmd.isInMenu())
```

### <mark style="color:green;">`isLeaning()`</mark>

Returns true if you're leaning.

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is leaning: " .. cmd.isLeaning())
```

### <mark style="color:green;">**`isForward()`**</mark>

Returns true if current cmd moves forward.  (Pressing W or equivalent keybind)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is forward: " .. cmd.isForward())
```

### <mark style="color:green;">`isOnlyForward()`</mark>

Returns true if current cmd **ONLY** moves forward. Meaning no strafing.

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is only forward: " .. cmd.isOnlyForward())
```

### <mark style="color:green;">`goForward()`</mark>

Set the forwardMove so that this frame will make you move forward for 1 frame.

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.goForward() -- Walk forwards 1 frame
```

### <mark style="color:green;">`isBackward()`</mark>

Returns true if current cmd moves backwards.  (Pressing S or equivalent keybind)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is backward: " .. cmd.isOnlyForward())
```

### <mark style="color:green;">`isA()`</mark>

Returns true if current cmd strafes left.  (Pressing A or equivalent keybind)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is A: " .. cmd.isA())
```

### <mark style="color:green;">`isD()`</mark>

Returns true if current cmd strafes right.  (Pressing D or equivalent keybind)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is D: " .. cmd.isD())
```

### <mark style="color:green;">`isAorD()`</mark>

Returns true if current cmd strafes left or right.  (Pressing A or D or equivalent keybind)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is A or D: " .. cmd.isAorD())
```

### <mark style="color:green;">`isWA()`</mark>

Returns true if current cmd uses W+A.  (Pressing W + A or equivalent keybinds)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is WA: " .. cmd.isWA())
```

### <mark style="color:green;">`isWD()`</mark>

Returns true if current cmd uses W+D.  (Pressing W + D or equivalent keybinds)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is WD: " .. cmd.isWD())
```

### <mark style="color:green;">`isWAorWD()`</mark>

Returns true if current cmd uses W+A or W+D.  (Pressing W + A or W + D or equivalent keybinds)

**Example:**

```lua
local cmd = engine.getUserCmd()
print("is WA or WD: " .. cmd.isWAorWD())
```

### <mark style="color:green;">`hasMovement()`</mark>

Returns true if current cmd has any movement set on it.

**Example:**

```lua
local cmd = engine.getUserCmd()
print("moving this frame?: " .. cmd.hasMovement())
```

### <mark style="color:green;">`setForwardMove(forwardMove)`</mark>

* <mark style="color:purple;">`forwardMove`</mark> - <mark style="color:green;">127</mark> for moving forward, <mark style="color:green;">-127</mark> for moving backwards, <mark style="color:green;">0</mark> for no forward move.

Set the forward move for this command.

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.setForwardMove(127) -- Same as pressing W for 1 frame
cmd.setForwardMove(-127) -- Same as pressing S for 1 frame
```

### <mark style="color:green;">`setSideMove(sideMove)`</mark>

* <mark style="color:purple;">`sideMove`</mark> - <mark style="color:green;">127</mark> for strafing right, <mark style="color:green;">-127</mark> for strafing left, <mark style="color:green;">0</mark> for no side move.

Set the side move for this command.

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.setSideMove(127) -- Same as pressing D for 1 frame
cmd.setSideMove(-127) -- Same as pressing A for 1 frame
```

### <mark style="color:green;">`walk()`</mark>

Cancels a sprint.

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.walk() -- If you were sprinting, you're now walking
```

### <mark style="color:green;">`sprint()`</mark>

Sets the sprint button on the command.

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd.sprint() -- Sprinting now
```

### <mark style="color:green;">`setButton(button)`</mark>

* <mark style="color:purple;">`button`</mark> - The [button](/enums/cmdbutton.md) you wish to set

Sets a specific [button](/enums/cmdbutton.md) on the command.

{% hint style="info" %}
Buttons on usercmd's can be confusing at first.&#x20;

Your mental model of a usercmd should be the input that you can give as a player for a single frame. The buttons property is a single `int` that describes which actions you wish to perform.\
\
**Available Buttons are shown** [**here**](/enums/cmdbutton.md)**.**
{% endhint %}

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd:setButton(CmdButton.Jump) -- Equivalent to cmd:jump()
cmd:setButton(CmdButton.Knife) -- Same as knifing
```

### <mark style="color:green;">`removeButton(button)`</mark>

<mark style="color:purple;">`button`</mark> - The [button](/enums/cmdbutton.md) you wish to <mark style="color:green;">`remove`</mark>

Removes a specific button on the command. Only works before the command is used locally.\
Attach a event listener for <mark style="color:purple;">`onAfterCL_CreateNewCommands`</mark> and not <mark style="color:purple;">`render`</mark>\
if you wish to remove buttons.

**Example:**

```lua
local cmd = engine.getUserCmd()
cmd:removeButton(CmdButton.Jump) -- Can no longer jump
```

### <mark style="color:green;">`getViewAngles()`</mark>

Returns the viewangles that this command has. These are the viewangles which are sent to the server.

**Example:**

```lua
local cmd = engine.getUserCmd()
local vec = cmd:getViewAngles() -- Your viewangles this frames
```

### <mark style="color:green;">`getViewAngles()`</mark>

Returns the viewangles that this command has. These are the viewangles which are sent to the server.

**Example:**

```lua
local cmd = engine.getUserCmd()
local vec = cmd:getViewAngles() -- Your viewangles this frames
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anvil.team/types/usercmd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
