![]() |
|
[Release] Show Admins - Printable Version +- ItsMods (https://www.itsmods.com) +-- Forum: Archive (https://www.itsmods.com/Forum-Archive.html) +--- Forum: Archive (https://www.itsmods.com/Forum-Archive--64.html) +--- Thread: [Release] Show Admins (/Thread-Release-Show-Admins.html) |
Show Admins - abidullah - 01-24-2013 this is my code it will show u all the admins and mods online and insted of the text showing in the chat messgae it will show u in the HUD message the command is Quote:!admins sv_config.ini settings PHP Code: //You can add more user groups here
Usergroups=Admin,Moderator,User,Trainee_Moderator,Senior_Moderator
//Add all xuids here (Go ingame and use !getxuid)
Admin_xuids=
Moderator_xuids=
Trainee_Moderator_xuids=
Senior_Moderator_xuids=
//Add commands moderators can use here
Admin_commands=*ALL*
Moderator_commands=
Trainee_Moderator_commands=
Senior_Moderator_commands=
PHP Code: using Addon;
using System;
using System.Collections;
using System.Collections.Generic;
namespace ShowAdmins
{
public class ShowAdmins : CPlugin
{
private ArrayList Admin_Xuids = new ArrayList();
private ArrayList Moderator_Xuids = new ArrayList();
private ArrayList Senior_Moderator_Xuids = new ArrayList();
private ArrayList Trainee_Moderator_Xuids = new ArrayList();
public override void OnServerLoad()
{
try
{
string[] array = base.GetServerCFG("Permission", "Admin_xuids", "0").Split(new char[]
{
','
});
string[] array2 = base.GetServerCFG("Permission", "Moderator_xuids", "0").Split(new char[]
{
','
});
string[] array3 = base.GetServerCFG("Permission", "Senior_Moderator_xuids", "0").Split(new char[]
{
','
});
string[] array4 = base.GetServerCFG("Permission", "Trainee_Moderator_xuids", "0").Split(new char[]
{
','
});
string[] array5 = array;
for (int i = 0; i < array5.Length; i++)
{
string value = array5[i];
this.Admin_Xuids.Add(value);
}
string[] array6 = array2;
for (int j = 0; j < array6.Length; j++)
{
string value2 = array6[j];
this.Moderator_Xuids.Add(value2);
}
string[] array7 = array3;
for (int k = 0; k < array7.Length; k++)
{
string value3 = array7[k];
this.Senior_Moderator_Xuids.Add(value3);
}
string[] array8 = array4;
for (int l = 0; l < array8.Length; l++)
{
string value4 = array8[l];
this.Trainee_Moderator_Xuids.Add(value4);
}
base.ServerPrint("Plugin ShowAdmins loaded!");
}
catch (Exception ex)
{
base.ServerPrint("Plugin ShowAdmins: OnServerLoad catched exception: " + ex.Message);
}
}
public override ChatType OnSay(string Message, ServerClient Client, bool TeamChat)
{
try
{
ChatType result;
if (!Message.StartsWith("!admins"))
{
ChatType chatType = ChatType.ChatContinue;
result = chatType;
return result;
}
Message.Split(new char[]
{
' '
});
string text = "";
List<ServerClient> clients = base.GetClients();
if (clients != null)
{
bool flag = true;
int num = 0;
foreach (ServerClient current in clients)
{
if (this.Admin_Xuids.Contains(current.XUID))
{
if (flag)
{
text += current.Name;
flag = false;
}
else
{
text = text + ", " + current.Name;
}
num++;
}
if (this.Moderator_Xuids.Contains(current.XUID))
{
if (flag)
{
text += current.Name;
flag = false;
}
else
{
text = text + ", " + current.Name;
}
num++;
}
if (this.Senior_Moderator_Xuids.Contains(current.XUID))
{
if (flag)
{
text += current.Name;
flag = false;
}
else
{
text = text + ", " + current.Name;
}
num++;
}
if (this.Trainee_Moderator_Xuids.Contains(current.XUID))
{
if (flag)
{
text += current.Name;
flag = false;
}
else
{
text = text + ", " + current.Name;
}
num++;
}
}
if (num == 0)
{
base.iPrintLnBold("^2No Admins or Mods are ^1ONLINE^2 on this server", Client);
}
else
{
if (num == 1)
{
base.iPrintLnBold("^2Admin^1/^2Mod ^1[" + text + " ]^2is on this server", Client);
}
else
{
base.iPrintLnBold("^2Admins^1&^2 Mods^1[" + text + "]^2 are on this server", Client);
}
}
}
result = ChatType.ChatNone;
return result;
}
catch (Exception ex)
{
base.ServerPrint("Plugin ShowAdmins: OnSay catched exception: " + ex.Message);
}
return ChatType.ChatContinue;
}
}
}
RE: Show Admins - SgtLegend - 01-24-2013 Hi abidullah, After reviewing your code I found it to be very verbose which created a lot of un-needed and redundant code which will slow the plugin down, see the below for a re-written version I created quickly off your code which is 87 lines shorter and will perform much nicer on slower server. EDIT: After browsing the forum quickly I noticed your code was very similar to the following post http://www.itsmods.com/forum/Thread-Server-admin-where-are-you.html?pid=84086#pid84086 Code: using Addon;
using System;
using System.Collections;
using System.Collections.Generic;
namespace ShowAdmins
{
public class ShowAdmins : CPlugin
{
// The list for the XUIDs to be stored in
private List<string> xuids = new List<string>();
/// <summary>
/// Executes when the server has successfully loaded
/// </summary>
public override void OnServerLoad()
{
ServerPrint("Plugin ShowAdmins loaded!");
// Get all the XUIDs from the configuration
xuids.Add(GetServerCFG("Permission", "Admin_xuids", string.Empty));
xuids.Add(GetServerCFG("Permission", "Moderator_xuids", string.Empty));
xuids.Add(GetServerCFG("Permission", "Senior_Moderator_xuids", string.Empty));
xuids.Add(GetServerCFG("Permission", "Trainee_Moderator_xuids", string.Empty));
}
/// <summary>
/// Executes when a client types something into the chat, currently we are listening for the
/// "!admins" command
/// </summary>
/// <param name="Message"></param>
/// <param name="Client"></param>
/// <param name="TeamChat"></param>
/// <returns></returns>
public override ChatType OnSay(string Message, ServerClient Client, bool TeamChat)
{
if (Message.StartsWith("!admins"))
{
List<string> found = new List<string>();
string message;
int total = 0;
// Get all the clients currently on the server
List<ServerClient> clients = GetClients();
foreach (ServerClient client in clients)
{
// Run through the xuids (if any) and determine if any currently online clients are
// part of the permission groups
foreach (string list in xuids)
{
if (list.Contains(client.XUID))
{
found.Add(client.Name);
total++;
}
}
}
// Are there any clients online that had a valid XUID?
if (total == 0)
{
message = "^2No Admins or Mods are ^1ONLINE ^2on this server";
}
else
{
message = (total == 1) ? "^2Admin^1/^2Mod ^1[ {0} ] ^2is online" : "^2Admins ^1& ^2Mods ^1[ {0} ] ^2are online";
message = string.Format(message, string.Join(", ", found.ToArray()));
}
iPrintLnBold(message, Client);
return ChatType.ChatNone;
}
return ChatType.ChatContinue;
}
}
}RE: Show Admins - Dr3am95 - 02-02-2013 Ive already the !admin pluginwho show the admins in the server, but i dont want to show the mods into the !admin command . Can u make me guys a plugin (like !mods) which shows the mods who are online, Thanks a lot ;DD RE: Show Admins - EnVi Sweden Rocks - 02-02-2013 (02-02-2013, 15:48)Dr3am95 Wrote: Ive already the !admin pluginwho show the admins in the server, but i dont want to show the mods into the !admin command . Can u make me guys a plugin (like !mods) which shows the mods who are online, here u got !mods plugin, enjoy (changed he's code little) PHP Code: using Addon;
using System;
using System.Collections;
using System.Collections.Generic;
namespace ShowModerators
{
public class ShowAdmins : CPlugin
{
// The list for the XUIDs to be stored in
private List<string> xuids = new List<string>();
/// <summary>
/// Executes when the server has successfully loaded
/// </summary>
public override void OnServerLoad()
{
ServerPrint("Plugin ShowModerators loaded!");
// Get all the XUIDs from the configuration
xuids.Add(GetServerCFG("Permission", "Moderator_xuids", string.Empty));
}
/// <summary>
/// Executes when a client types something into the chat, currently we are listening for the
/// "!admins" command
/// </summary>
/// <param name="Message"></param>
/// <param name="Client"></param>
/// <param name="TeamChat"></param>
/// <returns></returns>
public override ChatType OnSay(string Message, ServerClient Client, bool TeamChat)
{
if (Message.StartsWith("!mods"))
{
List<string> found = new List<string>();
string message;
int total = 0;
// Get all the clients currently on the server
List<ServerClient> clients = GetClients();
foreach (ServerClient client in clients)
{
// Run through the xuids (if any) and determine if any currently online clients are
// part of the permission groups
foreach (string list in xuids)
{
if (list.Contains(client.XUID))
{
found.Add(client.Name);
total++;
}
}
}
// Are there any clients online that had a valid XUID?
if (total == 0)
{
message = "^2No Mods are ^1ONLINE ^2on this server";
}
else
{
message = (total == 1) ? "^2Moderator ^1[ {0} ] ^2is online" : "^2Mods ^1[ {0} ] ^2are online";
message = string.Format(message, string.Join(", ", found.ToArray()));
}
iPrintLnBold(message, Client);
return ChatType.ChatNone;
}
return ChatType.ChatContinue;
}
}
}
RE: Show Admins - Dr3am95 - 02-02-2013 (02-02-2013, 16:08)EnVi Sweden Rocks Wrote:Thanks a lot!!! I gave u some points(02-02-2013, 15:48)Dr3am95 Wrote: Ive already the !admin pluginwho show the admins in the server, but i dont want to show the mods into the !admin command . Can u make me guys a plugin (like !mods) which shows the mods who are online, DD
RE: Show Admins - supernuke - 02-16-2013 I have a Problem, with this Plugin. Its works fine but the displayed txt its to fast, nothing can read ?!
RE: Show Admins - EnVi Sweden Rocks - 02-16-2013 it is then it is too many mods/admins will it shows really fast. i dont know why. RE: Show Admins - supernuke - 02-17-2013 I think the display txt can show only one line. If there are to many Admins/ Mods, it needs 2 lines..... This can be ?! |