Skip to main content

RPC - Server to Client

The server calls the client function using Remote Procedure Call (RPC).

A function that needs to be called on the client:

function WeaponFlyObj:RpcOnShoot(bullet)    --client to doend

Registering Function in NetworkInject so that the client can find the same function and run it when the server calls it.

function WeaponFlyObj:NetworkInject()    self.host.interact.networkIB.networkIBState:InjectFunc("RpcOnShoot", self.RpcOnShoot)    --inject other functionend

The server uses the interface ServerRpcIntFunc (Please read NetworkIBStateX for more interfaces) in networkIBState to call functions in the client. (RpcOnShoot).

​ other interface refer to NetworkIBStateX

ServerRpcIntFunc(funtionName, int, includeServer)

  • functionName: The name of the function to be called on the client

  • int: int value

  • includeServer: run this function on the server as well,In this case, includeServer is false, so it will only run RpcOnShoot on the client side.

    function WeaponFlyObj:ServerOnShoot(bullet)    self.host.interact.networkIB.networkIBState:ServerRpcIntFunc("RpcOnShoot", bullet.netId, false)end