Helpful Comparing Players Method

Helpful Comparing Players Method

Postby Conor » 20 Jun 2013, 00:36

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;
}
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Return to Knowledge Base

Who is online

Users browsing this forum: No registered users and 1 guest

cron