Script Helpers
helpers.lua
This utility module provides functions for resource checks, debugging, formatting, coordinate math, vector calculations, progress bars, and drawing tools.
isStarted(script)
Returns
true
if a resource is started.
Example:
getScript()
Caches and returns the name of the current resource.
Easier than typing GetCurrentResourceName()
over and over
Example:
isServer()
Returns true if running on the server.
This was mainly made becuase IsDuplicityVersion()
kept confusing me
Example:
debugPrint(...) / eventPrint(...)
Prints messages with debug context if debugMode is enabled.
Example:
jsonPrint(table)
Pretty-prints a table with colorized JSON if debugMode is enabled.
Example:
keyGen()
Generates a 3-character unique ID.
Good grabbing randomly generated strings
Example:
cv(amount)
Comma-separates a number (e.g., 1000000
to 1,000,000
).
Example:
formatCoord(vec)
Outputs a formatted string from vector types.
Compacts and adds console colours to the vector to be printed
Example:
getCenterOfZones(coords)
Returns average center position of a vector3 list.
A few use cases, but I used it to see how well spaced blips were together
Example:
countTable(tbl)
Returns the number of entries in a table.
Simple function to print how many "entires" are in a table
Example:
pairsByKeys(tbl)
Iterator for sorted keys.
Example:
concatenateText(tbl)
Joins string table entries with newlines.
Example:
RotationToDirection(rot)
Converts a heading vector to a directional vector.
Example:
basicBar(percent)
Returns a bar like ████░░░░░
at 50%.
Basically a progress bar but as a string, I use this in drawTexts when progressbars aren't able to be used
Example:
normalizeVector(vec)
Returns a normalized version of a vector3.
Example:
drawLine(start, end, color) / drawSphere(pos, color)
Debug drawing helpers.
Stays visible for more than one frame
Example:
PerformRaycast(start, end, entity?, flags?)
Raycast with material detection. Returns ray hit data.
Example:
adjustForGround(coords)
Adjusts a z-coordinate to ground height.
Example:
ensureNetToVeh(id) / ensureNetToEnt(id)
Resolves net ID to entity safely.
Example:
sendLog(text) / sendServerLog(data)
Logging helpers, includes player name, coords, script source.
Example:
GetGroundMaterialAtPosition(coords)
Returns the material hash + readable name from the surface below coords.
Example:
GetPropDimensions(model)
Loads a model and returns width, depth, height.
I use this to parse a model to create a box target instead of entity target when creating distProps/distPeds
Example:
GetEntityForwardVector(entity)
Returns the forward direction vector based on entity heading.
Example:
Last updated