Page 1 of 1

Helpful Comparing Players Method

PostPosted: 20 Jun 2013, 00:36
by Conor
This is just a very basic method which I thought I'd create here for you to copy and paste into commands when you're coding them, to save some time. Basically, in pretty much most commands you make, you check if a player is online, and then you check their rank in comparison to another player. So this method will just do this, but saves you writing it out every time, you can just paste the method across.

The method returns a bool value, so see in the example below how it is used.

Code: Select all
public override void Use(Player p, string message)
{
    Player who = Player.Find(message);
   
    if (ComparePlayer(who, p))
    {
        // Code here - the player exists and is a lower rank.
    }
}

public bool ComparePlayer(Player who, Player p)
{
   if (who == null || who.hidden)
   {
       Player.SendMessage(p, "Player could not be found.");
       return false;
   }
 
   if (who.group.Permission >= p.group.Permission)
   {
       Player.SendMessage(p, "Cannot use this command on a player of greater or equal rank.");
       return false;
   }   
   return true;
}