1. 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);
                }
            }
     
  2. 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);
                }
            }
     
  3. Wulf

    Wulf Community Admin

    A lot of that is unnecessary. Here are some suggestions:
    • 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.
     
  4. I really appreciate you taking the time to help me with this. This has enabled me to get a working plugin that allows me to use oxide permissions to allow my moderators to kick and ban in the server without having full admin access to the server. This has saved me a lot of worry with giving players the ability to moderate without me being fully involved 24/7.
    [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.
     
  5. It works though right? That is what matters to you.