Skip to content

Entity

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(soundName, soundLevel, pitchPercent, volume, channel, flags, dsp)

Purpose

Detour of Entity:EmitSound that plays a sound from this entity, handling web sound URLs and fallbacks. This function overrides the base game's EmitSound method to add support for web-sourced audio streams.

When Called

Use whenever an entity needs to emit a sound that may be streamed.

Parameters

string soundName File path or URL to play.

number soundLevel Sound level for attenuation.

number pitchPercent Pitch modifier.

number volume Volume from 0-100.

number channel Optional sound channel.

number flags Optional emit flags.

number dsp Optional DSP effect index.

Returns

boolean True when handled by websound logic; otherwise base emit result.

Example Usage

  ent:EmitSound("lilia/websounds/example.mp3", 75)

isProp()

Purpose

Indicates whether this entity is a physics prop.

When Called

Use when filtering interactions to physical props only.

Returns

boolean True if the entity class is prop_physics.

Example Usage

  if ent:isProp() then handleProp(ent) end

isItem()

Purpose

Checks if the entity represents a Lilia item.

When Called

Use when distinguishing item entities from other entities.

Returns

boolean True if the entity class is lia_item.

Example Usage

  if ent:isItem() then pickUpItem(ent) end

isMoney()

Purpose

Checks if the entity is a Lilia money pile.

When Called

Use when processing currency pickups or interactions.

Returns

boolean True if the entity class is lia_money.

Example Usage

  if ent:isMoney() then ent:Remove() end

isSimfphysCar()

Purpose

Determines whether the entity belongs to supported vehicle classes.

When Called

Use when applying logic specific to Simfphys/LVS vehicles.

Returns

boolean True if the entity is a recognized vehicle type.

Example Usage

  if ent:isSimfphysCar() then configureVehicle(ent) end

checkDoorAccess(client, access)

Purpose

Verifies whether a client has a specific level of access to a door.

When Called

Use when opening menus or performing actions gated by door access.

Parameters

Player client Player requesting access.

number access Required access level, defaults to DOOR_GUEST.

Returns

boolean True if the client meets the access requirement.

Example Usage

  if door:checkDoorAccess(ply, DOOR_OWNER) then openDoor() end

keysOwn(client)

Purpose

Assigns vehicle ownership metadata to a player.

When Called

Use when a player purchases or claims a vehicle entity.

Parameters

Player client Player to set as owner.

Example Usage

  vehicle:keysOwn(ply)

keysLock()

Purpose

Locks a vehicle entity via its Fire interface.

When Called

Use when a player locks their owned vehicle.

Example Usage

  vehicle:keysLock()

keysUnLock()

Purpose

Unlocks a vehicle entity via its Fire interface.

When Called

Use when giving a player access back to their vehicle.

Example Usage

  vehicle:keysUnLock()

getDoorOwner()

Purpose

Retrieves the owning player for a door or vehicle, if any.

When Called

Use when displaying ownership information.

Returns

Player|nil Owner entity or nil if unknown.

Example Usage

  local owner = door:getDoorOwner()

isLocked()

Purpose

Returns whether the entity is flagged as locked through net vars.

When Called

Use when deciding if interactions should be blocked.

Returns

boolean True if the entity's locked net var is set.

Example Usage

  if door:isLocked() then denyUse() end

isDoorLocked()

Purpose

Checks the underlying lock state of a door entity.

When Called

Use when syncing lock visuals or handling use attempts.

Returns

boolean True if the door reports itself as locked.

Example Usage

  local locked = door:isDoorLocked()

isFemale()

Purpose

Infers whether the entity's model is tagged as female.

When Called

Use for gender-specific animations or sounds.

Returns

boolean True if GetModelGender returns "female".

Example Usage

  if ent:isFemale() then setFemaleVoice(ent) end

getDoorPartner()

Purpose

Finds the paired door entity associated with this door.

When Called

Use when syncing double-door behavior or ownership.

Returns

Entity|nil Partner door entity when found.

Example Usage

  local partner = door:getDoorPartner()

sendNetVar(key, receiver)

Purpose

Sends a networked variable for this entity to one or more clients.

When Called

Use immediately after changing lia.net values to sync them.

Parameters

string key Net variable name to send.

Player receiver optional Optional player to send to; broadcasts when nil.

Example Usage

  ent:sendNetVar("locked", ply)

clearNetVars(receiver)

Purpose

Clears all stored net vars for this entity and notifies clients.

When Called

Use when an entity is being removed or reset.

Parameters

Player receiver optional Optional target to notify; broadcasts when nil.

Example Usage

  ent:clearNetVars()

removeDoorAccessData()

Purpose

Resets stored door access data and closes any open menus.

When Called

Use when clearing door permissions or transferring ownership.

Example Usage

  door:removeDoorAccessData()

setLocked(state)

Purpose

Sets the locked net var state for this entity.

When Called

Use when toggling lock status server-side.

Parameters

boolean state Whether the entity should be considered locked.

Example Usage

  door:setLocked(true)

setKeysNonOwnable(state)

Purpose

Marks an entity as non-ownable for keys/door systems.

When Called

Use when preventing selling or owning of a door/vehicle.

Parameters

boolean state True to make the entity non-ownable.

Example Usage

  door:setKeysNonOwnable(true)

setNetVar(key, value, receiver)

Purpose

Stores a networked variable for this entity and notifies listeners.

When Called

Use when updating shared entity state that clients need.

Parameters

string key Net variable name.

any value Value to store and broadcast.

Player receiver optional Optional player to send to; broadcasts when nil.

Example Usage

  ent:setNetVar("color", Color(255, 0, 0))

setLocalVar(key, value)

Purpose

Saves a local (server-only) variable on the entity.

When Called

Use for transient server state that should not be networked.

Parameters

string key Local variable name.

any value Value to store.

Example Usage

  ent:setLocalVar("cooldown", CurTime())

getLocalVar(key, default)

Purpose

Reads a server-side local variable stored on the entity.

When Called

Use when retrieving transient server-only state.

Parameters

string key Local variable name.

any default Value to return if unset.

Returns

any Stored local value or default.

Example Usage

  local cooldown = ent:getLocalVar("cooldown", 0)

playFollowingSound(soundPath, volume, shouldFollow, maxDistance, startDelay, minDistance, pitch, soundLevel, dsp)

Purpose

Plays a web sound locally on the client, optionally following the entity.

When Called

Use when the client must play a streamed sound attached to an entity.

Parameters

string soundPath URL or path to the sound.

number volume Volume from 0-1.

boolean shouldFollow Whether the sound follows the entity.

number maxDistance Maximum audible distance.

number startDelay Delay before playback starts.

number minDistance Minimum distance for attenuation.

number pitch Playback rate multiplier.

number soundLevel Optional sound level for attenuation.

number dsp Optional DSP effect index.

Example Usage

  ent:playFollowingSound(url, 1, true, 1200)

isDoor()

Purpose

Determines whether this entity should be treated as a door.

When Called

Use when applying door-specific logic on an entity.

Returns

boolean True if the entity class matches common door types.

Example Usage

  if ent:isDoor() then handleDoor(ent) end

getNetVar(key, default)

Purpose

Retrieves a networked variable stored on this entity.

When Called

Use when reading shared entity state on either server or client.

Parameters

string key Net variable name.

any default Fallback value if none is set.

Returns

any Stored net var or default.

Example Usage

  local locked = ent:getNetVar("locked", false)