Skip to content

Class

scripts/vscripts/alyxlib/class.lua

Global variables

Name Value
EntityClassNameMap table
READY_NORMAL 0
READY_GAME_LOAD 2
READY_TRANSITION 3

Methods

Set

This method is deprecated.

Assigns a new value to entity's field name. This also saves the field.

EntityClass:Set(name, value)

Parameters

  • name
    string
    Name of the field
  • value
    any
    Value to assign

Save

Manually saves a given entity field.

If no value is provided, the value of the field with the same name will be saved. If no name is provided, all fields will be saved.

EntityClass:Save(name, value)

Parameters

  • name (optional)
    string
    Name of the field to save
  • value (optional)
    any
    Value to save

Think

EntityClass:Think()

ResumeThink

Resumes the entity think function.

EntityClass:ResumeThink()

PauseThink

Pauses the entity think function.

EntityClass:PauseThink()

Output

Defines a function to redirected to IO output on spawn.

EntityClass:Output(output, func)

Parameters

  • output
    string
  • func
    function

GameEvent

Defines a function for listening to a game event.

EntityClass:GameEvent(gameEvent, func)

Parameters

  • gameEvent
    GameEventsAll
  • func
    function

PlayerEvent

Defines a function for listening to a player event.

EntityClass:PlayerEvent(playerEvent, func)

Parameters

  • playerEvent
    PLAYER_EVENTS_ALL
  • func
    function

Functions

inherit

Inherits an existing entity class which was defined using the entity function.

If no entity is provided, the entity calling the code will inherit the class. If no calling entity is found, an error will be thrown.

inherit(script, entity)

Parameters

  • script
    T
    The class/script to inherit
  • entity (optional)
    EntityHandle
    Entity which will inherit the class

Returns

  • T

Inherited class

  • T

self instance of entity, the entity inheriting script

entity

Creates a new entity class.

If this is called in an entity attached script then the entity automatically inherits the class and the class inherits the entity's metatable.

The class is only created once so this can be called in entity attached scripts multiple times and all subsequent calls will return the already created class.

entity(name)

Parameters

  • name (optional)
    T
    Internal class name

Returns

  • any

The newly created class

  • T

self instance of entity inheriting the class, if called in an attached script

  • table

The first inherited class, if any

  • table

Private members table of the class (unused)

printinherits

Prints all classes that ent inherits.

printinherits(ent, nest)

Parameters

  • ent
    EntityClass
  • nest (optional)
    string

getvalvemeta

Gets the original metatable that Valve assigns to the entity.

getvalvemeta(ent)

Parameters

  • ent
    EntityClass
    The entity search

Returns - table? Metatable originally assigned to ent

getinherits

Gets a list of all classes that class inherits.

Does not include the Valve class - use getvalvemeta for that.

getinherits(class)

Parameters

  • class
    EntityClass
    The entity or class to search

Returns - EntityClass[] List of class tables

isinstance

Checks if an entity inherits a given EntityClass.

isinstance(ent, class)

Parameters

  • ent
    EntityClass, EntityHandle
    Entity to check
  • class
    string, table
    Name or class table to check

Returns - boolean true if ent inherits class, false otherwise

IsClassEntity

Checks if an entity is using the AlyxLib class system.

IsClassEntity(ent)

Parameters

  • ent
    EntityHandle
    Entity to check

Returns - boolean true if ent is a class entity, false otherwise

Types

EntityClass

Inherits from: CBaseEntity, CEntityInstance, CBaseModelEntity, CBasePlayer, CHL2_Player, CBaseAnimating, CBaseFlex, CBaseCombatCharacter, CAI_BaseNPC, CBaseTrigger, CEnvEntityMaker, CInfoWorldLayer, CLogicRelay, CMarkupVolumeTagged, CEnvProjectedTexture, CPhysicsProp, CSceneEntity, CPointClientUIWorldPanel, CPointTemplate, CPointWorldText, CPropHMDAvatar, CPropVRHand

The top-level entity class that provides base functionality.

Field Type Description
__inherits table Table of inherited classes
__name string Name of the class
__outputs table<string, function> # Map of output names to functions that will be connected on spawn
__game_events table<string, function> # Map of game events to functions that will be listened to on spawn
__player_events table<string, function> # Map of player events to functions that will be listened to on spawn
__rawget function Custom rawget function to get a value from meta.__values without checking inherits
Initiated boolean If the class entity has been activated
IsThinking boolean If the entity is currently thinking with Think function
OnActivate function Called automatically on Activate if defined
OnReady function Called automatically after Activate, if defined, when EasyConvars and Player are initialized
OnSpawn function Called automatically on Spawn if defined
UpdateOnRemove function Called before the entity is killed
OnBreak function Called when a breakable entity is broken
OnTakeDamage function Called when entity takes damage
Precache function Called before Spawn for precaching
Think function Entity think function.

Aliases

OnReadyType

Value Description
READY_NORMAL
READY_GAME_LOAD
READY_TRANSITION