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
  1. Examples

Create a speed overlay

PreviousIntroductionNextCreating a Clock with ImGui

Last updated 3 years ago

In this small example we will create a text overlay that will display your current 2D speed. First lets make sure the code we will write will be called every frame and thus update the display correctly.

function speedOverlay()
    --Nothing here yet
end

engine.addEventListener("render", speedOverlay)

Now for us to render our speed we have to first obtain it. The namespace provides a method for this that we can use, called . Let's plug that into the code we have.

function speedOverlay()
    local speed = player.get2DSpeed()
end

engine.addEventListener("render", speedOverlay)

We want to render this data to the screen, for example to the lower middle of it. For anything drawing related the namespace provides methods for most primitive shapes and . The draw.text method expects arguments that we have to pass, namely:

  • content - This will be the speed we obtained

  • pos - For example the lower middle of your screen

  • color - The color of the speed, as a Vec4, e.g. Vec4:new(255, 0, 0, 255) for red

  • fontSize - The size of the text in pixels

  • fontName - The name of the

Let's also floor our speed and convert it to a string and save it in another variable:

function speedOverlay()
    local speed = player.get2DSpeed()
    local speedString = tostring(math.floor(speed))
    draw.text(speedString, Vec2:new(960, 540), Vec4:new(255, 0, 0, 255), 36, "Verdana")
end

engine.addEventListener("render", speedOverlay)

The result shoud look similiar to this:

๐Ÿš€
player
get2DSpeed
draw
text
font