Knight Remotes API
Last updated
Was this helpful?
Last updated
Was this helpful?
The KnightRemotes
module provides a robust framework for managing remote events and functions across the client and server in the Knight framework. This module handles remote creation, firing, middleware management, and connection, ensuring efficient, secure communication for your game.
Get Remotes: Synchronously or asynchronously retrieve RemoteAPI
instances by name.
Fire Remotes: Trigger remotes on specific players, all players, or players nearby a location.
Middleware: Integrate middleware functions for security and validation checks on events.
Register/Unregister Remotes: Add or remove remote functions/events dynamically.
Here’s the revised documentation with the requested formatting changes:
Remotes:GetAsync(RemoteName: string) -> await RemoteAPI
Description:
Waits asynchronously to retrieve the RemoteAPI
associated with the specified remote name.
Usage:
Parameters:
RemoteName (string): The name of the remote event or function to retrieve.
Returns:
RemoteAPI: The RemoteAPI
associated with RemoteName
(yields until available).
Remotes:Get(RemoteName: string) -> RemoteAPI | boolean
Description:
Fetches the RemoteAPI
associated with the given remote name synchronously.
Usage:
Parameters:
RemoteName (string): The name of the remote.
Returns:
RemoteAPI: The RemoteAPI
if available, otherwise false
.
Remotes:Fire(RemoteName: string, ...) -> (any...)
Description: Triggers the specified remote event or function with the provided arguments.
Usage:
Parameters:
RemoteName (string): The name of the remote.
... (any): Arguments passed to the remote event.
Remotes:FireAllNearby(RemoteName: string, position: Vector3, maxDistance: number | boolean, ...) -> (any...)
Description: Fires the remote to all players within the specified distance from a central position.
Usage:
Parameters:
RemoteName (string): The name of the remote.
position (Vector3): Center position for nearby players.
maxDistance (number | boolean): Maximum radius; if true
, defaults to 50.
... (any): Additional arguments passed to the remote.
Remotes:FireAll(RemoteName: string, ...) -> (any...)
Description: Triggers the remote for all connected players.
Usage:
Parameters:
RemoteName (string): The remote’s name.
... (any): Arguments passed to each connected player.
Remotes:Connect(RemoteName: string, callback: () -> void | nil | boolean) -> void
Description: Attaches a callback to the specified remote. The callback executes each time the remote event is fired.
Usage:
Parameters:
RemoteName (string): The name of the remote.
callback (function): Function executed on the remote event firing.
Remotes:Register(RemoteName: string, RemoteClass: string, Callback: any) -> void
Description: Registers a new remote with a specified class type and optional callback function.
Usage:
Parameters:
RemoteName (string): Name for the new remote.
RemoteClass (string): Class type (e.g., RemoteFunction).
Callback (function, optional): Function to associate with the remote.
Remotes:RegisterMiddleware(Target: string, Callback: (Player: Player, ...any) -> boolean): void
Description: Adds middleware for validation or checks before a remote is triggered.
Usage:
Parameters:
Target (string): The target remote or *
for global middleware.
Callback (function): Middleware function, returning true
to proceed or false
to block.
Remotes:UnregisterMiddleware(Target: string): void
Description: Removes middleware associated with a specific remote.
Usage:
Parameters:
Target (string): The name of the remote from which to remove middleware.
RemoteAPI:Fire(...) -> (any...)
Description: Triggers the associated remote event with the provided arguments.
Usage:
Parameters:
... (any): Arguments passed to the remote event.
RemoteAPI:FireAll(...) -> (any...)
Description: Fires the associated remote for all players.
Usage:
Parameters:
... (any): Arguments passed to each connected player.
RemoteAPI:FireAllNearby(position: Vector3, maxDistance: number | boolean, ...) -> (any...)
Description: Triggers the remote for players within a specific range from a center position.
Usage:
Parameters:
position (Vector3): The central position for nearby players.
maxDistance (number | boolean): Maximum radius; defaults to 50 if true
.
... (any): Additional arguments for the remote.
RemoteAPI:Connect(callback: () -> void | nil | boolean) -> void
Description: Attaches a callback to the remote event, executed when the event fires.
Usage:
Parameters:
callback (function): Function to execute on the event firing.
RemoteAPI:OnDestroying(callback: (RemoteName: string) -> void) -> void
Description: Sets a callback function to be executed when the remote is destroyed.
Usage:
Parameters:
callback (function): Function called with the RemoteName
when destroyed.
RemoteAPI:Destroy()
Description:
Removes the remote from cache and triggers any attached OnDestroying
callbacks.
Usage:
Retrieve a remote using Get
and fire it with some arguments.
Additionally you can fire an event via:
Register a new remote that will respond with a callback function.
Add middleware to restrict access or validate conditions before a remote is triggered.
Fire a remote to all players within a 100-stud radius of a specific position.
Attach a callback function to run when a remote is fired.
Destroy a remote when it's no longer needed and execute cleanup code.
You can organize events into "groups" by naming them with a prefix, separated by a colon (e.g., PointsService:GetPoints
). This allows for structured and readable event names within your system.
In this example, PointsService:GetPoints
is treated as a single, valid event name, enabling a structured namespace approach for grouping related events in the KnightRemotes
module.