Warp/docs/api/1.0/server.md
EternityDev aa693aee4f v1.0.11
2024-05-19 13:17:07 +07:00

3.3 KiB

Server

For Server-sided

.Server

Create new Warp event.

::: code-group

(
	Identifier: string,
	rateLimit: {
		maxEntrance: number?,
		interval: number?,
	}?
)
local Remote = Warp.Server("Remote")

:::

.fromServerArray

Create new Warp events with array.

::: code-group

(
	{ any }
)
local Events = Warp.fromServerArray({
	["Remote1"] = {
		rateLimit = {
			maxEntrance: 50,
			interval: 1,
		}
	}, -- with rateLimit configuration
	"Remote2", -- without rateLimit configuration
	["Remote3"] = {
		rateLimit = {
			maxEntrance: 10,
		}
	}, -- with rateLimit configuration
})

-- Usage
Events.Remote1:Connect(function(player, ...) end)
Events.Remote2:Connect(function(player, ...) end)
Events.Remote3:Connect(function(player, ...) end)

:::

:Connect

Connect event to receive incoming from client way.

::: code-group

(
	player: Player,
	callback: (...any) -> ()
): string
Remote:Connect(function(player, ...)
	print(player, ...)
end)

:::

:Once

This function likely :Connect but it disconnect the event once it fired.

::: code-group

(
	player: Player,
	callback: (...any) -> ()
)
Remote:Once(function(player, ...)
	print(player, ...)
end)

:::

:Disconnect

Disconnect the event connection.

::: code-group

(
	key: string
): boolean
local connection = Remote:Connect(function(player, ...) end) -- store the key

Remote:Disconnect(connection)

:::

:DisconnectAll

Disconnect All the event connection.

Remote:DisconnectAll()

:Fire

Fire the event to a client.

::: code-group

(
	reliable: boolean,
    player: Player,
	...: any
)
Remote:Fire(true, player, "Hello World!")

:::

:Fires

Fire the event to all clients.

::: code-group

(
	reliable: boolean,
	...: any
)
Remote:Fires(true, "Hello World!")

:::

:FireExcept

Fire the event to all clients but except a players.

::: code-group

(
	reliable: boolean,
	except: { Player },
	...: any
)
Remote:FireExcept(true, { Players.Eternity_Devs, Players.Player2 }, "Hello World!") -- this will sent to all players except { Players.Eternity_Devs, Players.Player2 }.

:::

:Invoke

Semiliar to :InvokeClient, but it have timeout system that not exists on RemoteFunction.InvokeClient.

::: code-group

(
	timeout: number,
    player: Player,
	...: any
) -> (...any)
local Request = Remote:Invoke(2, player, "Hello World!")

:::

::: warning This function is yielded, once it timeout it will return nil. :::

:Wait

Wait the event being triggered.

Remote:Wait() -- :Wait return number value

::: warning This function is yielded, Invoke might also ping this one and also causing error. :::

:Destroy

Disconnect all connection of event and remove the event from Warp.

Remote:Destroy()