Utilities Library
Utility helpers for colors, time, math, debug printing, and simple entity spawning.
Overview
The utilities library provides a comprehensive collection of helper functions for common scripting tasks in the Lilia framework. It includes utilities for color manipulation (HSV interpolation, blending, darkening, lightening), time and date operations (formatting, conversion, difference calculations), vector and angle serialization, debug printing, and server-side entity spawning. The library operates primarily in the shared realm, making functions available on both client and server, with some server-specific functions for entity management. It serves as a central library used by other modules and provides shared constants and utilities for networking data.
lia.utilities.speedTest
đ Purpose
Run a function repeatedly and measure the elapsed time.
â° When Called
When benchmarking a function's performance or measuring execution time.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
func |
function | Function to call repeatedly |
n |
number | Number of iterations to run |
âŠī¸ Returns
- number - Elapsed time in seconds per iteration
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Benchmark a function
local took = lia.utilities.speedTest(function() end, 1e5)
print(took)
đ Medium Complexity
-- Medium: Compare function performance
local function testFunc()
local sum = 0
for i = 1, 100 do sum = sum + i end
end
local avgTime = lia.utilities.speedTest(testFunc, 1000)
print("Average time: " .. avgTime .. " seconds")
âī¸ High Complexity
-- High: Benchmark multiple functions with analysis
local functions = {
{name = "Function A", func = functionA},
{name = "Function B", func = functionB}
}
for _, data in ipairs(functions) do
local time = lia.utilities.speedTest(data.func, 1e5)
print(data.name .. " took " .. time .. " seconds per iteration")
end
lia.utilities.daysBetween
đ Purpose
Return the number of days between two timestamps or time strings.
â° When Called
When comparing dates for cooldowns, reports, or time-based calculations.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
t1 |
string|number | First time (timestamp or formatted string) |
t2 |
string|number | Second time (timestamp or formatted string) |
âŠī¸ Returns
- number - Whole or fractional days between the two times
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Calculate days between timestamps
local days = lia.utilities.daysBetween(os.time(), os.time() + 172800)
đ Medium Complexity
-- Medium: Check if cooldown has expired
local lastUsed = player:GetPData("lastActionTime", "0")
local daysSince = lia.utilities.daysBetween(lastUsed, os.time())
if daysSince >= 7 then
print("Cooldown expired")
end
âī¸ High Complexity
-- High: Analyze multiple date ranges
local dates = {
{start = "2024-01-01", end = "2024-01-15"},
{start = "2024-02-01", end = "2024-02-20"}
}
for _, dateRange in ipairs(dates) do
local days = lia.utilities.daysBetween(dateRange.start, dateRange.end)
print("Range spans " .. days .. " days")
end
lia.utilities.lerpHSV
đ Purpose
Interpolate between two colors in HSV color space.
â° When Called
When animating color transitions or creating smooth color gradients.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
c1 |
Color | Start color |
c2 |
Color | End color |
maxVal |
number | Maximum range value |
curVal |
number | Current position in the range |
minVal |
number | Minimum range value (optional, defaults to 0) |
âŠī¸ Returns
- Color - Interpolated color between c1 and c2
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Interpolate between red and blue
local c = lia.utilities.lerpHSV(Color(255,0,0), Color(0,0,255), 1, 0.5, 0)
đ Medium Complexity
-- Medium: Animate color based on health
local health = player:Health()
local maxHealth = player:GetMaxHealth()
local color = lia.utilities.lerpHSV(
Color(255, 0, 0), -- Red (low health)
Color(0, 255, 0), -- Green (full health)
maxHealth,
health,
0
)
âī¸ High Complexity
-- High: Dynamic color system with multiple states
local function getStatusColor(status, intensity)
local colors = {
good = Color(0, 255, 0),
warning = Color(255, 255, 0),
bad = Color(255, 0, 0)
}
local baseColor = colors[status] or colors.good
return lia.utilities.lerpHSV(
Color(50, 50, 50), -- Dark base
baseColor,
100,
intensity,
0
)
end
lia.utilities.darken
đ Purpose
Return a darker version of a color by reducing lightness.
â° When Called
When you need to create a darker shade of an existing color.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
col |
Color | Base color to darken |
amt |
number | Amount to darken (0-1, where 1 is darkest) |
âŠī¸ Returns
- Color - Darkened color
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Create darker variant for hover states
local baseColor = Color(100, 150, 200)
local hoverColor = lia.utilities.darken(baseColor, 0.3)
âī¸ High Complexity
-- High: Generate color palette with dark variants
local function createColorPalette(baseColor)
return {
light = lia.utilities.lighten(baseColor, 0.3),
base = baseColor,
dark = lia.utilities.darken(baseColor, 0.3),
darker = lia.utilities.darken(baseColor, 0.6)
}
end
lia.utilities.lerpColor
đ Purpose
Linear interpolate between two colors in RGB color space.
â° When Called
When you need smooth color transitions in RGB space rather than HSV.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
f |
number | Fraction between 0 and 1 (0 = from, 1 = to) |
from |
Color | Start color |
to |
Color | End color |
âŠī¸ Returns
- Color - Interpolated color
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Lerp between two colors
local midColor = lia.utilities.lerpColor(0.5, Color(255,0,0), Color(0,0,255))
đ Medium Complexity
-- Medium: Animate color over time
local function getAnimatedColor(t)
return lia.utilities.lerpColor(
math.sin(t) * 0.5 + 0.5,
Color(255, 0, 0),
Color(0, 255, 0)
)
end
âī¸ High Complexity
-- High: Multi-color gradient system
local function getGradientColor(colors, progress)
progress = math.Clamp(progress, 0, 1)
local segment = 1 / (#colors - 1)
local index = math.floor(progress / segment) + 1
index = math.min(index, #colors - 1)
local localProgress = (progress % segment) / segment
return lia.utilities.lerpColor(localProgress, colors[index], colors[index + 1])
end
lia.utilities.blend
đ Purpose
Blend two colors by a specified ratio.
â° When Called
When you need to mix two colors together proportionally.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
a |
Color | First color |
b |
Color | Second color |
r |
number | Blend ratio (0-1, where 0 = a, 1 = b) |
âŠī¸ Returns
- Color - Blended color
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Blend based on condition
local function getConditionalColor(condition)
local ratio = condition and 1.0 or 0.0
return lia.utilities.blend(Color(255,0,0), Color(0,255,0), ratio)
end
âī¸ High Complexity
-- High: Dynamic color blending system
local function blendMultiple(colors, ratios)
local result = colors[1]
for i = 2, #colors do
result = lia.utilities.blend(result, colors[i], ratios[i] or 0.5)
end
return result
end
lia.utilities.rgb
đ Purpose
Shorthand to create a Color object from RGB values.
â° When Called
When you need a quick way to create color objects without typing Color().
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
r |
number | Red component (0-255) |
g |
number | Green component (0-255) |
b |
number | Blue component (0-255) |
âŠī¸ Returns
- Color - Color object
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Create color from variables
local r, g, b = 128, 64, 192
local color = lia.utilities.rgb(r, g, b)
âī¸ High Complexity
-- High: Generate color palette
local function generatePalette(baseR, baseG, baseB, count)
local palette = {}
for i = 1, count do
local factor = i / count
palette[i] = lia.utilities.rgb(
baseR * factor,
baseG * factor,
baseB * factor
)
end
return palette
end
lia.utilities.rainbow
đ Purpose
Return a cycling rainbow color over time.
â° When Called
When you need animated rainbow colors that cycle continuously.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
freq |
number | Speed factor for color cycling |
âŠī¸ Returns
- Color - Current rainbow color
đ Realm
Client
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Animate text with rainbow
hook.Add("HUDPaint", "RainbowText", function()
local color = lia.utilities.rainbow(0.5)
draw.SimpleText("Rainbow Text", "DermaDefault", 100, 100, color)
end)
âī¸ High Complexity
-- High: Multiple rainbow elements with different speeds
local function drawRainbowUI()
local colors = {
lia.utilities.rainbow(0.5),
lia.utilities.rainbow(1.0),
lia.utilities.rainbow(1.5)
}
for i, color in ipairs(colors) do
draw.RoundedBox(0, 10, 10 + i * 30, 200, 20, color)
end
end
lia.utilities.colorCycle
đ Purpose
Cycle between two colors over time.
â° When Called
When you need smooth color transitions between two specific colors.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
a |
Color | First color |
b |
Color | Second color |
f |
number | Frequency/speed of cycling (optional, defaults to 1) |
âŠī¸ Returns
- Color - Current color in the cycle
đ Realm
Client
đĄ Example Usage
đ° Low Complexity
-- Simple: Cycle between two colors
local color = lia.utilities.colorCycle(Color(255,0,0), Color(0,0,255))
đ Medium Complexity
-- Medium: Pulsing effect
hook.Add("HUDPaint", "PulsingBox", function()
local color = lia.utilities.colorCycle(Color(100,100,100), Color(255,255,255), 2)
draw.RoundedBox(0, 10, 10, 200, 200, color)
end)
âī¸ High Complexity
-- High: Multi-state color cycling
local function getStateColor(state)
local colors = {
idle = {Color(100,100,100), Color(150,150,150)},
active = {Color(255,0,0), Color(255,255,0)},
warning = {Color(255,100,0), Color(255,0,0)}
}
local stateColors = colors[state] or colors.idle
return lia.utilities.colorCycle(stateColors[1], stateColors[2], 1.5)
end
lia.utilities.colorToHex
đ Purpose
Convert a Color object to a hexadecimal string format.
â° When Called
When you need to convert colors to hex format for web or API usage.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
c |
Color | Color to convert |
âŠī¸ Returns
- string - Hexadecimal color string (e.g., "0xRRGGBB")
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Store color as hex string
local color = Color(128, 64, 192)
local hexString = lia.utilities.colorToHex(color)
player:SetPData("favoriteColor", hexString)
âī¸ High Complexity
-- High: Export color palette to hex format
local function exportPaletteToHex(palette)
local hexPalette = {}
for name, color in pairs(palette) do
hexPalette[name] = lia.utilities.colorToHex(color)
end
return util.TableToJSON(hexPalette)
end
lia.utilities.lighten
đ Purpose
Return a lighter version of a color by increasing lightness.
â° When Called
When you need to create a lighter shade of an existing color.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
col |
Color | Base color to lighten |
amt |
number | Amount to lighten (0-1, where 1 is lightest) |
âŠī¸ Returns
- Color - Lightened color
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Create lighter variant for UI elements
local baseColor = Color(50, 50, 50)
local highlightColor = lia.utilities.lighten(baseColor, 0.4)
âī¸ High Complexity
-- High: Generate full color scale
local function createColorScale(baseColor, steps)
local scale = {}
for i = 0, steps do
local amount = i / steps
scale[i + 1] = lia.utilities.lighten(baseColor, amount)
end
return scale
end
lia.utilities.toText
đ Purpose
Serialize a Color to a human-readable string format.
â° When Called
When you need to convert colors to text format for storage or display.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
c |
Color | Color to serialize |
âŠī¸ Returns
- string|nil - Color as "r,g,b,a" string, or nil if invalid
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Store color as text
local color = Color(128, 64, 192, 255)
local colorText = lia.utilities.toText(color)
player:SetPData("uiColor", colorText)
âī¸ High Complexity
-- High: Serialize color palette
local function serializePalette(palette)
local serialized = {}
for name, color in pairs(palette) do
serialized[name] = lia.utilities.toText(color)
end
return util.TableToJSON(serialized)
end
lia.utilities.secondsToDHMS
đ Purpose
Convert seconds into days, hours, minutes, and seconds.
â° When Called
When you need to break down a time duration into its components.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
sec |
number | Total seconds to convert |
âŠī¸ Returns
- number, number, number, number - Days, hours, minutes, seconds
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Format time remaining
local function formatTimeRemaining(seconds)
local d, h, m, s = lia.utilities.secondsToDHMS(seconds)
local parts = {}
if d > 0 then table.insert(parts, d .. "d") end
if h > 0 then table.insert(parts, h .. "h") end
if m > 0 then table.insert(parts, m .. "m") end
if s > 0 then table.insert(parts, s .. "s") end
return table.concat(parts, " ")
end
âī¸ High Complexity
-- High: Multi-time formatting with localization
local function formatTimes(times)
local formatted = {}
for i, seconds in ipairs(times) do
local d, h, m, s = lia.utilities.secondsToDHMS(seconds)
formatted[i] = {
days = d,
hours = h,
minutes = m,
seconds = s,
formatted = string.format("%dd %dh %dm %ds", d, h, m, s)
}
end
return formatted
end
lia.utilities.hMSToSeconds
đ Purpose
Convert hours, minutes, and seconds to total seconds.
â° When Called
When you need to convert time components into a single duration value.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
h |
number | Hours |
m |
number | Minutes |
s |
number | Seconds |
âŠī¸ Returns
- number - Total seconds
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Calculate total duration
local function calculateTotalDuration(periods)
local total = 0
for _, period in ipairs(periods) do
total = total + lia.utilities.hMSToSeconds(period.h, period.m, period.s)
end
return total
end
âī¸ High Complexity
-- High: Schedule system with time conversion
local function scheduleEvents(events)
for _, event in ipairs(events) do
local delay = lia.utilities.hMSToSeconds(event.hours, event.minutes, event.seconds)
timer.Simple(delay, function()
hook.Run("ScheduledEvent", event.name)
end)
end
end
lia.utilities.formatTimestamp
đ Purpose
Format a timestamp into a locale-friendly table or string.
â° When Called
When you need to display timestamps in a readable format.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
ts |
number | Unix timestamp |
âŠī¸ Returns
- table|string - Formatted time as table or string
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Format multiple timestamps
local function formatTimestamps(timestamps)
local formatted = {}
for _, ts in ipairs(timestamps) do
table.insert(formatted, lia.utilities.formatTimestamp(ts))
end
return formatted
end
âī¸ High Complexity
-- High: Logging system with formatted timestamps
local function logEvent(event, data)
local timestamp = lia.utilities.formatTimestamp(os.time())
local logEntry = {
time = timestamp,
event = event,
data = data
}
table.insert(logSystem.entries, logEntry)
end
lia.utilities.weekdayName
đ Purpose
Parse a time string and return the weekday name.
â° When Called
When you need to determine the day of the week from a formatted time string.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
str |
string | Formatted time string (HH:MM:SS - DD/MM/YYYY) |
âŠī¸ Returns
- string - Weekday name (e.g., "Monday")
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Check if it's a weekend
local function isWeekend(timeString)
local day = lia.utilities.weekdayName(timeString)
return day == "Saturday" or day == "Sunday"
end
âī¸ High Complexity
-- High: Schedule system with weekday filtering
local function scheduleWeeklyEvents(events)
for _, event in ipairs(events) do
local day = lia.utilities.weekdayName(event.time)
if day == event.weekday then
timer.Simple(getTimeUntil(event.time), function()
hook.Run("WeeklyEvent", event.name)
end)
end
end
end
lia.utilities.timeUntil
đ Purpose
Calculate time difference until a future time string.
â° When Called
When you need to know how long until a specific time.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
str |
string | Future time string (HH:MM:SS - DD/MM/YYYY) |
âŠī¸ Returns
- string - Human-readable time difference
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Check if event is soon
local function isEventSoon(eventTime)
local timeLeft = lia.utilities.timeUntil(eventTime)
return timeLeft:match("%d+") and tonumber(timeLeft:match("%d+")) < 60
end
âī¸ High Complexity
-- High: Event notification system
local function setupEventNotifications(events)
for _, event in ipairs(events) do
timer.Create("event_" .. event.id, 60, 0, function()
local timeLeft = lia.utilities.timeUntil(event.time)
if timeLeft then
hook.Run("EventTimeUpdate", event.id, timeLeft)
end
end)
end
end
lia.utilities.currentLocalTime
đ Purpose
Return the current local time as a formatted string.
â° When Called
When you need the current time in a formatted string format.
âī¸ Parameters
None
âŠī¸ Returns
- string - Current time formatted as "HH:MM:SS - DD/MM/YYYY"
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Log with timestamp
local function log(message)
local timestamp = lia.utilities.currentLocalTime()
print("[" .. timestamp .. "] " .. message)
end
âī¸ High Complexity
-- High: Comprehensive logging system
local function logEvent(eventType, data)
local timestamp = lia.utilities.currentLocalTime()
local logEntry = {
timestamp = timestamp,
type = eventType,
data = data,
player = IsValid(ply) and ply:SteamID() or "SERVER"
}
table.insert(logSystem, logEntry)
end
lia.utilities.timeDifference
đ Purpose
Return a human-friendly difference between now and a time string.
â° When Called
When you need to calculate and display time differences.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
str |
string | Time string (HH:MM:SS - DD/MM/YYYY) |
âŠī¸ Returns
- number - Days difference
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Check if within time window
local function isWithinDays(timeString, maxDays)
local days = lia.utilities.timeDifference(timeString)
return math.abs(days) <= maxDays
end
âī¸ High Complexity
-- High: Activity tracking system
local function checkPlayerActivity(steamID)
local lastSeen = GetPData(steamID, "lastSeen", "")
if lastSeen == "" then return nil end
local daysAgo = lia.utilities.timeDifference(lastSeen)
return {
steamID = steamID,
lastSeen = lastSeen,
daysAgo = daysAgo,
active = daysAgo <= 30
}
end
lia.utilities.serializeVector
đ Purpose
Serialize a Vector object to JSON format.
â° When Called
When you need to store or transmit vector data as JSON.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
v |
Vector | Vector to serialize |
âŠī¸ Returns
- string - JSON string representation of the vector
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Save player position
local function savePlayerPosition(player)
local pos = player:GetPos()
local json = lia.utilities.serializeVector(pos)
player:SetPData("lastPosition", json)
end
âī¸ High Complexity
-- High: Save multiple positions
local function saveCheckpoints(checkpoints)
local data = {}
for i, checkpoint in ipairs(checkpoints) do
data[i] = lia.utilities.serializeVector(checkpoint.pos)
end
return util.TableToJSON(data)
end
lia.utilities.deserializeVector
đ Purpose
Deserialize JSON data into a Vector object.
â° When Called
When you need to reconstruct a vector from JSON data.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
data |
string | JSON string to deserialize |
âŠī¸ Returns
- Vector - Reconstructed vector
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Deserialize a vector
local json = "[100,200,300]"
local vec = lia.utilities.deserializeVector(json)
đ Medium Complexity
-- Medium: Load player position
local function loadPlayerPosition(player)
local json = player:GetPData("lastPosition", "")
if json ~= "" then
local pos = lia.utilities.deserializeVector(json)
player:SetPos(pos)
end
end
âī¸ High Complexity
-- High: Load checkpoint system
local function loadCheckpoints(jsonData)
local data = util.JSONToTable(jsonData)
local checkpoints = {}
for i, vecJson in ipairs(data) do
checkpoints[i] = {
pos = lia.utilities.deserializeVector(vecJson),
id = i
}
end
return checkpoints
end
lia.utilities.serializeAngle
đ Purpose
Serialize an Angle object to JSON format.
â° When Called
When you need to store or transmit angle data as JSON.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
a |
Angle | Angle to serialize |
âŠī¸ Returns
- string - JSON string representation of the angle
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Save entity angles
local function saveEntityAngles(entity)
local ang = entity:GetAngles()
local json = lia.utilities.serializeAngle(ang)
entity:SetPData("savedAngles", json)
end
âī¸ High Complexity
-- High: Save entity transform
local function saveEntityTransform(entity)
return {
pos = lia.utilities.serializeVector(entity:GetPos()),
ang = lia.utilities.serializeAngle(entity:GetAngles())
}
end
lia.utilities.deserializeAngle
đ Purpose
Deserialize JSON data into an Angle object.
â° When Called
When you need to reconstruct an angle from JSON data.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
data |
string | JSON string to deserialize |
âŠī¸ Returns
- Angle - Reconstructed angle
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Deserialize an angle
local json = "[0,90,0]"
local ang = lia.utilities.deserializeAngle(json)
đ Medium Complexity
-- Medium: Load entity angles
local function loadEntityAngles(entity)
local json = entity:GetPData("savedAngles", "")
if json ~= "" then
local ang = lia.utilities.deserializeAngle(json)
entity:SetAngles(ang)
end
end
âī¸ High Complexity
-- High: Load entity transform
local function loadEntityTransform(entity, data)
entity:SetPos(lia.utilities.deserializeVector(data.pos))
entity:SetAngles(lia.utilities.deserializeAngle(data.ang))
end
lia.utilities.dprint
đ Purpose
Print a prefixed debug line to console.
â° When Called
When you need to output debug information with a consistent prefix.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
... |
any | Values to print (variable arguments) |
âŠī¸ Returns
- void
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Debug with multiple values
lia.utilities.dprint("Player", ply:Nick(), "joined at", os.time())
âī¸ High Complexity
-- High: Conditional debug system
local function debugLog(condition, ...)
if condition and GetConVar("developer"):GetInt() > 0 then
lia.utilities.dprint(...)
end
end
debugLog(true, "Module loaded", moduleName)
lia.utilities.spawnProp
đ Purpose
Spawn a physics prop with optional force, lifetime, angle, and color.
â° When Called
When spawning temporary props server-side for effects or gameplay.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
model |
string | Model path for the prop |
pos |
Vector | Position to spawn at |
force |
Vector|nil | Optional force to apply |
life |
number|nil | Optional auto-remove after seconds |
ang |
Angle|nil | Optional spawn angle |
col |
Color|nil | Optional collision group override |
âŠī¸ Returns
- Entity - The spawned entity
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
-- Simple: Spawn a prop
local ent = lia.utilities.spawnProp("models/props_c17/oildrum001.mdl", Vector(0,0,64))
đ Medium Complexity
-- Medium: Spawn prop with force and lifetime
local ent = lia.utilities.spawnProp(
"models/props_junk/wood_crate001a.mdl",
Vector(0, 0, 100),
Vector(0, 0, 500),
10,
Angle(0, 45, 0)
)
âī¸ High Complexity
-- High: Spawn prop system with validation
local function spawnPropSafe(model, pos, options)
options = options or {}
if not util.IsValidModel(model) then
error("Invalid model: " .. model)
return nil
end
local ent = lia.utilities.spawnProp(
model,
pos,
options.force,
options.lifetime,
options.angle,
options.collisionGroup
)
if IsValid(ent) and options.color then
ent:SetColor(options.color)
end
return ent
end
lia.utilities.spawnEntities
đ Purpose
Spawn multiple entities from a class->properties table.
â° When Called
When you need to spawn multiple entities at once from a configuration table.
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
tbl |
table | Map of entity class to properties (position or full property table) |
âŠī¸ Returns
- void
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
-- Simple: Spawn entities
lia.utilities.spawnEntities({
["prop_physics"] = { model = "models/props_junk/wood_crate001a.mdl", pos = Vector(0,0,64) }
})
đ Medium Complexity
-- Medium: Spawn multiple entity types
lia.utilities.spawnEntities({
["prop_physics"] = Vector(0, 0, 64),
["prop_dynamic"] = Vector(100, 0, 64),
["npc_combine_s"] = Vector(200, 0, 64)
})
âī¸ High Complexity
-- High: Spawn system with full configuration
local function spawnMapEntities(mapData)
local entities = {}
for class, config in pairs(mapData.entities) do
if istable(config) then
entities[class] = {
pos = config.pos or Vector(0,0,0),
ang = config.ang or Angle(0,0,0),
model = config.model,
keyvalues = config.keyvalues or {}
}
else
entities[class] = config
end
end
lia.utilities.spawnEntities(entities)
end