Repository navigation
Part 4. RPC Buttons
In this guide we'll cover RPC Buttons and how to implement RPC calls from your mod's settings page.
The RPC Button control is a button that will can trigger code in your Mod Controller when clicked.
RPC Buttons can be marked as server-side or client side, and ModConfig will handle the RPC/Replication for you.
RPC Buttons can be useful for various functionality you wish to expose to players; any administrative or maintenance task can be tied to an RPC Button, which gives you the control to allow admins or players to trigger code in your mod.
Some examples could be
- Clearing internal data in your mod
- Resetting or reinitializing actors or classes
- Manually triggering update code to refresh data
We'll start off with a client-side RPC button.
- Open the
GetModSettingsfunction in your mod controller - Add an
Add Setting RPCButtonnode - Set the
Namefield, make note that we'll need it later - Set the
Label TextandTooltip Textas you feel is necessary - Use
Mod Append Settingas usual to add the RPC Button to the settings object
Now we have an RPC Button as part of our list of settings. We can capture the RPC trigger by adding a Mod RPCClient Event to an event graph in your Mod Controller.
- Add a
Mod RPCClientEvent - Add a
VerifyCallernode, and link theCalling Objectpin to theCallerpin - Add a
Setting RPCnode and link theRPC Namepin to theRPC Name Inputpin - Enter the RPC Name you created above into the
RPC Namepin - Connect a function of your choosing (or a block of code on the event graph) to the
Is RPCpin
When a user clicks your RPC Button control in the ModConfig page, the code you connected to the Is RPC pin will be executed on the client.
Server-side RPC calls are similar to other server-side controls in ModConfig.
- Open the
GetModSettingsfunction in your mod controller - Add an
Add Setting RPCButtonnode - Set the
Namefield, make note that we'll need it later - Set the
Label TextandTooltip Textas you feel is necessary - Add a
Setting Mark Server Sidenode and connect theSetting Objectpin to theSetting Fieldpin - Use
Mod Append Settingas usual
Now we have an RPC button marked as server-side. This means two things for RPC button controls
- The RPC button will only be visible to admins
- The RPC code will automatically trigger on the server when the button is clicked
Now with the RPC Button marked as server-side and added to our settings page, we can capture the RPC call in the Mod Controller. This process is similar to the client-side version above
- Add a
Mod RPCServerEvent - Add a
VerifyCallernode, and link theCalling Objectpin to theCallerpin - Add a
Setting RPCnode and link theRPC Namepin to theRPC Name Inputpin - Enter the RPC Name you created above into the
RPC Namepin - Connect a function of your choosing (or a block of code on the event graph) to the
Is RPCpin
As said above, when a user clicks your RPC Button control in the ModConfig page, the code you connected to the Is RPC pin will be executed on the server now. You can use this to replicate back to all clients or run authoritative code.