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
  • Methods
  • player.getPosition()
  • player.setPosition(position)
  • player.getVelocity()
  • player.setVelocity(velocity)
  • player.getView()
  • player.setView(viewAngles)
  • player.getDeltas()
  • player.getCrosshairWorldPosition()
  • player.get2DSpeed()
  • player.getCurrentWeaponID()
  • player.setCurrentWeaponID(id)
  • player.getFPS()
  • player.setFPS(fps)
  • player.lookAtPosition(position)
  • player.moveTo(position)
  • player.getName()
  • player.getMainhandWeaponID()
  • player.getRPGWeaponID()
  • player.getWeaponDelay()
  • player.isConnectedToServer()
  • player.isOnLocalServer()
  • player.isSpectating()
  • player.isUsingRPG()
  • player.willLeaveGroundThisFrame()
  • player.willTouchGroundThisFrame()
  • player.willTouchGroundNextFrame()
  • player.wasInAirLastFrame()
  • player.didTouchGroundLastFrame()
  • player.willBounceThisFrame()
  • player.willBounceNextFrame()
  1. Namespaces

player

This namespace provides methods that allow you to interact with your player.

PreviousengineNextkey

Last updated 1 month ago

Methods

player.getPosition()

Returns your position as a Vec3

Example:

local position = player.getPosition()
print(position:toString()

player.setPosition(position)

Only works in devmap.

position - The position you want to set

Example:

player.setPosition(player.getPosition():add(Vec3:new(0, 0, 1000))
-- Teleport up 1000 units

player.getVelocity()

Returns your velocity as a Vec3.

Example:

local velocity = player.getVelocity()
print(velocity:toString())

player.setVelocity(velocity)

Only works in devmap.

velocity - The velocity you want to set

Example:

player.setVelocity(Vec3:new(3000, 3000, 3000))

player.getView()

Returns your viewangles as a Vec3 in the following format

  1. pitch

  2. yaw

  3. roll

Example:

local viewangles = player.getView()
print(tostring(viewangles.y) -- Prints your yaw angle

player.setView(viewAngles)

  • viewAngles - A Vec3 with the angles you wish to set

Set your viewangles to the ones defined by the given Vec3

Adding onto angles indicates leftward motion, subtracting rightward motion

Example:

-- Spin left
function turn()
    local view = player.View()
    view.y = view.y + 1
    player.setView(view)
end

engine.addEventListener("render", turn);

player.getDeltas()

Returns your delta angles as a Vec3.

Delta angles can be hard to wrap your head around at first. Call of Duty 4 does not update your viewangle in memory if a teleport occurs. Teleports such as loading your position in CodJumper will create a mismatch of your true viewangle and the one that resides in memory.

The difference is called the delta angle.

Example:

If you save your position with a yaw angle of 0 and turn 180 degree around,

then your yaw angle in memory will be 180. If you then load your position

it will still be 180, however the yaw delta angle will be -180.

Together they make up your true angle of yaw 0.

Delta angles go from -180 to +180

Example:

local deltas = player.getDeltas()
print(deltas:toString()) -- Your delta angles

player.getCrosshairWorldPosition()

Returns the position the player currently aims at.

Example:

local aimPosition = player.getCrosshairWorldPosition()
print("I am aiming at " .. aimPosition:toString())

player.get2DSpeed()

Returns your current 2D speed.

Example:

local speed = player.get2DSpeed()
print("I am " .. speed .. " units fast")

player.getCurrentWeaponID()

Returns the weapon ID of your currently equipped weapon.

Example:

local weaponID = player.getCurrentWeaponID()
print(weaponID)

player.setCurrentWeaponID(id)

  • id The id of the weapon you want to switch to

Switches weapon to the given weapon ID.

Example:

local position = player.getPosition()
print(position:toString())

player.getFPS()

Returns your current FPS.

Example:

local fps = player.getFPS()
print("Current fps: " .. fps)

player.setFPS(fps)

  • fps - The new fps to set

Sets your fps to the given value.

Example:

player.setFPS(250)

player.lookAtPosition(position)

  • position - A position as a Vec3 that you want to look at

Sets your viewangles so that you directly look at the given position

Example:

local closestPlayer = engine.getClosestPlayer()

-- Makes you look at the closest player
player.lookAtPosition(closestPlayer.origin)

player.moveTo(position)

  • position - A position as a Vec3 that you want to move to.

Will move to the given position.

Example:

local closestPlayer = engine.getClosestPlayer()

-- Makes you move to closest player
player.moveTo(closestPlayer.origin)

player.getName()

Returns your name.

Example:

local name = player.getName()
print("My name is " .. name)

player.getMainhandWeaponID()

Returns the id of your main weapon.

Example:

local mainWeapon = player.getMainhandWeaponID()
player.setCurrentWeaponID(mainWeapon) -- Switch to main weapon

player.getRPGWeaponID()

Returns the weapon id of your rpg.

Example:

local rpg = player.getRPGWeaponID()
player.setCurrentWeaponID(rpg) -- Switch to rpg

player.getWeaponDelay()

Returns the delay of your current weapon. The delay indicates how long the weapon is still unusable or in an animation. For example if you shoot the RPG without ADS then it takes time for the RPG to zoom in and eventually fire the rocket. The delay is a number in miliseconds how much of that animation is left.

Example:

local delay = player.getWeaponDelay()

-- Turn around right before rpg shoots
if (delay < 20 and player.isUsingRPG()) then
    local view = player.getView()
    view.y = view.y + 180;
    player.setView(view)
end

player.isConnectedToServer()

Returns true if you're connected to a remote server.

Example:

print("Connected: " .. tostring(player.isConnectedToServer()))

player.isOnLocalServer()

Returns true if you're on a local server.

Example:

print("on local server?: " .. tostring(player.isOnLocalServer()))

player.isSpectating()

Returns true if you're spectating.

Example:

print("Spectating?: " .. tostring(player.isSpectating()))

player.isUsingRPG()

Returns true if you're currently using a RPG.

Example:

-- Disallow rpg usage 
if (player.isUsingRPG()) then
    player.setCurrentWeaponID(player.getMainhandWeaponID())
end

player.willLeaveGroundThisFrame()

Returns true if you will be considered in air this frame. This can either be the result of jumping or walking of a platform etc.

Example:

-- Jump at edges of platforms
if (player.willLeaveGroundThisFrame()) then
    engine.getUserCmd().jump()
end

player.willTouchGroundThisFrame()

Returns true if you will land on ground this frame.

Example:

if (player.willTouchGroundThisFrame()) then
    print("Landing on ground now")
end

player.willTouchGroundNextFrame()

Returns true if you will land on ground next frame.

Example:

if (player.willTouchGroundNextFrame()) then
    print("Landing on ground next frame")
end

player.wasInAirLastFrame()

Returns true if you were in air last frame.

Example:

if (player.wasInAirLastFrame()) then
    print("Was in air last frame (and still could be)")
end

player.didTouchGroundLastFrame()

Returns true if you landed on ground last frame.hi

Notice This is not returning if you were on ground last frame. It is returning if you landed on ground last frame and thus will only be true if you were in air 2 frames ago and touched ground last frame.

Example:

-- Bhop 
if (player.didTouchGroundLastFrame()) then
    engine.getUserCmd().jump()
end

player.willBounceThisFrame()

Returns if you will bounce this frame.

Example:

if (player.willBounceThisFrame())
    print("I will bounce now")
end

player.willBounceNextFrame()

Returns if you will bounce next frame.

Example:

if (player.willBounceNextFrame())
    print("I will bounce next frame")
end

Sets your position to the given

Sets your velocity to the given

๐Ÿ“ฆ
getPosition
setPosition
getVelocity
setVelocity
getView
setView
getDeltas
getCrosshairWorldPosition
get2DSpeed
getCurrentWeaponID
setCurrentWeaponID
getFPS
setFPS
lookAtPosition
moveTo
getName
getMainhandWeaponID
getRPGWeaponID
getWeaponDelay
isConnectedToServer
isOnLocalServer
isSpectating
isUsingRPG
willLeaveGroundThisFrame
willTouchGroundThisFrame
willTouchGroundNextFrame
wasInAirLastFrame
didTouchGroundLastFrame
willBounceThisFrame
willBounceNextFrame
Vec3
Vec3