Skip to main content
Version: latest - a1.37.x โš–๏ธ

Base Entity

Entity is the base for all Classes, and all those entities share the same Methods and Events described in this page.

info

This is the base class for all Entities we have. You cannot spawn it directly.

๐Ÿ—ฟย Static Functionsโ€‹

tip

The following functions are accessed statically using the specific class with a dot. Example: Character.GetAll().

ReturnsNameDescription
table of Base EntityGetAllReturns a table containing all Entities of the class this is called on
Base EntityGetByIndexReturns a specific Entity of this class at an index
integerGetCountReturns how many Entities of this class exist
iteratorGetPairsReturns an iterator with all Entities of this class to be used with pairs()
tableInheritInherits this class with the Inheriting System
table of tableGetInheritedClassesGets a list of all directly inherited classes from this Class created with the Inheriting System
table or nilGetParentClassGets the parent class if this Class was created with the Inheriting System
booleanIsChildOfGets if this Class is child of another class if this Class was created with the Inheriting System
functionSubscribeSubscribes to an Event for all entities of this Class
functionSubscribeRemoteSubscribes to a custom event called from server
UnsubscribeUnsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed

GetAllโ€‹

Returns a table containing all Entities of the class this is called on

โ€” Returns table of Base Entity (Copy of table containing all Entities).

local ret = Entity.GetAll()

GetByIndexโ€‹

Returns a specific Entity of this class at an index

โ€” Returns Base Entity (Entity at index).

local ret = Entity.GetByIndex(index)
TypeParameterDefaultDescription
integerindexThe index of the Entity

GetCountโ€‹

Returns how many Entities of this class exist

โ€” Returns integer (Number of Entities of this class).

local ret = Entity.GetCount()

GetPairsโ€‹

Returns an iterator with all Entities of this class to be used with pairs(). This is a more performant method than GetAll(), as it will return the iterator to access the Entities directly instead of creating and returning a copy of the Entities table.

Note: Destroying Entities from inside a GetPairs() loop will cause the iterable to change size during the process. If you want to loop-and-destroy, please use GetAll().

โ€” Returns iterator (Iterator with all Entities of this class).

local ret = Entity.GetPairs()

Inheritโ€‹

Inherits this class with the Inheriting System

โ€” Returns table (The new Class table).

local ret = Entity.Inherit(name, custom_values)
TypeParameterDefaultDescription
stringnameThe name of the new Class
table or nilcustom_valuesAn optional table with custom values to be set in the inherited class table

GetInheritedClassesโ€‹

Gets a list of all directly inherited classes from this Class created with the Inheriting System

โ€” Returns table of table (All children Classes).

local ret = Entity.GetInheritedClasses(recursively?)
TypeParameterDefaultDescription
booleanrecursively?falseReturns all inherited children

GetParentClassโ€‹

Gets the parent class if this Class was created with the Inheriting System

โ€” Returns table or nil (The parent class).

local ret = Entity.GetParentClass()

IsChildOfโ€‹

Gets if this Class is child of another class if this Class was created with the Inheriting System

โ€” Returns boolean.

local ret = Entity.IsChildOf(class)
TypeParameterDefaultDescription
tableclassThe other class to check

Subscribeโ€‹

Subscribes to an Event for all entities of this Class

โ€” Returns function (Callback that was passed (useful for unsubscribing later if your callback is an anonymous function)).

local ret = Entity.Subscribe(event_name, callback)
TypeParameterDefaultDescription
stringevent_nameName of the event to subscribe to
functioncallbackFunction to call when the event is triggered

SubscribeRemoteโ€‹

Subscribes to a custom event called from server

โ€” Returns function (Callback that was passed (useful for unsubscribing later if your callback is an anonymous function)).

local ret = Entity.SubscribeRemote(event_name, callback)
TypeParameterDefaultDescription
stringevent_nameName of the event to subscribe to
functioncallbackFunction to call when the event is triggered

Unsubscribeโ€‹

Unsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed

Entity.Unsubscribe(event_name, callback?)
TypeParameterDefaultDescription
stringevent_nameName of the event to unsubscribe from
functioncallback?nilOptional callback to unsubscribe

๐Ÿฆ ย Functionsโ€‹

ReturnsNameDescription
integerGetIDGets the universal network ID of this Entity (same on both client and server)
tableGetClassGets the class of this entity
booleanIsARecursively checks if this entity is inherited from a Class
functionSubscribeSubscribes to an Event on this specific entity
functionSubscribeRemoteSubscribes to a custom event called from server on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
SetValueSets a Value in this Entity
anyGetValueGets a Value stored on this Entity at the given key
DestroyDestroys this Entity
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players

GetIDโ€‹

Gets the universal network ID of this Entity (same on both client and server)

โ€” Returns integer.

local ret = my_entity:GetID()

GetClassโ€‹

Gets the class of this entity

โ€” Returns table.

local ret = my_entity:GetClass()

IsAโ€‹

Recursively checks if this entity is inherited from a Class

โ€” Returns boolean.

local ret = my_entity:IsA(class)
TypeParameterDefaultDescription
tableclassThe Class

Subscribeโ€‹

Subscribes to an Event on this specific entity

โ€” Returns function (Callback that was passed (useful for unsubscribing later if your callback is an anonymous function)).

local ret = my_entity:Subscribe(event_name, callback)
TypeParameterDefaultDescription
stringevent_nameName of the event to subscribe to
functioncallbackFunction to call when the event is triggered

SubscribeRemoteโ€‹

Subscribes to a custom event called from server on this specific entity

โ€” Returns function (Callback that was passed (useful for unsubscribing later if your callback is an anonymous function)).

local ret = my_entity:SubscribeRemote(event_name, callback)
TypeParameterDefaultDescription
stringevent_nameName of the event to subscribe to
functioncallbackFunction to call when the event is triggered

Unsubscribeโ€‹

Unsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed

my_entity:Unsubscribe(event_name, callback?)
TypeParameterDefaultDescription
stringevent_nameName of the event to unsubscribe from
functioncallback?nilOptional callback to unsubscribe

SetValueโ€‹

Sets a value in this Entity, which can be accessed by any package (optionally sync on clients if called from server)

Please refer to Entity Values for more information

my_entity:SetValue(key, value, sync_on_clients?)
TypeParameterDefaultDescription
stringkey
anyvalue
booleansync_on_clients?falseServer side parameter, if enabled will sync this value with all clients

GetValueโ€‹

Gets a Value stored on this Entity at the given key. Please refer to Entity Values for more information

โ€” Returns any (Value at key or fallback if key doesn't exist).

local ret = my_entity:GetValue(key, fallback)
TypeParameterDefaultDescription
stringkey
anyfallbackFallback value if key doesn't exist

Destroyโ€‹

Destroys this Entity

my_entity:Destroy()

IsValidโ€‹

Returns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)

โ€” Returns boolean.

local ret = my_entity:IsValid()

CallRemoteEventโ€‹

Calls a custom remote event directly on this entity to a specific Player

my_entity:CallRemoteEvent(event_name, player, args...?)
TypeParameterDefaultDescription
stringevent_nameThe Event Name to trigger the event
PlayerplayerThe remote player to send this event
anyargs...?nilArguments to pass to the event

CallRemoteEventโ€‹

Calls a custom remote event directly on this entity

my_entity:CallRemoteEvent(event_name, args...?)
TypeParameterDefaultDescription
stringevent_nameThe Event Name to trigger the event
anyargs...?nilArguments to pass to the event

BroadcastRemoteEventโ€‹

Calls a custom remote event directly on this entity to all Players

my_entity:BroadcastRemoteEvent(event_name, args...?)
TypeParameterDefaultDescription
stringevent_nameThe Event Name to trigger the event
anyargs...?nilArguments to pass to the event

๐Ÿš€ย Eventsโ€‹

NameDescription
SpawnTriggered when an Entity is spawned/created
DestroyTriggered when an Entity is destroyed
ValueChangeTriggered when an Entity has a value changed with :SetValue()
ClassRegisterTriggered when a new Class is registered with the Inheriting System

Spawnโ€‹

Triggered when an Entity is spawned/created
Entity.Subscribe("Spawn", function(self)

end)
TypeArgumentDescription
Base EntityselfThe Entity that was spawned

Destroyโ€‹

Triggered when an Entity is destroyed
Entity.Subscribe("Destroy", function(self)

end)
TypeArgumentDescription
Base EntityselfThe Entity which that was destroyed

ValueChangeโ€‹

Triggered when an Entity has a value changed with :SetValue()
Entity.Subscribe("ValueChange", function(self, key, value)

end)
TypeArgumentDescription
Base EntityselfThe Entity that just had a value changed
stringkeyThe key used
anyvalueThe value that was set

ClassRegisterโ€‹

Triggered when a new Class is registered with the Inheriting System
Entity.Subscribe("ClassRegister", function(class)

end)
TypeArgumentDescription
tableclassThe inherited Class