Solved BasePlayer.Find error

Discussion in 'Rust Development' started by Reynostrum, Jun 11, 2016.

  1. Code:
    [ChatCommand("test")]
            void FindPlayer(BasePlayer player)
            {
                var targetPlayer = BasePlayer.Find("steamid");
                if (targetPlayer.IsConnected())
                {
                    //targetPlayer is online
                }
                else
                {
                    //targetPlayer is offline
                }
            }
    I think this should work, but it does'nt.

    Code:
    [Debug]   at Oxide.Plugins.ExtraPlugins.FindPlayer (.BasePlayer player) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.ExtraPlugins.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
     
  2. Code:
    public static BasePlayer Find(string strNameOrIDOrIP)
    You're not searching for anyone.

    Code:
    var targetPlayer = BasePlayer.Find("Reynostrum");
    var targetPlayer = BasePlayer.Find("12345678987654321");
    var targetPlayer = BasePlayer.Find("127.0.0.1");
     
  3. Sorry, I don't follow, I am new with C#
    Code:
    var targetPlayer = BasePlayer.Find("12345678987654321");
    That's what I am doing, but what's wrong?
     
  4. It will return null if nothing found, so make sure it's not null
     
  5. Code:
    void FindPlayer(BasePlayer player)
            {
                var targetPlayer = BasePlayer.Find("steamid");
                if (targetPlayer != null)
                {
                    if(targetPlayer.IsConnected())
                    {
                        //online
                    }
                    else
                    {
                        //offline
                    }
                }
                else
                {
                    //offline
                }
            }
    Something like this?
     
  6. Really if it's not null, they're online