Anvil Scripting Reference
  • Getting started
    • Introduction
  • ๐Ÿš€Examples
    • Create a speed overlay
    • Creating a Clock with ImGui
    • Calculating Distances Tool
  • โš™๏ธ User Settings
    • Make use of our settings API
  • ๐Ÿ“ฆNamespaces
    • engine
    • player
    • key
    • mouse
    • memory
    • draw
    • ImGui
  • ๐ŸงชTypes
    • Vec2
    • Vec3
    • Vec4
    • playerState
    • refDef
    • clientEntity
    • cg
    • usercmd
    • trace
    • dvar
  • ๐Ÿ“„Enums
    • CmdButton
    • ImGuiWindowFlags
    • ImGuiStyleVar
    • ImGuiCol
Powered by GitBook
On this page
  • Available Properties
  • Methods
  • shoot()
  • jump()
  • isInMenu()
  • isLeaning()
  • isForward()
  • isOnlyForward()
  • goForward()
  • isBackward()
  • isA()
  • isD()
  • isAorD()
  • isWA()
  • isWD()
  • isWAorWD()
  • hasMovement()
  • setForwardMove(forwardMove)
  • setSideMove(sideMove)
  • walk()
  • sprint()
  • setButton(button)
  • removeButton(button)
  • getViewAngles()
  • getViewAngles()
  1. Types

usercmd

The input the player gives to the game for a frame.

PreviouscgNexttrace

Last updated 1 month ago

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.

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.

Available Properties

  • serverTime

  • buttons

  • weapon

  • offHandIndex

  • forwardMove

  • sideMove

Methods

  • removeButton

shoot()

Set shoot input for this command (frame).

Example:

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

jump()

Set shoot input for this command (frame).

Example:

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

isInMenu()

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

Example:

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

isLeaning()

Returns true if you're leaning.

Example:

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

isForward()

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

Example:

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

isOnlyForward()

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

Example:

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

goForward()

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

Example:

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

isBackward()

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

Example:

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

isA()

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

Example:

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

isD()

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

Example:

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

isAorD()

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

Example:

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

isWA()

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

Example:

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

isWD()

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

Example:

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

isWAorWD()

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

Example:

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

hasMovement()

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

Example:

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

setForwardMove(forwardMove)

  • forwardMove - 127 for moving forward, -127 for moving backwards, 0 for no forward move.

Set the forward move for this command.

Example:

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

setSideMove(sideMove)

  • sideMove - 127 for strafing right, -127 for strafing left, 0 for no side move.

Set the side move for this command.

Example:

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

walk()

Cancels a sprint.

Example:

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

sprint()

Sets the sprint button on the command.

Example:

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

setButton(button)

Buttons on usercmd's can be confusing at first.

Example:

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

removeButton(button)

Removes a specific button on the command. Only works before the command is used locally. Attach a event listener for onAfterCL_CreateNewCommands and not render if you wish to remove buttons.

Example:

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

getViewAngles()

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

Example:

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

getViewAngles()

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

Example:

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

button - The you wish to set

Sets a specific on the command.

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 .

button - The you wish to remove

๐Ÿงช
shoot
jump
isInMenu
isLeaning
isForward
isOnlyForward
goForward
isBackward
isA
isD
isAorD
isWA
isWD
isWAorWD
hasMovement
setForwardMove
setSideMove
walk
sprint
setButtons
getViewAngles
button
button
here
button