Skip to main content
Branch: Development

onRpc

Callable

  • onRpc<K>(rpcName: K, listener: (player: Player, ...args: Parameters<ICustomClientServerRpc[K]>) => ReturnType<ICustomClientServerRpc[K]> | Promise<ReturnType<ICustomClientServerRpc[K]>>): void
  • onRpc<K>(rpcName: Exclude<K, never>, listener: (player: Player, ...args: any[]) => any): void

  • Subscribes to a client -&gt; server RPC with the specified listener.

    Example

    alt.onRpc("testRpc", (player, ...args) => {
    alt.log(`${player.name} called testRpc`, args);

    // throw new Error("I am an error! Notice me!");
    return [1, 2, [10, 13, 19], false, "hey there"];
    });

    Remarks

    The return value of the listener function determines the response clients will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the client to throw an exception which has to be caught.


    Type parameters

    • K: never