Skip to main content
Branch: Development

onRpc

Callable

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

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

    Example

    alt.onRpc("testRpc", (...args) => {
    alt.log(`server 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 server will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the server to throw an exception which has to be caught.


    Type parameters

    • K: never