You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System.Linq;
using GameNetcodeStuff;
using HarmonyLib;
using Hax;
[HarmonyPatch(typeof(PlayerControllerB))]
class KickPlayerPatch {
[HarmonyPatch("SendNewPlayerValuesServerRpc")]
static bool Prefix(PlayerControllerB __instance) {
if (!Setting.EnableKickPlayer) return true;
Helper.GameNetworkManager?.currentLobby?.Members.ForEach((i, member) => {
if (Helper.LocalPlayer?.playerSteamId == member.Id.Value) return;
PlayerControllerB player = __instance.playersManager.allPlayerScripts[i];
player.playerSteamId = member.Id.Value;
player.playerUsername = member.Name;
player.usernameBillboardText.text = member.Name;
__instance.playersManager.mapScreen.radarTargets[i].name = player.playerUsername;
__instance.quickMenuManager.AddUserToPlayerList(player.playerSteamId, player.playerUsername, i);
});
return false;
}
[HarmonyPatch("SendNewPlayerValuesClientRpc")]
static void Postfix(PlayerControllerB __instance) {
if (!Setting.EnableKickPlayer) return;
if (Helper.LocalPlayer is not PlayerControllerB localPlayer) return;
// For example, write code to kick a player who meets certain conditions.
// In this example, we assume kicking the first player in the player list.
PlayerControllerB playerToKick = __instance.playersManager.allPlayerScripts.FirstOrDefault();
if (playerToKick != null) {
// Kick player code
playerToKick.Disconnect(); // This code should be implemented according to the actual game.
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
#pragma warning disable IDE1006
using System.Linq;
using GameNetcodeStuff;
using HarmonyLib;
using Hax;
[HarmonyPatch(typeof(PlayerControllerB))]
class KickPlayerPatch {
[HarmonyPatch("SendNewPlayerValuesServerRpc")]
static bool Prefix(PlayerControllerB __instance) {
if (!Setting.EnableKickPlayer) return true;
}
I was wondering if I could code like this
Beta Was this translation helpful? Give feedback.
All reactions