-
Notifications
You must be signed in to change notification settings - Fork 1
MessHallAPI Custom RPCs (Remote Procedure Call)
A Remote Procedure Call (RPC) is a way to send data to other players in the same room.
RPCs are used to sync values, positions, and other data, or to tell other clients to run actions.
In simple terms, an RPC lets you make other players’ games do something.
Making a custom RPC with MessHallAPI is simple.
Create a method and add the MessHallRPC attribute above it.
When creating an RPC, you need to define:
- Who can call it (
RPCCaller) - Who receives it (
RPCTarget)
-
RPCCaller.Anyone-> any player can call it -
RPCCaller.HostOnly-> only the host can call it
-
All-> sent to everyone except the sender -
AllInclusive-> sent to everyone including the sender -
Host-> only the host receives it
[MessHallRPC(RPCTarget.AllInclusive, RPCCaller.Anyone)]
public static void RPC_Message(string msg)
{
MelonLogger.Msg($"Message Received! {msg}");
}This RPC sends a message to everyone in the game, including the sender.
To send an RPC, use:
MessHallAPI.Networking.NetworkManager.InvokeRPC("YourModName", "RPC_MethodName", args);MessHallAPI.Networking.NetworkManager.InvokeRPC("TestMod", "RPC_Message", "hello");This will make every client log "hello".
Make sure the first argument is your mod’s file name (without .dll).
You can target a specific player using [RPCTarget].
Add it to a parameter in your method:
[MessHallRPC(RPCTarget.All, RPCCaller.Anyone)]
public static void RPC_Message([MessHallAPI.Networking.RPCTarget] int target, string msg)
{
MelonLogger.Msg($"Message Received! {msg}");
}MessHallAPI.Networking.NetworkManager.InvokeRPC("YourModName", "RPC_Message", 1, "hello");This will only run on the player with ID 1.
Use [RPCInfo] in your method parameters.
MessHallAPI fills this automatically, so you do not pass it when calling the RPC.
[MessHallRPC(RPCTarget.All, RPCCaller.Anyone)]
public static void RPC_Message([MessHallAPI.Networking.RPCInfo] MessHallAPI.Networking.MessHallRpcInfo info, string msg)
{
MelonLogger.Msg($"Message from {info.Sender}: {msg}");
}MessHallAPI.Networking.NetworkManager.InvokeRPC("YourModName", "RPC_Message", "hello");Yes. You can use both in the same RPC.
Just remember you do not pass a value for RPCInfo when calling it.
MessHallAPI supports:
byte, short, ushort, int, uint, long, ulong, float, double, bool, string
Using any other type will not work.