Description
EventService is a ZSharp unique library for handling game events. From OnClockTick to WeatherService.OnWeatherSet, see event key list for a list of event keys that exists.
Properties
| Type | Key | Default Value |
|---|---|---|
| No available properties |
Methods
| Return Type | Name | |
|---|---|---|
| EventPacket | Invoke (key: string, playerPacket: *(Player | {Player})?*, …) |
| Signal | OnInvoked (key: string, func: (event: EventPacket, …any) -> nil, position: number?) | |
| {string} | ListHandlers (pattern: string?, search: boolean?) |
Property Descriptions
No available properties
Method Descriptions
EventPacket Invoke(key: string, playerPacket: (Player | {Player})?, …)
- Invokes an event of
key. To see list of active event handlers, useEventService:ListHandlers(). -
@paramplayerPacket:- [Server Invoke]
nilis the same as an empty table. - [Server Invoke]
{Player}a list of players that can event can invoke to. - [Client Invoke] playerPacket input doesn’t matter, it always default to
LocalPlayer.
- [Server Invoke]
Signal OnInvoked(key: string, func: (event: EventPacket, …any) -> nil, position: number?)
- Connects a
functionto handle when a event ofkeyis invoked. - Returns a
Signal, which disconnects when the instance is destroyed.
Examples:
-- Listening to `OnClockTick` event.
local disFunc = EventService:OnInvoked("OnClockTick", function(event: EventPacket, ...)
local osTime = ... -- Based on event key arguments. Check event key list.
print("Current time", osTime); -- Prints os timestamp every second when the clock ticks.
end)
task.wait(5);
disFunc(); -- Disconnect event listener after 5 seconds.
{[number]: string} ListHandlers(pattern: string?, search: boolean?)
- Returns a sorted list of event handler keys.
pattern ~= nil- Then it will return every available instance.
pattern ~= nil and search ~= true- Then it will search for instances with names exactly matches the
pattern.
- Then it will search for instances with names exactly matches the
pattern ~= nil and search == true- Then it will
string.matchinstances with names matching the pattern.
- Then it will
Event Packet
Description
Event packets are objects that allow you to cancel events.
Properties
| Type | Key | Default Value |
|---|---|---|
| boolean | Cancelled | false |
| boolean | Completed | false |
| Player? | Player | nil |
| {Player}? | Players | nil |
Methods
| Return Type | Name |
|---|---|
| nil | SetCancelled (value: boolean) |
Property Descriptions
- Status of the event, when cancelled, every other proceeding event handlers will not be invoked.
- Use
EventPacket:SetCancelled(...)to set this value.
- When completed, canceling events will have no effect.
- Returns the first player in
EventPacket.Playersornil.
- Returns the list of players. Server will replicate the event to the list of players in this list. If a player is removed, they will not receive the event signal.
- Has no replication effect on client side.
Method Descriptions
nil SetCancelled(value: boolean)
- Cancels an event. E.g. If
WeatherService.OnWeatherSetis cancelled, the weather will not be set byWeatherService.
Event Key List
| Keys | Arguments | Data Type |
|---|---|---|
OnClockTick | serverTime | number |
WeatherService.OnWeatherSet | WeatherPacket | {any} |