Skip to content

Doors

Door management system for the Lilia framework providing preset configuration,


Overview

The doors library provides comprehensive door management functionality including preset configuration, database schema verification, and data cleanup operations. It handles door data persistence, loading door configurations from presets, and maintaining database integrity. The library manages door ownership, access permissions, faction and class restrictions, and provides utilities for door data validation and corruption cleanup. It operates primarily on the server side and integrates with the database system to persist door configurations across server restarts. The library also handles door locking/unlocking mechanics and provides hooks for custom door behavior integration.

lia.doors.getDoorDefaultValues()

Purpose

Retrieve door default values merged with any extra fields provided by modules.

When Called

Anywhere door defaults are needed (initialization, schema checks, load/save).

Returns

table defaults Map of field -> default value including extra fields. table extras Map of extra field definitions collected via the CollectDoorDataFields hook.


lia.doors.setCachedData(door, data)

Purpose

Store door data overrides in memory and sync to clients, omitting defaults.

When Called

After editing door settings (price, access, flags) server-side.

Parameters

Entity door Door entity.

table data Door data overrides.

Example Usage

  lia.doors.setCachedData(door, {
      name = "Police HQ",
      price = 0,
      factions = {FACTION_POLICE}
  })

lia.doors.getCachedData(door)

Purpose

Retrieve cached door data merged with defaults.

When Called

Before saving/loading or when building UI state for a door.

Parameters

Entity door

Returns

table Complete door data with defaults filled.

Example Usage

  local data = lia.doors.getCachedData(door)
  print("Door price:", data.price)

lia.doors.syncDoorData(door)

Purpose

Net-sync a single door's cached data to all clients.

When Called

After updating a door's data.

Parameters

Entity door

Example Usage

  lia.doors.syncDoorData(door)

lia.doors.syncAllDoorsToClient(client)

Purpose

Bulk-sync all cached doors to a single client.

When Called

On player spawn/join or after admin refresh.

Parameters

Player client

Example Usage

  hook.Add("PlayerInitialSpawn", "SyncDoorsOnJoin", function(ply)
      lia.doors.syncAllDoorsToClient(ply)
  end)

lia.doors.setData(door, data)

Purpose

Set data for a door (alias to setCachedData).

When Called

Convenience wrapper used by other systems.

Parameters

Entity door

table data

Example Usage

  lia.doors.setData(door, {locked = true})

lia.doors.addPreset(mapName, presetData)

Purpose

Register a preset of door data for a specific map.

When Called

During map setup to predefine door ownership/prices.

Parameters

string mapName

table presetData

Example Usage

  lia.doors.addPreset("rp_downtown", {
      [1234] = {name = "Bank", price = 0, factions = {FACTION_POLICE}},
      [5678] = {locked = true, hidden = true}
  })

lia.doors.getPreset(mapName)

Purpose

Retrieve a door preset table for a map.

When Called

During map load or admin inspection of presets.

Parameters

string mapName

Returns

Example Usage

  local preset = lia.doors.getPreset(game.GetMap())
  if preset then PrintTable(preset) end

lia.doors.verifyDatabaseSchema()

Purpose

Validate the doors database schema against expected columns.

When Called

On startup or after migrations to detect missing/mismatched columns.

Example Usage

  hook.Add("DatabaseConnected", "VerifyDoorSchema", lia.doors.verifyDatabaseSchema)

lia.doors.cleanupCorruptedData()

Purpose

Detect and repair corrupted faction/class door data in the database.

When Called

Maintenance task to clean malformed data entries.

Example Usage

  concommand.Add("lia_fix_doors", function(admin)
      if not IsValid(admin) or not admin:IsAdmin() then return end
      lia.doors.cleanupCorruptedData()
  end)

lia.doors.getData(door)

Purpose

Access cached door data (server/client wrapper).

When Called

Anywhere door data is needed without hitting DB.

Parameters

Entity door

Returns

Example Usage

  local data = lia.doors.getData(ent)
  if data.locked then
      -- show locked icon
  end

lia.doors.getCachedData(door)

Purpose

Client helper to build full door data from cached entries.

When Called

For HUD/tooltips when interacting with doors.

Parameters

Entity door

Returns

Example Usage

  local info = lia.doors.getCachedData(door)
  draw.SimpleText(info.name or "Door", "LiliaFont.18", x, y, color_white)

lia.doors.updateCachedData(doorID, data)

Purpose

Update the client-side cache for a door ID (or clear it).

When Called

After receiving sync updates from the server.

Parameters

number doorID

table data optional nil clears the cache entry.

Example Usage

  lia.doors.updateCachedData(doorID, net.ReadTable())