Cage

Cage Service Docs

Documentation Hub

API Reference

Complete Lua API reference for Ham Mafia. All functions are accessible via the Ham or ham global tables in both camelCase and lowercase variants.

Execution Context

The HamMafia Executor lets you choose where to run your code. In the bottom-left of the executor tab, you can select between an isolated Lua state or a specific resource. When running in isolated mode, global values are not shared with server resources. For example, setting _G.test = true in isolated mode will not be accessible from any server resource, and vice versa.

Categories

General

getName()
Returns the authenticated username.
Syntax
Ham.getName()
Returns

string — The username of the authenticated user.

Example
local username = Ham.getName()
print("Welcome, " .. username)
getDiscordName()
Returns the linked Discord username.
Syntax
Ham.getDiscordName()
Returns

string — Discord username.

Example
local discord = Ham.getDiscordName()
print("Discord: " .. discord)
getDiscordId()
Returns the linked Discord user ID.
Syntax
Ham.getDiscordId()
Returns

string — Discord user ID.

Example
local id = Ham.getDiscordId()
print("Discord ID: " .. id)
isGuiOpen()
Checks whether the Ham GUI menu is currently open.
Syntax
Ham.isGuiOpen()
Returns

booleantrue if the menu is open.

Example
if not Ham.isGuiOpen() then
    -- Only draw when menu is closed
    Ham.drawText("HUD Active", {10, 10}, {255, 255, 255, 255})
end

Input Handling

isKeyDown(key)
Returns whether a key is currently held down.
Parameters
NameTypeDescription
keyintegerImGui key code
Returns

boolean

Example
if Ham.isKeyDown(87) then
    print("W is being held")
end
isKeyPressed(key)
Returns whether a key was just pressed this frame.
Parameters
NameTypeDescription
keyintegerImGui key code
Returns

boolean

Example
if Ham.isKeyPressed(70) then -- F key
    print("F was pressed this frame")
end
isKeyReleased(key)
Returns whether a key was just released this frame.
Parameters
NameTypeDescription
keyintegerImGui key code
Returns

boolean

Example
if Ham.isKeyReleased(32) then -- Space
    print("Space was released")
end
isMouseDown(button)
Checks if a mouse button is currently held.
Parameters
NameTypeDescription
buttonintegerMouse button index (0=left, 1=right, 2=middle)
Returns

boolean

Example
if Ham.isMouseDown(0) then
    print("Left mouse button is held")
end
isMouseClicked(button)
Checks if a mouse button was clicked this frame.
Parameters
NameTypeDescription
buttonintegerMouse button index
Returns

boolean

Example
if Ham.isMouseClicked(0) then
    print("Left mouse clicked")
end
isMouseDoubleClicked(button)
Checks for a double-click on a mouse button.
Parameters
NameTypeDescription
buttonintegerMouse button index
Returns

boolean

Example
if Ham.isMouseDoubleClicked(0) then
    print("Double click detected")
end
isMouseReleased(button)
Checks if a mouse button was released this frame.
Parameters
NameTypeDescription
buttonintegerMouse button index
Returns

boolean

Example
if Ham.isMouseReleased(1) then
    print("Right mouse released")
end
getMousePos()
Gets the current mouse position on screen.
Returns

float, float — X and Y coordinates.

Example
local x, y = Ham.getMousePos()
print("Mouse at: " .. x .. ", " .. y)
getKeyState(key)
Gets the async key state (Windows API).
Parameters
NameTypeDescription
keyintegerVirtual key code (see Key Codes)
Returns

integer — Key state value.

Example
local state = Ham.getKeyState(0x01) -- Left mouse button
if state ~= 0 then
    print("Left mouse is pressed")
end
toggleMouse(enabled)
Shows or hides the mouse cursor.
Parameters
NameTypeDescription
enabledbooleantrue to show cursor
Example
Ham.toggleMouse(true)  -- Show cursor
toggleInputBlock(enabled)
Blocks or unblocks game input while your script handles input.
Parameters
NameTypeDescription
enabledbooleantrue to block game input
Example
Ham.toggleMouse(true)
Ham.toggleInputBlock(true)
-- Handle your own input here
Ham.toggleInputBlock(false)
Ham.toggleMouse(false)

Clipboard

copyToClipboard(text)
Copies text to the system clipboard.
Parameters
NameTypeDescription
textstringText to copy
Example
local endpoint = Ham.getServerEndpoint()
Ham.copyToClipboard(endpoint)
print("Server IP copied!")
getClipboard()
Returns the current clipboard contents.
Returns

string — Clipboard text content.

Example
local text = Ham.getClipboard()
print("Clipboard: " .. text)

Drawing API

All drawing functions must be called inside a render callback/loop. Colors use RGBA format {r, g, b, a} with values 0–255.

drawLine(startPos, endPos, color, thickness)
Draws a line between two points.
Parameters
NameTypeDescription
startPostableStart position {x, y}
endPostableEnd position {x, y}
colortableColor {r, g, b, a}
thicknessintegerLine thickness in pixels (1–100)
Example
-- Draw a red diagonal line
Ham.drawLine({100, 100}, {200, 200}, {255, 0, 0, 255}, 2)
drawRect(startPos, endPos, color, rounding, flags, thickness)
Draws a rectangle outline.
Parameters
NameTypeDescription
startPostableTop-left position {x, y}
endPostableBottom-right position {x, y}
colortableColor {r, g, b, a}
roundingfloatCorner rounding radius (0–100)
flagsintegerRounding corner flags
thicknessintegerLine thickness (1–100)
Example
-- White rounded rectangle outline
Ham.drawRect({50, 50}, {150, 150}, {255, 255, 255, 255}, 5, 0, 1)
drawRectFilled(rect, color, rounding, roundingCorners)
Draws a filled rectangle.
Parameters
NameTypeDescription
recttableRectangle {x, y, w, h}
colortableColor {r, g, b, a}
roundingfloatCorner rounding (optional, default 0)
roundingCornersintegerCorner flags (optional, default 0)
Example
-- Blue semi-transparent rounded box
Ham.drawRectFilled({100, 100, 200, 100}, {0, 128, 255, 200}, 10, 0)
drawRectGradient(rect, colorStart, colorEnd, vertical)
Draws a filled rectangle with a gradient.
Parameters
NameTypeDescription
recttableRectangle {x, y, w, h}
colorStarttableStarting color {r, g, b, a}
colorEndtableEnding color {r, g, b, a}
verticalbooleantrue for vertical gradient, false for horizontal
Example
-- Red to blue horizontal gradient
Ham.drawRectGradient({0, 0, 200, 50}, {255, 0, 0, 255}, {0, 0, 255, 255}, false)
drawCircle(circle, color, segments, thickness, filled)
Draws a circle (outline or filled).
Parameters
NameTypeDescription
circletableCircle {x, y, radius}
colortableColor {r, g, b, a}
segmentsintegerNumber of segments (higher = smoother)
thicknessfloatLine thickness (outline only)
filledbooleantrue for filled, false for outline
Example
-- Yellow outline circle
Ham.drawCircle({200, 200, 50}, {255, 255, 0, 255}, 32, 2, false)
-- Green filled circle
Ham.drawCircle({300, 200, 30}, {0, 255, 0, 200}, 24, 0, true)
drawText(text, position, color, fontSize, centered, outline, outlineColor)
Draws text on screen.
Parameters
NameTypeDescription
textstringText to draw (supports \n)
positiontablePosition {x, y}
colortableText color {r, g, b, a}
fontSizefloatFont size in pixels (optional, default 12)
centeredbooleanCenter text horizontally (optional)
outlinebooleanDraw text outline (optional)
outlineColortableOutline color (optional)
Example
-- White text with black outline at size 16
Ham.drawText("Hello World!", {100, 100}, {255, 255, 255, 255}, 16, false, true, {0, 0, 0, 255})
drawTexture(texture, pos1, pos2, color, rounding, cornerFlags)
Draws a texture/image on screen.
Parameters
NameTypeDescription
textureuserdataTexture handle from addCustomTexture
pos1tableTop-left position {x, y}
pos2tableBottom-right position {x, y}
colortableTint color (use white for no tint)
roundingfloatCorner rounding (optional)
cornerFlagsintegerCorner flags (optional)
Example
local tex = Ham.addCustomTexture("img.png", "https://example.com/img.png")
if tex then
    Ham.drawTexture(tex, {10, 10}, {110, 110}, {255, 255, 255, 255})
end
pushClipRect(min, max, intersect)
Pushes a clipping rectangle. All subsequent draw calls are clipped to this rect.
Parameters
NameTypeDescription
mintableTop-left {x, y}
maxtableBottom-right {x, y}
intersectbooleanIntersect with existing clip rect
popClipRect()
Pops the last pushed clipping rectangle.
Example
Ham.pushClipRect({50, 50}, {250, 250}, true)
Ham.drawText("Clipped!", {60, 60}, {255, 255, 255, 255})
Ham.popClipRect()
getTextWidth(text)
Returns the width and height of text using the current font.
Parameters
NameTypeDescription
textstringText to measure
Returns

float, float — Width and height in pixels.

Example
local width, height = Ham.getTextWidth("Hello World")
print("Text size: " .. width .. "x" .. height)
getResolution()
Returns the current screen resolution.
Returns

integer, integer — Screen width and height in pixels.

Example
local width, height = Ham.getResolution()
print("Resolution: " .. width .. "x" .. height)
worldToScreen(x, y, z)
Converts 3D world coordinates to 2D screen coordinates.
Parameters
NameTypeDescription
xfloatWorld X coordinate
yfloatWorld Y coordinate
zfloatWorld Z coordinate
Returns

boolean, float, float — Whether the point is on screen, screen X and screen Y.

Example
local onScreen, screenX, screenY = Ham.worldToScreen(100.0, 200.0, 50.0)
if onScreen then
    Ham.drawText("Target", {screenX, screenY}, {255, 0, 0, 255}, 14, true)
end

Font Management

addFont(fontIndex, size)
Adds a built-in font.
Parameters
NameTypeDescription
fontIndexinteger1 = Rubik, 2 = Font Awesome, 3 = Consolas
sizenumberFont size in pixels
Returns

userdata|nil — Font handle or nil on failure.

Example
local font = Ham.addFont(1, 18) -- Rubik 18px
if font then
    Ham.setFont(font)
    Ham.drawText("Custom font!", {10, 10}, {255, 255, 255, 255})
    Ham.resetFont()
end
addWindowsFont(fontName, size)
Adds a font from the Windows font directory.
Parameters
NameTypeDescription
fontNamestringWindows font filename (e.g. "arial.ttf")
sizenumberFont size in pixels
Returns

userdata|nil

Example
local font = Ham.addWindowsFont("arial.ttf", 20)
if font then
    Ham.setFont(font)
    Ham.drawText("Arial!", {10, 10}, {255, 255, 255, 255})
    Ham.resetFont()
end
addCustomFont(fontName, fontUrl, size)
Downloads and adds a custom font from a URL.
Parameters
NameTypeDescription
fontNamestringLocal filename to save as
fontUrlstringURL to download the font from
sizeintegerFont size in pixels
Returns

userdata|nil — Font handle or nil on failure.

Example
local font = Ham.addCustomFont("MyFont.ttf", "https://example.com/font.ttf", 16)
if font then
    Ham.setFont(font)
end
setFont(font)
Sets the active font for subsequent draw calls.
Parameters
NameTypeDescription
fontuserdataFont handle from addFont/addWindowsFont/addCustomFont
Example
local font = Ham.addFont(3, 14) -- Consolas 14px
Ham.setFont(font)
Ham.drawText("Monospace!", {10, 10}, {255, 255, 255, 255})
resetFont()
Resets to the default font.
Example
Ham.resetFont() -- Back to default font

Texture Management

addCustomTexture(textureName, textureUrl)
Downloads and loads a texture from a URL.
Parameters
NameTypeDescription
textureNamestringLocal filename to cache as
textureUrlstringURL to download from
Returns

userdata|nil — Texture handle.

Example
local logo = Ham.addCustomTexture("logo.png", "https://example.com/logo.png")
if logo then
    Ham.drawTexture(logo, {10, 10}, {60, 60}, {255, 255, 255, 255})
end
addCustomTextureAsync(textureName, textureUrl)
Starts an asynchronous texture download.
Parameters
NameTypeDescription
textureNamestringLocal filename to cache as
textureUrlstringURL to download the texture from
Returns

integer — Request ID (use with getAsyncTextureResult).

Example
local requestId = Ham.addCustomTextureAsync("bigimage.png", "https://example.com/big.png")
getAsyncTextureResult(requestId)
Checks the status of an async texture load.
Parameters
NameTypeDescription
requestIdintegerRequest ID from addCustomTextureAsync
Returns

table — Result with fields: ready (boolean), success (boolean), texture (userdata), width (integer), height (integer), error (string).

Example
local result = Ham.getAsyncTextureResult(requestId)
if result.ready then
    if result.success then
        myTexture = result.texture
        print("Loaded: " .. result.width .. "x" .. result.height)
    else
        print("Error: " .. result.error)
    end
end
cleanupAsyncTextureRequests()
Cleans up all pending async texture requests.
Example
Ham.cleanupAsyncTextureRequests()

Utility Functions

openUrl(url)
Opens a URL in the default web browser.
Parameters
NameTypeDescription
urlstringURL to open (must start with http:// or https://)
Returns

booleantrue if successful.

Example
Ham.openUrl("https://cageservice.net")
Execute(resourceName, code)
Executes Lua code in a specified resource context.
Parameters
NameTypeDescription
resourceNamestringTarget resource name (use "isolated" for isolated context)
codestringLua code to execute
Returns

booleantrue if execution was successful.

Example
Ham.Execute("isolated", "print('Hello from isolated context')")
disableWeather(enabled)
Disables weather effects.
Parameters
NameTypeDescription
enabledbooleantrue to disable weather sync
Example
Ham.disableWeather(true)
passObjectControl(playerServerId, vehicleId)
Passes network object control to another player.
Parameters
NameTypeDescription
playerServerIdintegerTarget player’s server ID
vehicleIdintegerEntity/vehicle ID to pass control of
Example
Ham.passObjectControl(5, 12345)
lockEventLogger(secretKey)
Locks the event logger with a secret key.
Parameters
NameTypeDescription
secretKeystringSecret key for unlocking later
Returns

booleantrue if successfully locked.

Example
local success = Ham.lockEventLogger("my_secret_key")
unlockEventLogger(secretKey)
Unlocks the event logger.
Parameters
NameTypeDescription
secretKeystringThe secret key used to lock
Returns

booleantrue if successfully unlocked.

Example
Ham.unlockEventLogger("my_secret_key")

HTTP Client

httpGet(url, headers, insecure)
Performs a synchronous HTTP GET request.
Parameters
NameTypeDescription
urlstringURL to request
headerstable|nilOptional headers {["Header"] = "value"}
insecureboolean|nilSkip SSL verification (optional)
Returns

table{status, data, error, success}

Example
local res = Ham.httpGet("https://api.example.com/data", {
    ["Authorization"] = "Bearer token123"
})
if res.success then
    print("Data: " .. res.data)
end
httpPost(url, payload, headers, insecure)
Performs a synchronous HTTP POST request.
Parameters
NameTypeDescription
urlstringURL to request
payloadstringRequest body
headerstable|nilOptional headers
insecureboolean|nilSkip SSL verification (optional)
Returns

table — Same response format as httpGet.

Example
local res = Ham.httpPost("https://api.example.com/log",
    '{"player": "test", "action": "join"}',
    {["Content-Type"] = "application/json"}
)
print("Status: " .. res.status)
httpGetAsync(url, headers, insecure)
Starts an asynchronous HTTP GET request.
Parameters
NameTypeDescription
urlstringURL to request
headerstable|nilOptional headers
insecureboolean|nilSkip SSL verification
Returns

integer — Request ID.

Example
local requestId = Ham.httpGetAsync("https://api.example.com/data")
httpPostAsync(url, payload, headers, insecure)
Starts an asynchronous HTTP POST request.
Parameters
NameTypeDescription
urlstringURL to request
payloadstringRequest body
headerstable|nilOptional headers
insecureboolean|nilSkip SSL verification
Returns

integer — Request ID.

Example
local requestId = Ham.httpPostAsync("https://api.example.com/submit", '{"data": 123}')
getAsyncResult(requestId)
Checks the status of an async HTTP request.
Parameters
NameTypeDescription
requestIdintegerRequest ID from async function
Returns

table — Result with fields: ready (boolean), pending (boolean), success (boolean), data (string), status (integer), error (string).

Example
local result = Ham.getAsyncResult(requestId)
if result.ready then
    if result.success then
        print("Response: " .. result.data)
    else
        print("Error: " .. result.error)
    end
end
cleanupAsyncRequests()
Cleans up completed and stale async HTTP requests.
Example
Ham.cleanupAsyncRequests()

Server & Resource Info

getServerEndpoint()
Returns the current server endpoint address.
Returns

string

Example
local ip = Ham.getServerEndpoint()
print("Server IP: " .. ip)
getServerHostname()
Returns the current server hostname.
Returns

string

Example
local name = Ham.getServerHostname()
print("Server: " .. name)
getResources()
Returns a list of all resources on the server.
Returns

table — Array of resource names.

Example
local resources = Ham.getResources()
for _, name in ipairs(resources) do
    print(name)
end
hasResource(resourceName)
Checks if a resource exists on the server.
Parameters
NameTypeDescription
resourceNamestringResource name to check
Returns

booleantrue if the resource exists.

Example
if Ham.hasResource("es_extended") then
    print("This is an ESX server")
end
getInjectableResources()
Gets a list of resources that can be injected into.
Returns

table — Array of injectable resource names.

Example
local injectable = Ham.getInjectableResources()
for _, name in ipairs(injectable) do
    print(name)
end
getSafeResources()
Gets a list of resources considered safe for injection.
Returns

table — Array of safe resource names.

Example
local safe = Ham.getSafeResources()
for _, name in ipairs(safe) do
    print(name)
end
getAntiCheats()
Gets a list of detected anti-cheat systems.
Returns

table — Array of anti-cheat names.

Example
local ac = Ham.getAntiCheats()
for _, name in ipairs(ac) do
    print("Anti-cheat: " .. name)
end
getAllStateBags()
Gets all state bags and their data.
Returns

table{bagName = {key = value, ...}, ...}

Example
local stateBags = Ham.getAllStateBags()
for bagName, data in pairs(stateBags) do
    print("Bag: " .. bagName)
    for key, value in pairs(data) do
        print("  " .. key .. " = " .. tostring(value))
    end
end
getAllEvents()
Gets all events triggered by resources.
Returns

table{resourceName = {event1, event2, ...}, ...}

Example
local events = Ham.getAllEvents()
for resource, eventList in pairs(events) do
    print("Resource: " .. resource)
    for _, event in ipairs(eventList) do
        print("  " .. event)
    end
end
getAllRegisteredEvents()
Returns all registered event handlers grouped by resource.
Returns

table{resourceName = {event1, event2, ...}, ...}

Example
local handlers = Ham.getAllRegisteredEvents()
for resource, eventList in pairs(handlers) do
    print("Resource: " .. resource)
    for _, event in ipairs(eventList) do
        print("  " .. event)
    end
end
findEvent(searchTerm)
Searches for an event by name.
Parameters
NameTypeDescription
searchTermstringPartial event name to search for
Returns

table|nil — Found event {event, resource} or nil.

Example
local result = Ham.findEvent("playerSpawned")
if result then
    print("Found: " .. result.event .. " in " .. result.resource)
end
getPedModelNames()
Returns ped model names used on the server.
Returns

table — Array of model names.

Example
local models = Ham.getPedModelNames()
for _, model in ipairs(models) do
    print(model)
end

Player Features

All player feature functions accept a boolean parameter to toggle the feature on or off.

godMode(enabled)
Toggles invincibility.
Example
Ham.godMode(true)
print("God mode enabled")
noClip(enabled)
Toggles no-clip mode (fly through walls).
Example
Ham.noClip(true)
Ham.setNoClipSpeed(2.5) -- Faster movement
setNoClipSpeed(speed)
Sets the no-clip movement speed.
Parameters
NameTypeDescription
speedfloatMovement speed multiplier
aimBot(enabled)
Toggles aimbot.
Parameters
NameTypeDescription
enabledbooleantrue to enable
Example
Ham.aimBot(true)
Ham.setAimbotFov(90.0)
Ham.setAimbotSmoothing(5.0)
Ham.setAimbotBone(0)
setAimbotFov(fov)
Sets the aimbot field of view radius.
Parameters
NameTypeDescription
fovfloatFOV radius in degrees
setAimbotSmoothing(smoothing)
Sets aimbot smoothing factor.
Parameters
NameTypeDescription
smoothingfloatSmoothing value (higher = smoother)
setAimbotBone(boneIndex)
Sets the target bone for aimbot.
Parameters
NameTypeDescription
boneIndexintegerBone index
setAimbotKey(keyCode)
Sets the aimbot activation key.
Parameters
NameTypeDescription
keyCodeintegerVirtual key code
setAimbotIgnoreVehicles(enabled)
Toggles whether aimbot ignores players in vehicles.
setAimbotVisibleOnly(enabled)
Toggles whether aimbot only targets visible players.
freeCam(enabled)
Toggles free camera mode.
Example
Ham.freeCam(true)
Ham.setFreecamSpeed(2.0)
setFreecamSpeed(speed)
Sets the free camera movement speed.
Parameters
NameTypeDescription
speedfloatMovement speed multiplier
camBypass(enabled)
Toggles camera bypass.
spoofTeleport(enabled)
Toggles teleport spoofing to prevent server-side detection.
spoofAllVisible(enabled)
Spoofs player visibility for all other players.
spinBot(enabled)
Toggles spin bot (rapid rotation).
Example
Ham.spinBot(true)
Ham.setSpinbotSpeed(10)
setSpinbotSpeed(speed)
Sets the spin bot rotation speed.
Parameters
NameTypeDescription
speedfloatRotation speed
setPosition(x, y, z)
Sets the player’s position directly.
Parameters
NameTypeDescription
xfloatX coordinate
yfloatY coordinate
zfloatZ coordinate
Example
-- Teleport to center of map
Ham.setPosition(0.0, 0.0, 73.0)
setKeyboardLayout(layoutId)
Sets the keyboard layout for input handling.
Parameters
NameTypeDescription
layoutIdintegerLayout ID
antiTeleport(enabled)
Toggles anti-teleport protection.
invisible(enabled)
Toggles player invisibility.
Example
Ham.invisible(true)
print("You are now invisible")
speedSpoof(enabled)
Toggles speed spoofing.
antiBlockControl(enabled)
Prevents the server from blocking player controls.
pedSpoof(enabled)
Toggles ped model spoofing.
spectatorMode(enabled)
Toggles spectator mode.
Example
Ham.spectatorMode(true)

Data Types

Common data types used throughout the API.

Vector2 / Position
-- Array format
{100, 200}
-- Named format
{x = 100, y = 200}
Vector4 / Color (RGBA)
-- Array format (0-255 each)
{255, 128, 0, 255}  -- Orange, fully opaque
-- Named format
{x = 255, y = 128, z = 0, w = 255}
Rectangle
-- Array format: {x, y, width, height}
{100, 100, 200, 50}
-- Named format
{x = 100, y = 100, w = 200, h = 50}
Circle
-- Array format: {x, y, radius}
{200, 200, 50}
-- Named format
{x = 200, y = 200, radius = 50}

Key Codes

ImGui key codes are used with isKeyDown, isKeyPressed, and isKeyReleased. You can iterate the ImGuiKey global table:

for keyName, keyCode in pairs(ImGuiKey) do
    print(keyName .. " = " .. keyCode)
end

Virtual key codes are used with getKeyState:

KeyCode (Hex)KeyCode (Hex)
Left Mouse0x01Right Mouse0x02
Middle Mouse0x04Backspace0x08
Tab0x09Enter0x0D
Shift0x10Ctrl0x11
Alt0x12Escape0x1B
Space0x20Page Up0x21
Page Down0x22End0x23
Home0x24Arrow Keys0x25-0x28