Event
Events are useful to establish communication between the Server and all connected Players.
Here's a simple example:
local e = Event() e.someMessage = "Something I'd like to say!" e.someNumber = 42 e:SendTo(Server) -- send to Server -- other possible recipients: e:SendTo(Players) -- send to all players e:SendTo(Players[2]) -- send to player 2 e:SendTo(OtherPlayers) -- send to all players but self
Events trigger the DidReceiveEvent function for each recipient (see Client.DidReceiveEvent & Server.DidReceiveEvent).
Server.DidReceiveEvent = function(event) -- `action` here is a custom field set by the developer if event.action == "ping" then local response = Event() response.action = "pong" response:SendTo(event.Sender) end end
Constructors
Event ( )
Functions
Sends the Event to recipients in parameters.
Recipients can be individual Players, OtherPlayers, Players or Server.
local e = Event() e.someMessage = "Something I'd like to say!" e:SendTo(Player[2], Player[3]) -- send to player 2 & 3
Properties
An array containing all recipients for that event.
Recipients can contain individual Players, OtherPlayers, Players or Server.
Who sent the event. A useful property when you want to send a response:
Server.DidReceiveEvent = function(event) -- `action` here is a custom field set by the developer if event.action == "ping" then local response = Event() response.action = "pong" response:SendTo(event.Sender) end end