Skip to content

Instantly share code, notes, and snippets.

@Pandapip1
Created March 12, 2021 17:23
Show Gist options
  • Save Pandapip1/f52500da0272e6bd2acc67ac7a6debf8 to your computer and use it in GitHub Desktop.
Save Pandapip1/f52500da0272e6bd2acc67ac7a6debf8 to your computer and use it in GitHub Desktop.
Better RPC (with example)
public static class BetterRPC
{
}
using Reactor.Extensions;
using Reactor.Unstrip;
using Reactor.BetterRPC;
using UnityEngine;
using HarmonyLib;
namespace YourCoolMod
{
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))]
public static class ExampleButton
{
private static CooldownButton btn;
public static void Postfix(HudManager __instance)
{
btn = new CooldownButton(
() =>
{
// Do cool stuff when the button is pressed
},
5f, // The cooldown for this button is five seconds
Properties.Resources.yournamehere, // change yournamehere to the name you set in step 2
new Vector2(0.125f, 0.125f), // The position of the button, 1 unit is 100 pixels
() =>
{
// Who has access to the button? This allows alive crewmates to use the new button while the game is started
return !PlayerControl.LocalPlayer.Data.IsDead && !PlayerControl.LocalPlayer.Data.IsImpostor && (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started || AmongUsClient.Instance.GameMode == GameModes.FreePlay);
},
__instance
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment