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
  • engine.addEventListener(name, callable)
  • engine.removeEventListener(name)
  • engine.removeAllEventListeners()
  • engine.getServerName()
  • engine.getPlayerState()
  • engine.getRefDef()
  • engine.getCG()
  • engine.getDvar(dvarName)
  • engine.getUserCmd()
  • engine.getPreviousUserCmd()
  • engine.execCommand(command)
  • engine.getPlayerList()
  • engine.getLocalClientEntity()
  • engine.getClosestPlayer()
  • engine.isVisible(target)
  • engine.trace(start, end)
  • engine.getForwardVector(viewangles)
  • engine.angle2short(angle)
  • engine.short2angle(short)
  • engine.getWindowSize()
  • engine.notify(message)
  • engine.disconnect()
  • engine.setStat(id, value)
  • engine.isVisible(target)
  • engine.getScriptId()
  1. Namespaces

engine

This namespace provides methods that allow you to interact with the iw3 engine through Anvil.

PreviousMake use of our settings APINextplayer

Last updated 1 month ago

Methods

engine.addEventListener(name, callable)

  • event - The type of event you want to listen for

  • callable - A defined function or a lambda

This method registers a eventlistener for the specified event, that is a function that will be executed every time the event occurs.

Example:

function hi()
    print("whats up")
end

engine.addEventListener("render", hi);

This will print whats up every time a new frame is rendered.

Available Events

  • render - Emitted when a new frame is being rendered

  • onBeforeEndScene - Emitted right before a new frame is being rendered

  • onAfterEndScene - Emitted after a new frame has been rendered

  • onBeforeCL_WritePacket - Emitted right before the game sends a packet to the server

  • onAfterCL_CreateNewCommands - Emitted after a new user command has been created

  • onLoad - Emitted when you load your position

  • onSave - Emitted when you save your position

  • onBounce - Emitted when you bounce

engine.removeEventListener(name)

  • event - The name of the event you dont want to listen/react to anymore

Removes a previously attachted event listener by the name of the event.

Example:

engine.removeEventListener("render")

engine.removeAllEventListeners()

Removes all attached event listeners for the current script.

Example:

engine.removeAllEventListeners()

engine.getServerName()

Returns the name of the server you're currently connected to.

Example:

--Suppose you play on 3xP
local name = engine.getServerName()
print(name) -- 3xP' Codjumper

engine.getPlayerState()

Example:

local playerState = engine.getPlayerState()
print(playerState.Origin.x)

engine.getRefDef()

Example:

local refdef = engine.getRefDef()
print(refdef.width) -- CoD4 window width

engine.getCG()

Example:

local cg = engine.getCG()
print(cg.ClientNum) -- Your client number

engine.getDvar(dvarName)

Example:

local sens = engine.getDvar("sensitivity")
sens:setFloat(1.5) -- sets sensitivity to 1.5

engine.getUserCmd()

Example:

local usercmd = engine.getUserCmd();
usercmd:jump(); -- Makes you jump
usercmd:shoot(); -- Shoots your weapon once

engine.getPreviousUserCmd()

Example:

local usercmd = engine.getPreviousUserCmd();
usercmd:jump(); -- Makes you jump
usercmd:shoot(); -- Shoots your weapon once

engine.execCommand(command)

  • command - A console command to execute

Executes the given command

Example:

engine.execCommand("say hi from lua");

engine.getPlayerList()

Example:

local players = engine.getPlayerList()

-- Print the position of all players right now
for i, entity in ipairs(players) do
    print(entity.origin:toString())
end

engine.getLocalClientEntity()

Example:

local me = engine.getLocalClientEntity()

-- Prints your team
print("I am in team " .. tostring(me.team))

engine.getClosestPlayer()

Example:

local closestPlayer = engine.getClosestPlayer()

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

engine.isVisible(target)

Returns true if target is visible from your currnent position, false otherwise.

Example:

-- True if the map origin is visible from your current position
engine.isVisible(Vec3:new(0, 0, 0))

-- True if you can see the closest player
engine.isVisible(engine.getClosestPlayer())

engine.trace(start, end)

Example:

local pointA = Vec3:new(0, 0, 0)
local pointB = Vec3:new(500, 500, 1000)

local trace = engine.trace(pointA, pointB)
print("Hit something at: " .. trace.getHitLocation(pointA, pointB))

engine.getForwardVector(viewangles)

Example:

local forward = engine.getForwardVector(player.getView())
print("Forward: " .. forward:toString())

engine.angle2short(angle)

Converts the decimal angle to a 2 byte integer representation.

A unsigned 2 byte integer has a range from 0 to 65535. CoD4 is based on the Quake engine. Back in the 90's they optimized the bandwidth needed to communicate with the server. Instead of sending your viewangles as 3 floats (12 byte), they're sent as 2 byte shorts each, reducing the bandwidth by 50%. If you're working with usercmd's then please be aware that the viewangles there are in the short representation. Things to consider: Since a full circle of 360 degrees are mapped onto a finite interval of 0 - 65535, the precision suffers. The minimum change of a viewangle is:

360.0 / 65536 = 0.0054931640625

Example:

-- Prints 16384
print("90 degree as short: " .. tostring(engine.angle2short(90.0)))

engine.short2angle(short)

Converts a 2 byte integer representation of an angle back to a float.

Example:

-- Prints 90.0
print("16384 as angle: " .. tostring(engine.short2angle(16384)))

engine.getWindowSize()

Example:

-- Prints your window dimensions
print("Window dimensions: " .. engine.getWindowSize():toString())

engine.notify(message)

Displays a notification on the right hand side of the screen with the given message.

Example:

-- Display notification
engine.notify("Test toast")

engine.disconnect()

Disconnect from current server.

Example:

-- Disconnects
engine.disconnect()

engine.setStat(id, value)

Sets a stat id to a given value (Equivalent of GSC player setStat).

id- The id of the stat

value- The value you wish to set

Example:

-- Set ruby currency on Vistic CodJumper 
engine.setStat(2392, 99999)

engine.isVisible(target)

Returns true if target is visible from your currnent position, false otherwise.

Example:

-- True if the map origin is visible from your current position
engine.isVisible(Vec3:new(0, 0, 0))

-- True if you can see the closest player
engine.isVisible(engine.getClosestPlayer())

engine.getScriptId()

Returns the id of the current script. Use this to uniquely identify your script. Useful for ImGui Window ID's etc.

Example:

print("script id: " .. engine.getScriptId())

Returns the predicted .

Returns the object.

Returns the object.

Returns the you requested. You can then change the values of the dvar with .

Returns the latest .

Returns the previous . Use previous user cmd's for silent stuff.

Returns a list of players in the server as a list of 's

Returns the for yourself.

Returns the closest player as a

target - The position as a to check if it is visible

Performs a ray trace from start to end and returns a object.

Obtain the forward vector as a from the given viewangles as a

Returns the CoD4 window size as a

target - The position as a to check if it is visible

📦
addEventListener
removeEventListener
removeAllEventListeners
getServerName
getPlayerState
getRefDef
getCG
getDvar
getUserCmd
getPreviousUserCmd
execCommand
getPlayerList
getLocalClientEntity
getClosestPlayer
isVisible
getBoneOrigin
trace
getForwardVector
angle2short
short2angle
getWindowSize
notify
disconnect
setStat
getScriptId
playerState
refDef
cg
dvar
methods
user command
user command
clientEntity
clientEntity
clientEntity
Vec3
trace
Vec3
Vec3
Vec2
Vec3