Entity is the base for all Classes, and all those entities share the same Methods and Events described in this page.
This is the base class for all Entities we have. You cannot spawn it directly.
Static Functions
The following functions are accessed statically using the specific class with a dot. Example: Character.GetAll()
.
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)
Type | Parameter | Default | Description |
---|
integer | index | | The 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)
Type | Parameter | Default | Description |
---|
string | name | | The name of the new Class |
table or nil | custom_values | | An 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?)
Type | Parameter | Default | Description |
---|
boolean | recursively? | false | Returns 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)
Type | Parameter | Default | Description |
---|
table | class | | The 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)
Type | Parameter | Default | Description |
---|
string | event_name | | Name of the event to subscribe to |
function | callback | | Function 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)
Type | Parameter | Default | Description |
---|
string | event_name | | Name of the event to subscribe to |
function | callback | | Function 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?)
Type | Parameter | Default | Description |
---|
string | event_name | | Name of the event to unsubscribe from |
function | callback? | nil | Optional callback to unsubscribe |
Functions
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)
Type | Parameter | Default | Description |
---|
table | class | | The 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)
Type | Parameter | Default | Description |
---|
string | event_name | | Name of the event to subscribe to |
function | callback | | Function 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)
Type | Parameter | Default | Description |
---|
string | event_name | | Name of the event to subscribe to |
function | callback | | Function 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?)
Type | Parameter | Default | Description |
---|
string | event_name | | Name of the event to unsubscribe from |
function | callback? | nil | Optional 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?)
Type | Parameter | Default | Description |
---|
string | key | | |
any | value | | |
boolean | sync_on_clients? | false | Server 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)
Type | Parameter | Default | Description |
---|
string | key | | |
any | fallback | | Fallback value if key doesn't exist |
Destroy
Destroys this Entity
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...?)
Type | Parameter | Default | Description |
---|
string | event_name | | The Event Name to trigger the event |
Player | player | | The remote player to send this event |
any | args...? | nil | Arguments to pass to the event |
CallRemoteEvent
Calls a custom remote event directly on this entity
my_entity:CallRemoteEvent(event_name, args...?)
Type | Parameter | Default | Description |
---|
string | event_name | | The Event Name to trigger the event |
any | args...? | nil | Arguments to pass to the event |
BroadcastRemoteEvent
Calls a custom remote event directly on this entity to all Players
my_entity:BroadcastRemoteEvent(event_name, args...?)
Type | Parameter | Default | Description |
---|
string | event_name | | The Event Name to trigger the event |
any | args...? | nil | Arguments to pass to the event |
Events
Spawn
Triggered when an Entity is spawned/created
Entity.Subscribe("Spawn", function(self)
end)
Type | Argument | Description |
---|
Base Entity | self | The Entity that was spawned |
Destroy
Triggered when an Entity is destroyed
Entity.Subscribe("Destroy", function(self)
end)
Type | Argument | Description |
---|
Base Entity | self | The Entity which that was destroyed |
ValueChange
Triggered when an Entity has a value changed with :SetValue()
Entity.Subscribe("ValueChange", function(self, key, value)
end)
Type | Argument | Description |
---|
Base Entity | self | The Entity that just had a value changed |
string | key | The key used |
any | value | The value that was set |
ClassRegister
Triggered when a new Class is registered with the Inheriting System
Entity.Subscribe("ClassRegister", function(class)
end)
Type | Argument | Description |
---|
table | class | The inherited Class |