The code below shows how to get a list of players that are ranked Op. It then checks, if they are online. If yes it sends them a message. This code makes use of
powerful LINQ.
- Code: Select all
var operatorGroup = Group.groupList.Where(g => g.Permission == LevelPermission.Operator).First();
var operators = operatorGroup.playerList.All();
foreach (var op in operators)
{
var opOnline = Player.Find(op);
if (opOnline == null)
continue;
Player.SendMessage(opOnline, "Some message");
}
If you want to get a list of Op+ players, then replace the two first lines with this:
- Code: Select all
var operatorPlusGroup = Group.groupList.Where(g => g.Permission >= LevelPermission.Operator);
var operatorsPlus = operatorPlusGroup.SelectMany(g => g.playerList.All());
Well, you can do the same without LINQ (below), but I recommend LINQ because it's more readable and concise.
- Code: Select all
Group operatorGroup = null;
foreach (Group g in Group.groupList)
{
if (g.Permission == LevelPermission.Operator)
{
operatorGroup = g;
break;
}
}
List<string> operators = operatorGroup.playerList.All();
*I haven't tested it, but it should work.