Skip to content

Persistence

This page documents hooks in the persistence category.


CanPersistEntity(entity)View Source

Purpose

Determines whether an entity should remain protected from PermaProps persistence tools when it matches Lilia's built-in persistent entity checks.

Category

Persistence

Realm

Server

Parameters

Entity entity The entity being evaluated for PermaProps persistence.

Returns

boolean|nil Return false to let PermaProps treat the entity as eligible even if it matches the default protected classes. Returning true or nil keeps the normal protection behavior.

Example Usage

  hook.Add("CanPersistEntity", "liaExampleCanPersistEntity", function(entity)
      if IsValid(entity) and entity:GetClass() == "lia_vendor" then
          return true
      end
  end)

GetEntitySaveData(ent)View Source

Purpose

Allows modules to append extra data when a persistent entity is serialized.

Category

Persistence

Realm

Server

Parameters

Entity ent The entity being serialized.

Returns

table|nil Return a table of extra save data to merge into the entity record. Returning nil leaves the save payload unchanged.

Example Usage

  hook.Add("GetEntitySaveData", "liaExampleCoreEntitySaveData", function(ent)
      if IsValid(ent) then return {customClass = ent:GetClass()} end
  end)

LoadData()View Source

Purpose

Runs when persistent gamemode data should be loaded from storage.

Category

Persistence

Realm

Server

Example Usage

  hook.Add("LoadData", "liaExampleCoreLoadData", function()
      print("Loading saved world data")
  end)

OnEntityLoaded(ent, data)View Source

Purpose

Runs after a persistent entity is recreated so modules can restore extra state from the saved data.

Category

Persistence

Realm

Server

Parameters

Entity ent The entity that was loaded.

table data The decoded save data for the entity.

Example Usage

  hook.Add("OnEntityLoaded", "liaExampleCoreEntityLoaded", function(ent, data)
      if IsValid(ent) and data.customClass then print(data.customClass) end
  end)

OnEntityPersisted(ent, entData)View Source

Purpose

Runs after a persistent entity snapshot has been written into the persistence data set.

Category

Persistence

Realm

Server

Parameters

Entity ent The entity that was saved.

table entData The serialized persistence payload stored for the entity.

Example Usage

  hook.Add("OnEntityPersisted", "liaExampleOnEntityPersisted", function(ent, entData)
      print("[Persistence] Saved", entData.class)
  end)

OnEntityPersistUpdated(ent, data)View Source

Purpose

Runs after an existing persistent entity entry has been updated in the saved persistence data.

Category

Persistence

Realm

Server

Parameters

Entity ent The entity whose saved record was updated.

table data The updated persistence data entry.

Example Usage

  hook.Add("OnEntityPersistUpdated", "liaExampleOnEntityPersistUpdated", function(ent, data)
      print("[Persistence] Updated", data.class)
  end)

OnSavedItemLoaded(loadedItems)View Source

Purpose

Runs after saved world items have been restored from database rows.

Category

Persistence

Realm

Server

Parameters

table loadedItems An array containing the restored item instances.

Example Usage

  hook.Add("OnSavedItemLoaded", "liaExampleOnSavedItemLoaded", function(loadedItems)
      print("[Persistence] Restored items:", #loadedItems)
  end)

PostLoadData()View Source

Purpose

Runs after persistent gamemode data finishes loading so modules can perform post-load setup.

Category

Persistence

Realm

Server

Example Usage

  hook.Add("PostLoadData", "liaExampleCorePostLoadData", function()
      print("Finished loading saved world data")
  end)

ShouldDataBeSaved()View Source

Purpose

Determines whether the server shutdown routine should save Lilia data, config, characters, and admin state.

Category

Persistence

Realm

Server

Returns

boolean|nil Return false to skip the shutdown save routine. Returning nil allows the default behavior to continue.

Example Usage

  hook.Add("ShouldDataBeSaved", "liaExampleShouldDataBeSaved", function()
      if lia.shuttingDown then
          return true
      end
  end)

ShouldDeleteSavedItems()View Source

Purpose

Determines whether saved world items should be deleted from storage instead of being respawned during data loading.

Category

Persistence

Realm

Server

Returns

boolean|nil Return true to delete the saved item records instead of restoring them. Returning nil or false allows normal item restoration.

Example Usage

  hook.Add("ShouldDeleteSavedItems", "liaExampleShouldDeleteSavedItems", function()
      return false
  end)

ShouldEntityLoad(entityData)View Source

Purpose

Determines whether a persisted entity entry should be restored during data loading.

Category

Persistence

Realm

Server

Parameters

table entityData The saved persistence row containing class, position, angles, model, and optional custom data.

Returns

boolean|nil Return false to skip restoring that saved entity. Returning nil allows the default behavior to continue.

Example Usage

  hook.Add("ShouldEntityLoad", "liaExampleShouldEntityLoad", function(entityData)
      if entityData.class == "prop_ragdoll" then
          return false
      end
  end)

ShouldEntitySave(entity)View Source

Purpose

Determines whether a persistent entity should be included in Lilia's persistence save, create, and update routines.

Category

Persistence

Realm

Server

Parameters

Entity entity The live entity being evaluated for persistence.

Returns

boolean|nil Return false to exclude the entity from persistence. Returning nil allows the default behavior to continue.

Example Usage

  hook.Add("ShouldEntitySave", "liaExampleShouldEntitySave", function(entity)
      if entity:GetClass() == "prop_ragdoll" then
          return false
      end
  end)

ShouldSaveItem(itemTable, itemEntity)View Source

Purpose

Determines whether a dropped item entity should be written to the saved world-item table.

Category

Persistence

Realm

Server

Parameters

Item itemTable The item instance being considered for persistence.

Entity itemEntity The world entity representing the item.

Returns

boolean|nil Return false to skip saving the dropped item. Returning nil allows the default persistence behavior to continue.

Example Usage

  hook.Add("ShouldSaveItem", "liaExampleShouldSaveItem", function(itemTable, itemEntity)
      if itemTable.temp then
          return false
      end
  end)

UpdateEntityPersistence(entity)View Source

Purpose

Runs when a persistent entity should refresh its saved position, model, angles, and custom persistence data.

Category

Persistence

Realm

Server

Parameters

Entity entity The live persistent entity whose saved record should be updated.

Example Usage

  hook.Add("UpdateEntityPersistence", "liaExampleUpdateEntityPersistence", function(entity)
      if entity.IsPersistent then
          print("Refreshing persistence for", entity:GetClass())
      end
  end)