Events

Events (or Callbacks) are the way to transmit and send data between Packages or between Client and Server side.

Tip

This is a Static Class named Events. You can access it’s methods directly with :. It is not possible to initialize or create new instances.

Tip

It is possible to pass any kind of Official Classes and Structures (Vector, Rotator, Color, Character, Player, Prop, etc…) through events, including through network =D!

Attention

It is NOT (yet) possible to send tables through network Events.

Functions

Name

Description

Call(string EventName, table {Args…})

Calls an Event which will be triggered in all Local Packages

client-only-label

CallRemote(string EventName, table {Args…})

Calls an Event on Client which will be triggered in all Server Packages

server-only-label

CallRemote(string EventName, Player Remote, table {Args…})

Calls an Event on Server which will be triggered in all Client’s Packages of Player

server-only-label

BroadcastRemote(string EventName, table {Args…})

Calls an Event on Server which will be triggered in all Client’s Packages

Examples

Tip

Remote means the other side, e.g.: if I’m the client, the remote is the server. If I’m the server, the remote is the client.

-- [[CLIENT]]

-- register for a local Event (local = client only)
Events:on("MyLocalEvent", function(my_text)
    Package: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:on("MyClientEvent", function(my_text)
    Package:Log("Event received from server! " .. my_text)
    -- outputs "Event received from server! hello nanos world!"
end)

-- calls a remote Event in all Server Packages
Events:CallRemote("MyServerEvent", {"hello nanos world!"})

Note

On Server, registering for remote events has an addition parameter: Player, which is the client who sent the event.

-- [[SERVER]]

-- register for a local Event (local = server only)
Events:on("MyLocalEvent", function(my_text)
    Package: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:on("MyServerEvent", function(player, my_text)
    Package:Log(player:GetName() .. " sent an event from client! " .. my_text)
    -- outputs "Syed sent an event from client! hello nanos world!"

            -- sends an "answer" to the player which sent this event
    Events:CallRemote("MyClientEvent", player, {"hello nanos world! message only for you!"})
end)

-- sends a remote Event to all Players in all Client Packages
Events:BroadcastRemote("MyClientEvent", {"hello nanos world!"})

Passing entities through events:

-- register for an Event (remote or local)
Events:on("MyAnotherEvent", function(my_text, my_vector, my_character, my_number)
    Package:Log("Event received! " .. my_text .. " " .. my_vector.X .. " " .. my_character:GetViewMode() .. " " .. my_number)
    -- outputs "Event received! hello nanos world! 123 1 456"
end)

-- passing Characters through events
local my_temp_character = Character()

-- calls a local Event in all Local Packages
Events:Call("MyEvent", {"hello nanos world!", Vector(123, 123, 123), my_temp_character, 456})

-- calls a remote Event in all Server Packages
Events:CallRemote("MyEvent", {"hello nanos world!", Vector(123, 123, 123), my_temp_character, 456})