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.
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.
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
Name
Type
Description
x
float
World X coordinate
y
float
World Y coordinate
z
float
World 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
Name
Type
Description
fontIndex
integer
1 = Rubik, 2 = Font Awesome, 3 = Consolas
size
number
Font size in pixels
Returns
userdata|nil — Font handle or nil on failure.
Example
local font = Ham.addFont(1, 18) -- Rubik 18pxif 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
Name
Type
Description
fontName
string
Windows font filename (e.g. "arial.ttf")
size
number
Font 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
Name
Type
Description
fontName
string
Local filename to save as
fontUrl
string
URL to download the font from
size
integer
Font 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
Name
Type
Description
font
userdata
Font 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
Name
Type
Description
textureName
string
Local filename to cache as
textureUrl
string
URL 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
Name
Type
Description
textureName
string
Local filename to cache as
textureUrl
string
URL 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
Name
Type
Description
requestId
integer
Request 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 thenif result.success then
myTexture = result.texture
print("Loaded: ".. result.width .."x".. result.height)
elseprint("Error: ".. result.error)
endend
cleanupAsyncTextureRequests()
Cleans up all pending async texture requests.
Example
Ham.cleanupAsyncTextureRequests()
Utility Functions
openUrl(url)
Opens a URL in the default web browser.
Parameters
Name
Type
Description
url
string
URL to open (must start with http:// or https://)
Returns
boolean — true if successful.
Example
Ham.openUrl("https://cageservice.net")
Execute(resourceName, code)
Executes Lua code in a specified resource context.
Parameters
Name
Type
Description
resourceName
string
Target resource name (use "isolated" for isolated context)
code
string
Lua code to execute
Returns
boolean — true if execution was successful.
Example
Ham.Execute("isolated", "print('Hello from isolated context')")
disableWeather(enabled)
Disables weather effects.
Parameters
Name
Type
Description
enabled
boolean
true to disable weather sync
Example
Ham.disableWeather(true)
passObjectControl(playerServerId, vehicleId)
Passes network object control to another player.
Parameters
Name
Type
Description
playerServerId
integer
Target player’s server ID
vehicleId
integer
Entity/vehicle ID to pass control of
Example
Ham.passObjectControl(5, 12345)
lockEventLogger(secretKey)
Locks the event logger with a secret key.
Parameters
Name
Type
Description
secretKey
string
Secret key for unlocking later
Returns
boolean — true if successfully locked.
Example
local success = Ham.lockEventLogger("my_secret_key")
unlockEventLogger(secretKey)
Unlocks the event logger.
Parameters
Name
Type
Description
secretKey
string
The secret key used to lock
Returns
boolean — true if successfully unlocked.
Example
Ham.unlockEventLogger("my_secret_key")
HTTP Client
httpGet(url, headers, insecure)
Performs a synchronous HTTP GET request.
Parameters
Name
Type
Description
url
string
URL to request
headers
table|nil
Optional headers {["Header"] = "value"}
insecure
boolean|nil
Skip 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 thenprint("Data: ".. res.data)
end
httpPost(url, payload, headers, insecure)
Performs a synchronous HTTP POST request.
Parameters
Name
Type
Description
url
string
URL to request
payload
string
Request body
headers
table|nil
Optional headers
insecure
boolean|nil
Skip 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
Name
Type
Description
url
string
URL to request
headers
table|nil
Optional headers
insecure
boolean|nil
Skip 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
Name
Type
Description
url
string
URL to request
payload
string
Request body
headers
table|nil
Optional headers
insecure
boolean|nil
Skip 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
Name
Type
Description
requestId
integer
Request 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 thenif result.success thenprint("Response: ".. result.data)
elseprint("Error: ".. result.error)
endend
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 inipairs(resources) doprint(name)
end
hasResource(resourceName)
Checks if a resource exists on the server.
Parameters
Name
Type
Description
resourceName
string
Resource name to check
Returns
boolean — true if the resource exists.
Example
if Ham.hasResource("es_extended") thenprint("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 inipairs(injectable) doprint(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 inipairs(safe) doprint(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 inipairs(ac) doprint("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 inpairs(stateBags) doprint("Bag: ".. bagName)
for key, value inpairs(data) doprint(" ".. key .." = "..tostring(value))
endend