基础实体
Entity 是所有类的基础母版,所有这些实体都共享本页面中所描述的方法和事件。
👪Base Class
This is a Base Class. Base Classes are abstract definitions used to share common methods and events between related child classes, thus you cannot spawn it directly.
Classes that share methods and events from this Base Class: Billboard, Blueprint, Cable, Character, CharacterSimple, Decal, Gizmo, Grenade, InstancedStaticMesh, Light, Melee, Particle, Player, Prop, SceneCapture, StaticMesh, Sound, TextRender, Text3D, Trigger, VehicleWheeled, VehicleWater, Weapon, WebUI, Widget, Widget3D.
Classes that share methods and events from this Base Class: Billboard, Blueprint, Cable, Character, CharacterSimple, Decal, Gizmo, Grenade, InstancedStaticMesh, Light, Melee, Particle, Player, Prop, SceneCapture, StaticMesh, Sound, TextRender, Text3D, Trigger, VehicleWheeled, VehicleWater, Weapon, WebUI, Widget, Widget3D.
🧑💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
🗿 静态函数
提示
The following functions are accessed statically using the specific class with a dot. 示例:Character.GetAll()。
| Returns | Name | Description | |
|---|---|---|---|
| table of Base Entity | GetAll | 返回一个包含调用此方法的类中所有实体的表 | |
| Base Entity | GetByIndex | 返回该类中指定索引处的特定实体 | |
| integer | GetCount | 返回该类当前存在的实体数量 | |
| table of table | GetInheritedClasses | 获取使用 继承系统 创建的、直接继承自该类的所有子类列表 | |
| iterator | GetPairs | 返回一个包含该类所有实体的迭代器,用于 pairs() 循环 | |
| table or nil | GetParentClass | 如果该类是使用 继承系统 创建的,则获取其父类 | |
| table | Inherit | 使用 继承系统 继承此类 | |
| boolean | IsChildOf | 如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类 | |
| function | Subscribe | 为该类的所有实体订阅一个 事件 | |
| function | SubscribeRemote | 订阅从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调 |

GetAll
返回一个包含调用此方法的类中所有实体的表
local ret = Entity.GetAll()
Returns
| Type | Description |
|---|---|
| table of Base Entity | 包含所有实体的表副本 |

GetByIndex
返回该类中指定索引处的特定实体
local ret = Entity.GetByIndex(index)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | index | Required parameter | 实体的索引 |
Returns
| Type | Description |
|---|---|
| Base Entity | 该索引处的实体 |

GetCount
返回该类当前存在的实体数量
local ret = Entity.GetCount()
Returns
| Type | Description |
|---|---|
| integer | 该类的实体数量 |

GetInheritedClasses
获取使用 继承系统 创建的、直接继承自该类的所有子类列表
local ret = Entity.GetInheritedClasses(recursively?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | recursively? | false | 是否返回所有层级的继承子类 |

GetPairs
返回一个包含该类所有实体的迭代器,用于pairs()循环。这是一个比GetAll()性能更高的方法,因为它直接返回访问实体的迭代器,而不是创建并返回实体表副本。
注: 在GetPairs()循环内部销毁实体会导致可迭代对象在执行过程中改变大小。如果你需要进行循环并销毁操作,请使用GetAll()。
local ret = Entity.GetPairs()
Returns
| Type | Description |
|---|---|
| iterator | 包含该类所有实体的迭代器 |

GetParentClass
如果该类是使用 继承系统 创建的,则获取其父类
local ret = Entity.GetParentClass()

Inherit
使用 继承系统 继承此类
local class = Entity.Inherit(name, custom_values?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | name | Required parameter | 新类的名称 |
| table | custom_values? | {} | 一个可选的表,包含要在继承的类表中设置的自定义值 |
Returns
| Type | Description |
|---|---|
| table | 新类的表 |

IsChildOf
如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类
local ret = Entity.IsChildOf(class)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| table | class | Required parameter | 要检查的另一个类 |
Returns
| Type | Description |
|---|---|
| boolean | No description provided |

Subscribe
为该类的所有实体订阅一个 事件
local ret = Entity.Subscribe(event_name, callback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 要订阅的事件名称 |
| function | callback | Required parameter | 触发事件时要调用的函数 |
Returns
| Type | Description |
|---|---|
| function | 传进来的回调函数(如果你的回调是匿名函数,这对于以后退订很有用) |

SubscribeRemote
订阅从服务器调用的自定义远程事件
local ret = Entity.SubscribeRemote(event_name, callback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 要订阅的事件名称 |
| function | callback | Required parameter | 触发事件时要调用的函数 |
Returns
| Type | Description |
|---|---|
| function | 传进来的回调函数(如果你的回调是匿名函数,这对于以后退订很有用) |

Unsubscribe
退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调
Entity.Unsubscribe(event_name, callback?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 要退订的事件名称 |
| function | callback? | nil | 可选,要退订的特定回调函数 |
🦠 函数
| Returns | Name | Description | |
|---|---|---|---|
BroadcastRemoteEvent | 直接在此实体上向所有玩家调用自定义远程事件 | ||
BroadcastRemoteInRadiusEvent | 直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家 | ||
CallRemoteEvent | 直接在此实体上向特定玩家调用自定义远程事件 | ||
CallRemoteEvent | 直接在此实体上调用自定义远程事件 | ||
CallRemotePlayersEvent | 直接在此实体上调用自定义远程事件,并将事件传递给玩家列表 | ||
Destroy | 销毁该实体 | ||
FinishSpawn | 完成生成过程,如果实体是通过 defer_spawn 生成的,则将实体发送给客户端 | ||
| table of string | GetAllValuesKeys | 获取所有值键的列表 | |
| table | GetClass | 获取该实体的类 | |
| integer | GetID | 获取该实体的全网通用网络 ID(在客户端和服务器上相同) | |
| any | GetValue | 获取此实体上存储在给定键处的 值 | |
| boolean | HasAuthority | 获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false) | |
| boolean | IsA | 递归检查此实体是否继承自某个类 | |
| boolean | IsBeingDestroyed | 如果该实体正在被销毁,则返回 true | |
| boolean | IsValid | 如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true | |
SetValue | 在此实体中设置一个值 | ||
| function | Subscribe | 在这个特定实体上订阅一个事件 | |
| function | SubscribeRemote | 在这个特定实体上订阅一个从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调 |

BroadcastRemoteEvent
直接在此实体上向所有玩家调用自定义远程事件
🆕Updated Function
This method was recently updated in ver. 1.139. See the Compatibility Versions page for more information.
my_entity:BroadcastRemoteEvent(event_name, reliability?, args...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 用于触发事件的事件名称 |
| Reliability | reliability? | Reliability.Reliable | 网络可靠性规则 |
| any | args...? | nil | 传递给事件的参数 |

BroadcastRemoteInRadiusEvent
直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家
my_entity:BroadcastRemoteInRadiusEvent(event_name, radius, reliability?, args...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 用于触发事件的事件名称 |
| float | radius | Required parameter | 发送此事件的半径 |
| Reliability | reliability? | Reliability.Reliable | 网络可靠性规则 |
| any | args...? | nil | 传递给事件的参数 |

CallRemoteEvent
直接在此实体上向特定玩家调用自定义远程事件
🆕Updated Function
This method was recently updated in ver. 1.139. See the Compatibility Versions page for more information.
my_entity:CallRemoteEvent(event_name, player, reliability?, args...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 用于触发事件的事件名称 |
| Player | player | Required parameter | 接收此事件的远程玩家 |
| Reliability | reliability? | Reliability.Reliable | 网络可靠性规则 |
| any | args...? | nil | 传递给事件的参数 |

CallRemoteEvent
直接在此实体上调用自定义远程事件
🆕Updated Function
This method was recently updated in ver. 1.139. See the Compatibility Versions page for more information.
my_entity:CallRemoteEvent(event_name, reliability?, args...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 用于触发事件的事件名称 |
| Reliability | reliability? | Reliability.Reliable | 网络可靠性规则 |
| any | args...? | nil | 传递给事件的参数 |

CallRemotePlayersEvent
直接在此实体上调用自定义远程事件,并将事件传递给玩家列表
my_entity:CallRemotePlayersEvent(event_name, players, reliability?, args...?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 用于触发事件的事件名称 |
| table of Player | players | Required parameter | 发送该事件的目标远程玩家列表 |
| Reliability | reliability? | Reliability.Reliable | 网络可靠性规则 |
| any | args...? | nil | 传递给事件的参数 |

Destroy
销毁该实体
my_entity:Destroy()

FinishSpawn
如果实体是通过 defer_spawn 生成的,则完成生成过程并将实体发送给客户端。在配置实体以实现高效生成后调用此方法my_entity:FinishSpawn()

GetAllValuesKeys
获取所有值键的列表
local ret = my_entity:GetAllValuesKeys()

GetClass
获取该实体的类
local class = my_entity:GetClass()
Returns
| Type | Description |
|---|---|
| table | class |

GetID
获取该实体的全网通用网络 ID(在客户端和服务器上相同)
local id = my_entity:GetID()
Returns
| Type | Description |
|---|---|
| integer | id |

GetValue
获取此实体上存储在给定键处的值。请参考 实体值 获取更多信息
local value = my_entity:GetValue(key, fallback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | key | Required parameter | No description provided |
| any | fallback | Required parameter | 如果键不存在时的备用值 |
Returns
| Type | Description |
|---|---|
| any | 键对应的值,若键不存在则返回备用值 |
See also GetAllValuesKeys, SetValue.

HasAuthority
获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false)
local ret = my_entity:HasAuthority()
Returns
| Type | Description |
|---|---|
| boolean | 如果由客户端生成则为 true,由服务器生成则为 false |

IsA
递归检查此实体是否继承自某个类
local ret = my_entity:IsA(class)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| table | class | Required parameter | 类 |
Returns
| Type | Description |
|---|---|
| boolean | No description provided |

IsBeingDestroyed
如果该实体正在被销毁,则返回 true。
你可以在诸如Drop的事件中检查此状态,以判断一个可拾取物是否是因为即将被销毁而被丢弃
local ret = my_entity:IsBeingDestroyed()
Returns
| Type | Description |
|---|---|
| boolean | No description provided |

IsValid
如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true
local is_valid = my_entity:IsValid()
Returns
| Type | Description |
|---|---|
| boolean | is_valid |

SetValue
在此实体中设置一个值,该值可以被任何包访问(如果是从服务器调用,则可以跨客户端选择性同步)
请参考实体值进一步了解
my_entity:SetValue(key, value, sync_on_clients?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | key | Required parameter | No description provided |
| any | value | Required parameter | No description provided |
| boolean | sync_on_clients? | false | 服务器端参数,如果启用,将此值与所有客户端同步 |
See also GetAllValuesKeys, GetValue.

Subscribe
在这个特定实体上订阅一个事件
local ret = my_entity:Subscribe(event_name, callback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 要订阅的事件名称 |
| function | callback | Required parameter | 触发事件时要调用的函数 |
Returns
| Type | Description |
|---|---|
| function | 传进来的回调函数(如果你的回调是匿名函数,这对于以后退订很有用) |

SubscribeRemote
在这个特定实体上订阅一个从服务器调用的自定义远程事件
local ret = my_entity:SubscribeRemote(event_name, callback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 要订阅的事件名称 |
| function | callback | Required parameter | 触发事件时要调用的函数 |
Returns
| Type | Description |
|---|---|
| function | 传进来的回调函数(如果你的回调是匿名函数,这对于以后退订很有用) |

Unsubscribe
退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调
my_entity:Unsubscribe(event_name, callback?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | 要退订的事件名称 |
| function | callback? | nil | 可选,要退订的特定回调函数 |
🚀 事件
| Name | Description | |
|---|---|---|
ClassRegister | 当使用 继承系统 注册一个新类时触发 | |
Destroy | 当实体被销毁时触发 | |
Spawn | 当实体被生成/创建时触发 | |
ValueChange | 当实体通过 :SetValue() 改变了值时触发 |

ClassRegister
当使用 继承系统 注册一个新类时触发
Entity.Subscribe("ClassRegister", function(class)
-- ClassRegister was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| table | class | 被继承的类 |

Destroy
当实体被销毁时触发
Entity.Subscribe("Destroy", function(self)
-- Destroy was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Entity | self | 被销毁的实体 |

Spawn
当实体被生成/创建时触发
Entity.Subscribe("Spawn", function(self)
-- Spawn was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Entity | self | 被生成的实体 |

ValueChange
当实体通过 :SetValue() 改变了值时触发Entity.Subscribe("ValueChange", function(self, key, value)
-- ValueChange was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Entity | self | 值刚刚发生改变的实体 |
| string | key | 所使用的键 |
| any | value | 被设置的新值 |