🚩 Events
Subscribe for user-defined Events.
🗿Static Class
This is a Static Class. Access it's methods directly with
.. It's not possible to spawn new instances.🧑💻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!
🎒 Examples
info
远程 代表对面的端,例如:如果我是客户端,远程就是服务器。 如果我是服务器,远程就是客户端。
基础用法
Client/Index.lua
-- register for a local Event (local = client only)
Events.Subscribe("MyLocalEvent", function(my_text)
Console.Log("Event received locally! " .. my_text)
-- outputs "Event received locally! hello nanos world!"
end)
-- calls a local Event in all Local Packages
Events.Call("MyLocalEvent", "hello nanos world!")
-- register for a server Event (remote = server)
Events.SubscribeRemote("MyClientEvent", function(my_text)
Console.Log("Event received from server! " .. my_text)
-- outputs "Event received from server! 你好 nanos world!"
end)
-- 在所有服务器包中调用一个远程事件
Events.CallRemote("MyServerEvent", Reliability.Reliable, "你好 nanos world!")
info
在服务器上,注册远程事件会有一个额外的参数:Player,即发送该事件的客户端。
Server/Index.lua
-- register for a local Event (local = server only)
Events.Subscribe("MyLocalEvent", function(my_text)
Console.Log("Event received locally! " .. my_text)
-- outputs "Event received locally! hello nanos world!"
end)
-- calls a local Event in all Local Packages
Events.Call("MyLocalEvent", "hello nanos world!")
-- register for a client Event (remote = client)
Events.SubscribeRemote("MyServerEvent", function(player, my_text)
Console.Log(player:GetName() .. " 从客户端发送了一个事件! " .. my_text)
-- outputs "Syed sent an event from client! 你好 nanos world!"
-- 向发送该事件的玩家发送一个“回复”
Events.CallRemote("MyClientEvent", player, Reliability.Reliable, "你好 nanos world! 给你专属的消息!")
end)
-- 向所有客户端包中的所有玩家广播一个远程事件
Events.BroadcastRemote("MyClientEvent", Reliability.Reliable, "你好 nanos world!")
通过事件传递实体
-- register for an Event (remote or local)
Events.Subscribe("MyAnotherEvent", function(my_text, my_vector, my_character, my_number)
Console.Log("Event received! " .. my_text .. " " .. my_vector.X .. " " .. my_character:GetViewMode() .. " " .. my_number)
-- outputs "Event received! 你好 nanos world! 123 1 456"
end)
-- 通过事件传递角色
local my_temp_character = Character()
-- 在所有本地包中调用一个本地事件
Events.Call("MyEvent", "你好 nanos world!", Vector(123, 123, 123), my_temp_character, 456)
-- 在所有服务器包中调用一个远程事件
Events.CallRemote("MyEvent", Reliability.Reliable, "你好 nanos world!", Vector(123, 123, 123), my_temp_character, 456)
tip
你可以在事件指南页面找到更多示例和详尽的指南。
🗿 Static Functions
| Returns | Name | Description | |
|---|---|---|---|
BroadcastRemote | Broadcasts a remote custom Event from the Server to ALL currently connected Players (Server ➔ Clients) | ||
BroadcastRemoteDimension | Broadcasts a remote custom Event from the Server to all Players currently residing in the specified Dimension (Server ➔ Clients) | ||
BroadcastRemoteInRadius | Broadcasts a remote custom Event from the Server to all Players within a specific location radius (Server ➔ Clients) | ||
BroadcastRemoteInRadiusDimension | Broadcasts a remote custom Event from the Server to all Players within a specific location radius AND residing in a specific Dimension (Server ➔ Clients) | ||
Call | Triggers a local custom Event across all Packages on the same side (Client ➔ Client OR Server ➔ Server) | ||
CallRemote | Triggers a remote custom Event from the Client to the Server (Client ➔ Server) | ||
CallRemote | Triggers a remote custom Event from the Server to the Client (Server ➔ Client) | ||
CallRemotePlayers | Triggers a remote custom Event from the Server to an array of specific Players (Server ➔ Clients) | ||
| function | Subscribe | Listens for a local custom Event triggered by Events.Call() on the same side | |
| function | SubscribeRemote | Listens for a network custom Event | |
Unsubscribe | Removes a local event listener previously registered with Events.Subscribe() | ||
UnsubscribeRemote | Removes a network event listener previously registered with Events.SubscribeRemote() |

BroadcastRemote
Broadcasts a remote custom Event from the Server to ALL currently connected Players (Server ➔ Clients)
Must be caught usingEvents.SubscribeRemote()on the Clients
Events.BroadcastRemote(event_name, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

BroadcastRemoteDimension
Broadcasts a remote custom Event from the Server to all Players currently residing in the specified Dimension (Server ➔ Clients)
Must be caught usingEvents.SubscribeRemote()on the Clients
Events.BroadcastRemoteDimension(event_name, dimension, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| integer | dimension | Required parameter | The Dimension to send this event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

BroadcastRemoteInRadius
Broadcasts a remote custom Event from the Server to all Players within a specific location radius (Server ➔ Clients)
Must be caught usingEvents.SubscribeRemote()on the Clients
Events.BroadcastRemoteInRadius(event_name, location, radius, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| Vector | location | Required parameter | The location used to calculate the event radius |
| number | radius | Required parameter | The radius to send this event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

BroadcastRemoteInRadiusDimension
Broadcasts a remote custom Event from the Server to all Players within a specific location radius AND residing in a specific Dimension (Server ➔ Clients)
Must be caught usingEvents.SubscribeRemote()on the Clients
Events.BroadcastRemoteInRadiusDimension(event_name, location, radius, dimension, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| Vector | location | Required parameter | The location used to calculate the event radius |
| number | radius | Required parameter | The radius to send this event |
| integer | dimension | Required parameter | The Dimension to send this event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

Call
Triggers a local custom Event across all Packages on the same side (Client ➔ Client OR Server ➔ Server)
Must be caught usingEvents.Subscribe()
Events.Call(event_name, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| any | args...? | nil | Arguments to pass to the event |
See also Subscribe.

CallRemote
Triggers a remote custom Event from the Client to the Server (Client ➔ Server)
The receiving Server will implicitly receive the sender 'Player' as the very first argument before your custom args
Must be caught usingEvents.SubscribeRemote()
Events.CallRemote(event_name, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

CallRemote
Triggers a remote custom Event from the Server to the Client (Server ➔ Client)
Must be caught usingEvents.SubscribeRemote()
Events.CallRemote(event_name, player, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| Player | player | Required parameter | The remote player to send this event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

CallRemotePlayers
Triggers a remote custom Event from the Server to an array of specific Players (Server ➔ Clients)
More network-efficient than looping CallRemote
Must be caught usingEvents.SubscribeRemote()on the Clients
Events.CallRemotePlayers(event_name, players, reliability?, args...?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to trigger the event |
| table of Player | players | Required parameter | The remote players to send this event |
| Reliability | reliability? | Reliability.Reliable | The network reliability rule |
| any | args...? | nil | Arguments to pass to the event |
See also SubscribeRemote.

Subscribe
Listens for a local custom Event triggered by Events.Call() on the same side— Returns function (the subscribed callback itself).
local ret = Events.Subscribe(event_name, callback)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to subscribe |
| function | callback | Required parameter | The callback function to execute |

SubscribeRemote
Listens for a network custom Event
If on the Server, it catchesEvents.CallRemote()from Clients (receiving the sender 'Player' as the first argument)
If on the Client, it catches Server broadcasts and remote calls
— Returns function (the subscribed callback itself).
local ret = Events.SubscribeRemote(event_name, callback)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to subscribe |
| function | callback | Required parameter | The callback function to execute |

Unsubscribe
Removes a local event listener previously registered with Events.Subscribe(). If no specific callback function is passed, it removes ALL local listeners for that event name in the current PackageEvents.Unsubscribe(event_name, callback?)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | The Event Name to unsubscribe |
| function | callback? | nil | The callback function to unsubscribe |

UnsubscribeRemote
Removes a network event listener previously registered with Events.SubscribeRemote(). If no specific callback function is passed, it removes ALL remote listeners for that event name in the current PackageEvents.UnsubscribeRemote(event_name, callback?)