Entity Meta
Entity management system for the Lilia framework.
Overview
The entity meta table provides comprehensive functionality for extending Garry's Mod entities with Lilia-specific features and operations. It handles entity identification, sound management, door access control, vehicle ownership, network variable synchronization, and entity-specific operations. The meta table operates on both server and client sides, with the server managing entity data and validation while the client provides entity interaction and display. It includes integration with the door system for access control, vehicle system for ownership management, network system for data synchronization, and sound system for audio playback. The meta table ensures proper entity identification, access control validation, network data synchronization, and comprehensive entity interaction management for doors, vehicles, and other game objects.
EmitSound
đ Purpose
Emits a sound from the entity, with support for web sounds and URL-based audio
â° When Called
When an entity needs to play a sound effect or audio
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
soundName |
string | The sound file path, URL, or websound identifier |
soundLevel |
number, optional | Sound level/distance (default: 100) |
pitchPercent |
number, optional | Pitch adjustment percentage |
volume |
number, optional | Volume level (default: 100) |
channel |
number, optional | Sound channel |
flags |
number, optional | Sound flags |
dsp |
number, optional | DSP effect |
âŠī¸ Returns
- boolean - True if sound was played successfully
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Play sound with custom volume and distance
entity:EmitSound("ambient/atmosphere/city_hum_loop.wav", 200, 100, 0.5)
âī¸ High Complexity
-- High: Play web sound with full parameters
entity:EmitSound("https://example.com/sound.mp3", 300, 100, 0.8, CHAN_AUTO, 0, 0)
isProp
đ Purpose
Checks if the entity is a physics prop
â° When Called
When you need to determine if an entity is a prop_physics object
âŠī¸ Returns
- boolean - True if the entity is a prop_physics, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in conditional logic
if entity:isProp() and entity:GetPhysicsObject():IsValid() then
entity:GetPhysicsObject():Wake()
end
âī¸ High Complexity
-- High: Combine with other checks for complex logic
if entity:isProp() and entity:GetModel():find("wood") then
-- Handle wooden prop specifically
entity:SetMaterial("models/wood")
end
isItem
đ Purpose
Checks if the entity is a Lilia item entity
â° When Called
When you need to determine if an entity is a lia_item object
âŠī¸ Returns
- boolean - True if the entity is a lia_item, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in item handling logic
if entity:isItem() and entity:GetItemData() then
local itemData = entity:GetItemData()
print("Item name:", itemData.name)
end
âī¸ High Complexity
-- High: Combine with inventory system
if entity:isItem() and IsValid(ply) then
local itemData = entity:GetItemData()
if itemData and ply:getChar():getInv():canFit(itemData) then
ply:getChar():getInv():add(itemData)
entity:Remove()
end
end
isMoney
đ Purpose
Checks if the entity is a Lilia money entity
â° When Called
When you need to determine if an entity is a lia_money object
âŠī¸ Returns
- boolean - True if the entity is a lia_money, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in money handling logic
if entity:isMoney() and IsValid(ply) then
local amount = entity:GetAmount() or 0
ply:getChar():giveMoney(amount)
entity:Remove()
end
âī¸ High Complexity
-- High: Combine with economy system
if entity:isMoney() and IsValid(ply) then
local amount = entity:GetAmount() or 0
local char = ply:getChar()
if char:getMoney() + amount <= char:getMaxMoney() then
char:giveMoney(amount)
entity:Remove()
ply:notify("You picked up $" .. amount)
end
end
isSimfphysCar
đ Purpose
Checks if the entity is a Simfphys vehicle or LVS vehicle
â° When Called
When you need to determine if an entity is a vehicle from Simfphys or LVS
âŠī¸ Returns
- boolean - True if the entity is a supported vehicle, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Check if entity is a vehicle
if entity:isSimfphysCar() then
print("This is a vehicle")
end
đ Medium Complexity
-- Medium: Use in vehicle handling logic
if entity:isSimfphysCar() and IsValid(ply) then
if entity:GetDriver() == ply then
ply:notify("You are driving this vehicle")
end
end
âī¸ High Complexity
-- High: Combine with vehicle systems
if entity:isSimfphysCar() and IsValid(ply) then
local char = ply:getChar()
if char:hasFlags("v") then
entity:SetDriver(ply)
entity:SetNetVar("owner", char:getID())
end
end
checkDoorAccess
đ Purpose
Checks if a client has access to a door with the specified access level
â° When Called
When you need to verify if a player can access a door
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player to check access for |
access |
number, optional | The required access level (default: DOOR_GUEST) |
âŠī¸ Returns
- boolean - True if the client has access, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Check specific access level
if door:checkDoorAccess(ply, DOOR_OWNER) then
ply:notify("You own this door")
end
âī¸ High Complexity
-- High: Use in door interaction system
if door:checkDoorAccess(ply, DOOR_GUEST) then
if door:isDoorLocked() then
ply:notify("The door is locked")
else
door:Fire("Open")
ply:notify("Door opened")
end
else
ply:notify("You don't have access to this door")
end
keysOwn
đ Purpose
Sets a client as the owner of a vehicle and updates ownership data
â° When Called
When a player becomes the owner of a vehicle
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player to set as the owner |
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Set owner with validation
if IsValid(ply) and ply:getChar() then
vehicle:keysOwn(ply)
ply:notify("You now own this vehicle")
end
âī¸ High Complexity
-- High: Use in vehicle purchase system
if ply:getChar():getMoney() >= vehiclePrice then
ply:getChar():takeMoney(vehiclePrice)
vehicle:keysOwn(ply)
ply:notify("Vehicle purchased for $" .. vehiclePrice)
else
ply:notify("Insufficient funds")
end
keysLock
đ Purpose
Locks a vehicle if it is a valid vehicle entity
â° When Called
When a player wants to lock their vehicle
âŠī¸ Returns
- None
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Lock with validation
if IsValid(vehicle) and vehicle:IsVehicle() then
vehicle:keysLock()
ply:notify("Vehicle locked")
end
âī¸ High Complexity
-- High: Use in vehicle interaction system
if vehicle:keysOwn(ply) and not vehicle:isLocked() then
vehicle:keysLock()
ply:notify("Vehicle locked")
elseif not vehicle:keysOwn(ply) then
ply:notify("You don't own this vehicle")
else
ply:notify("Vehicle is already locked")
end
keysUnLock
đ Purpose
Unlocks a vehicle if it is a valid vehicle entity
â° When Called
When a player wants to unlock their vehicle
âŠī¸ Returns
- None
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Unlock with validation
if IsValid(vehicle) and vehicle:IsVehicle() then
vehicle:keysUnLock()
ply:notify("Vehicle unlocked")
end
âī¸ High Complexity
-- High: Use in vehicle interaction system
if vehicle:keysOwn(ply) and vehicle:isLocked() then
vehicle:keysUnLock()
ply:notify("Vehicle unlocked")
elseif not vehicle:keysOwn(ply) then
ply:notify("You don't own this vehicle")
else
ply:notify("Vehicle is already unlocked")
end
getDoorOwner
đ Purpose
Gets the owner of a door entity
â° When Called
When you need to retrieve the owner of a door
âŠī¸ Returns
- Player or nil - The door owner if it's a vehicle with CPPI, nil otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Get door owner
local owner = door:getDoorOwner()
if IsValid(owner) then
print("Door owner:", owner:Name())
end
đ Medium Complexity
-- Medium: Check ownership for access control
local owner = door:getDoorOwner()
if IsValid(owner) and owner == ply then
ply:notify("You own this door")
end
âī¸ High Complexity
-- High: Use in door management system
local owner = door:getDoorOwner()
if IsValid(owner) then
local char = owner:getChar()
if char then
door:setNetVar("ownerName", char:getName())
door:setNetVar("ownerID", char:getID())
end
end
isLocked
đ Purpose
Checks if the entity is locked using network variables
â° When Called
When you need to check if an entity is in a locked state
âŠī¸ Returns
- boolean - True if the entity is locked, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in interaction logic
if entity:isLocked() then
ply:notify("This is locked")
else
entity:Use(ply)
end
âī¸ High Complexity
-- High: Use in security system
if entity:isLocked() and not ply:hasFlags("A") then
ply:notify("Access denied - locked")
elseif entity:isLocked() and ply:hasFlags("A") then
entity:setLocked(false)
ply:notify("Unlocked with admin access")
end
isDoorLocked
đ Purpose
Checks if a door entity is locked using internal variables or custom properties
â° When Called
When you need to check if a door is in a locked state
âŠī¸ Returns
- boolean - True if the door is locked, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in door interaction
if door:isDoorLocked() then
ply:notify("The door is locked")
else
door:Fire("Open")
end
âī¸ High Complexity
-- High: Use in door access system
if door:isDoorLocked() and not door:checkDoorAccess(ply, DOOR_OWNER) then
ply:notify("Door is locked and you don't have access")
elseif door:isDoorLocked() and door:checkDoorAccess(ply, DOOR_OWNER) then
door:setLocked(false)
ply:notify("Door unlocked with your key")
end
getEntItemDropPos
đ Purpose
Calculates the position and angle for dropping items from an entity
â° When Called
When an entity needs to drop an item at a specific location
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
offset |
number, optional | Distance to trace forward from entity (default: 64) |
âŠī¸ Returns
- Vector, Angle - The drop position and angle
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use with custom offset
local pos, ang = entity:getEntItemDropPos(100)
local item = ents.Create("lia_item")
item:SetPos(pos)
item:SetAngles(ang)
âī¸ High Complexity
-- High: Use in item dropping system
local pos, ang = entity:getEntItemDropPos(offset)
local tr = util.TraceLine({
start = pos,
endpos = pos + Vector(0, 0, -50),
mask = MASK_SOLID_BRUSHONLY
})
if tr.Hit then
pos = tr.HitPos + tr.HitNormal * 5
end
local item = ents.Create("lia_item")
item:SetPos(pos)
item:SetAngles(ang)
item:Spawn()
isFemale
đ Purpose
Checks if the entity's model represents a female character
â° When Called
When you need to determine the gender of a character entity
âŠī¸ Returns
- boolean - True if the entity is female, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Check if entity is female
if entity:isFemale() then
print("This is a female character")
end
đ Medium Complexity
-- Medium: Use in character customization
if entity:isFemale() then
entity:SetBodygroup(1, 1) -- Set female bodygroup
else
entity:SetBodygroup(1, 0) -- Set male bodygroup
end
âī¸ High Complexity
-- High: Use in roleplay system
if entity:isFemale() then
local char = entity:getChar()
if char then
char:setData("gender", "female")
char:setData("pronouns", {"she", "her", "hers"})
end
end
isNearEntity
đ Purpose
Checks if the entity is near another entity within a specified radius
â° When Called
When you need to check proximity between entities
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
radius |
number, optional | Search radius in units (default: 96) |
otherEntity |
Entity, optional | Specific entity to check for proximity |
âŠī¸ Returns
- boolean - True if near another entity, false otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Check if entity is near any other entity
if entity:isNearEntity() then
print("Entity is near something")
end
đ Medium Complexity
-- Medium: Check proximity to specific entity
if entity:isNearEntity(150, targetEntity) then
print("Entity is near target")
end
âī¸ High Complexity
-- High: Use in interaction system
if entity:isNearEntity(100, ply) then
if entity:isItem() then
ply:notify("Press E to pick up " .. entity:GetItemData().name)
elseif entity:isMoney() then
ply:notify("Press E to collect $" .. entity:GetAmount())
end
end
getDoorPartner
đ Purpose
Gets the partner door entity for double doors
â° When Called
When you need to find the paired door in a double door setup
âŠī¸ Returns
- Entity or nil - The partner door if found, nil otherwise
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Get door partner
local partner = door:getDoorPartner()
if IsValid(partner) then
print("Found door partner")
end
đ Medium Complexity
-- Medium: Use in door synchronization
local partner = door:getDoorPartner()
if IsValid(partner) then
partner:Fire("Open")
door:Fire("Open")
end
âī¸ High Complexity
-- High: Use in door management system
local partner = door:getDoorPartner()
if IsValid(partner) then
if door:isDoorLocked() then
partner:setLocked(true)
else
partner:setLocked(false)
end
door:setNetVar("partnerID", partner:EntIndex())
end
sendNetVar
đ Purpose
Sends a network variable to clients via network message
â° When Called
When you need to synchronize entity data with clients
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
key |
string | The network variable key to send |
receiver |
Player, optional | Specific player to send to, or nil for all players |
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
âī¸ High Complexity
-- High: Use in data synchronization system
if entity:getNetVar("dirty") then
entity:sendNetVar("data", nil)
entity:setNetVar("dirty", false)
end
clearNetVars
đ Purpose
Clears all network variables for the entity and notifies clients
â° When Called
When you need to remove all network data from an entity
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
receiver |
Player, optional | Specific player to notify, or nil for all players |
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
âī¸ High Complexity
-- High: Use in entity cleanup system
if entity:IsValid() then
entity:clearNetVars()
entity:Remove()
end
removeDoorAccessData
đ Purpose
Removes all door access data and notifies clients to close door menus
â° When Called
When you need to clear all door access permissions and close related UIs
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
âī¸ High Complexity
-- High: Use in door management system
if ply:hasFlags("A") then
door:removeDoorAccessData()
ply:notify("Door access data cleared")
end
setLocked
đ Purpose
Sets the locked state of an entity using network variables
â° When Called
When you need to lock or unlock an entity
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
state |
boolean | True to lock, false to unlock |
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
âī¸ High Complexity
-- High: Use in security system
if ply:hasFlags("A") then
entity:setLocked(not entity:isLocked())
ply:notify("Entity " .. (entity:isLocked() and "locked" or "unlocked"))
end
setKeysNonOwnable
đ Purpose
Sets whether a vehicle can be owned or sold
â° When Called
When you need to make a vehicle non-ownable or ownable
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
state |
boolean | True to make non-ownable, false to make ownable |
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
âī¸ High Complexity
-- High: Use in vehicle management system
if ply:hasFlags("A") then
vehicle:setKeysNonOwnable(true)
ply:notify("Vehicle made non-ownable")
end
isDoor
đ Purpose
Checks if the entity is a door by examining its class name
â° When Called
When you need to determine if an entity is a door
âŠī¸ Returns
- boolean - True if the entity is a door, false otherwise
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in door interaction
if entity:isDoor() and entity:checkDoorAccess(ply) then
entity:Fire("Open")
end
âī¸ High Complexity
-- High: Use in door management system
if entity:isDoor() then
local partner = entity:getDoorPartner()
if IsValid(partner) then
partner:setLocked(entity:isDoorLocked())
end
end
setNetVar
đ Purpose
Sets a network variable for the entity and synchronizes it with clients
â° When Called
When you need to store and sync data on an entity
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
key |
string | The network variable key |
value |
any | The value to store |
receiver |
Player, optional | Specific player to send to, or nil for all players |
âŠī¸ Returns
- None
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
âī¸ High Complexity
-- High: Use in data management system
if entity:getNetVar("dirty") then
entity:setNetVar("lastUpdate", CurTime())
entity:setNetVar("dirty", false)
end
getNetVar
đ Purpose
Gets a network variable from the entity (server-side)
â° When Called
When you need to retrieve synchronized data from an entity on the server
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
key |
string | The network variable key to retrieve |
default |
any, optional | Default value if the key doesn't exist |
âŠī¸ Returns
- any - The network variable value or default
đ Realm
Server
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in server-side logic
local owner = entity:getNetVar("owner")
if owner and IsValid(owner) then
print("Entity owner:", owner:Name())
end
âī¸ High Complexity
-- High: Use in server-side data management
local data = entity:getNetVar("data", {})
if data.lastUpdate and CurTime() - data.lastUpdate > 300 then
entity:setNetVar("data", {lastUpdate = CurTime()})
end
isDoor
đ Purpose
Checks if the entity is a door by examining its class name (client-side)
â° When Called
When you need to determine if an entity is a door on the client
âŠī¸ Returns
- boolean - True if the entity is a door, false otherwise
đ Realm
Client
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in client-side door interaction
if entity:isDoor() and entity:isNearEntity(100, LocalPlayer()) then
draw.DrawText("Press E to open door", "DermaDefault", ScrW()/2, ScrH()/2)
end
âī¸ High Complexity
-- High: Use in client-side door management
if entity:isDoor() then
local locked = entity:getNetVar("locked", false)
local color = locked and Color(255, 0, 0) or Color(0, 255, 0)
draw.DrawText(locked and "Locked" or "Unlocked", "DermaDefault", ScrW()/2, ScrH()/2, color)
end
getNetVar
đ Purpose
Gets a network variable from the entity (client-side)
â° When Called
When you need to retrieve synchronized data from an entity on the client
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
key |
string | The network variable key to retrieve |
default |
any, optional | Default value if the key doesn't exist |
âŠī¸ Returns
- any - The network variable value or default
đ Realm
Client
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Use in client-side logic
local owner = entity:getNetVar("owner")
if owner and owner == LocalPlayer() then
print("You own this entity")
end
âī¸ High Complexity
-- High: Use in client-side rendering
local locked = entity:getNetVar("locked", false)
local color = locked and Color(255, 0, 0) or Color(0, 255, 0)
draw.DrawText(locked and "Locked" or "Unlocked", "DermaDefault", x, y, color)
playFollowingSound
đ Purpose
Plays a sound that follows the entity with 3D positioning and distance attenuation
â° When Called
When you need to play a sound that moves with an entity
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
soundPath |
string | Path to the sound file or URL |
volume |
number, optional | Volume level (0-1, default: 1) |
shouldFollow |
boolean, optional | Whether sound should follow entity (default: true) |
maxDistance |
number, optional | Maximum audible distance (default: 1200) |
startDelay |
number, optional | Delay before playing (default: 0) |
minDistance |
number, optional | Minimum distance for full volume (default: 0) |
pitch |
number, optional | Pitch multiplier (default: 1) |
_ |
any, optional | Unused parameter |
dsp |
number, optional | DSP effect ID (default: 0) |
âŠī¸ Returns
- None
đ Realm
Client
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Play with custom volume and distance
entity:playFollowingSound("buttons/button15.wav", 0.5, true, 500)
âī¸ High Complexity
-- High: Play web sound with full parameters
entity:playFollowingSound("https://example.com/sound.mp3", 0.8, true, 1000, 0.5, 100, 1.2, nil, 1)