Hello all,
I've been desperate to try and get a Kick/Ban plugin working in Hurtworld. I'm super new to any kind of programming language, but I've been working for the past day in porting KickBan from Rust Legacy to Hurtworld. I've got it to the point that I can do everything in chat, except have the commands actually execute. I'm not sure how to even ask this, but does anyone know how to take this small line of code and get it to execute the Hurtworld Kick and Ban commands?
Code:void cmdKick(string userid, string name, string reason) { cachedUser = rust.FindPlayer(userid); if (cachedUser != null) { cachedUser.Kick(NetError.Facepunch_Kick_RCON, true); } } void cmdBan(string userid, string name = "Unknown", string reason = "Unkown") { ulong playerid; if (!ulong.TryParse(userid, out playerid)) { return; } cachedUser = rust.FindPlayer(userid); if (cachedUser != null) { cachedUser.Kick(NetError.ConnectionBanned, true); } }
Help with porting a plugin
Discussion in 'Hurtworld Development' started by denalb, Dec 15, 2015.
-
Code:
PlayerIdentity getPlayerFromUid(string uid) { var identityMap = GameManager.Instance.GetIdentityMap(); var identity = identityMap.FirstOrDefault(x => string.Equals(x.Value.SteamId.m_SteamID.ToString().ToLower(), uid.ToLower())).Value; return identity; } void cmdKick(string userid, string name, string reason) { cachedUser = getPlayerFromUid(userid); if (cachedUser != null) { GameManager instance = Singleton<GameManager>.Instance; if (instance == null) return; instance.KickPlayer(cachedUser.SteamId.m_SteamID.ToString(), reason); } } void cmdBan(string userid, string name = "Unknown", string reason = "Unkown") { ulong playerid; if (!ulong.TryParse(userid, out playerid)) { return; } cachedUser = getPlayerFromUid(userid); if (cachedUser != null) { ConsoleManager.Instance?.ExecuteCommand("ban "+userid); } }
-
Wulf Community Admin
- The PlayerIdentity already provides the NetworkPlayer via ConnectedNetworkPlayer.Value, so I'd remove getPlayerFromUid.
- You can get the GameManager instance with just GameManager.Instance, the Singleton is not required.
- The Steam ID is available with SteamId along, the m_SteamID is not needed.
- You could handle the kicking and command execution via Oxide's Covalence API as well.
-
[DOUBLEPOST=1450290864][/DOUBLEPOST]My code is complete garbage and I'm sure there is a lot that can be cleaned up (I had never touched programming before trying to port this plugin), but it is functioning as expected. -