Didnt add the gagmenu. optimize a little bit i hope it doesnt cause errors ingame.
Added logs to.
Code:
#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
#include <nvault>
#include <colorchat>
#define PLUGIN "Admin Menu HNS (AmxBans)"
#define VERSION "2.0"
#define AUTHOR "SnusMumrikeN"
#define TAG "[MD]"
#define ADMIN_LEVEL ADMIN_BAN
new const BanName[][64] = {
"1 Hour",
"2 Hour",
"Day",
"Week",
"Month"
}
new const BanTime[][64] = {
60,
120,
1440,
10080,
43200
}
new Style[ 33 ], Reason[ 33 ][ 51 ], Name[ 33 ], g_BanTime[ 33 ], Name2[ 33 ], Name3[ 33 ]
new gVault, g_iWarningsCount[ 33 ], gSteamID[ 32 ], vKey[ 64 ], vData[ 64 ];
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd ( "say /admin", "CmdMainMenu" )
register_clcmd ( "type_reason", "CmdReason" )
register_clcmd( "nightvision", "CmdMainMenu" );
}
public CmdMainMenu(id)
{
if(!(get_user_flags( id ) & ADMIN_LEVEL ) )
{
ColorChat(id, GREY, "^4%s^3 You need to be^4 admin^3 to use this menu!", TAG)
return PLUGIN_HANDLED
}
new title[512]; formatex(title, sizeof(title) - 1, "\r%s\y Admin Menu^n Choose a Category", TAG )
new menu = menu_create(title, "MainMenuHandle");
//Create Items Menu
menu_additem(menu, "Slay Player", "1", 0);
menu_additem(menu, "Kick Player", "2", 0);
menu_additem(menu, "Ban Player", "3", 0);
menu_additem(menu, "Gag Player", "4", 0);
menu_additem(menu, "Give Player Warning", "5", 0);
menu_additem(menu, "Change Player Nick", "6", 0);
menu_additem(menu, "Transfer Player", "7", 0);
//Display the menu
menu_display(id, menu, 0);
return PLUGIN_HANDLED
}
public MainMenuHandle(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
Style[id] = 0 // Slay
PlayerList(id)
}
case 2:
{
Style[id] = 1 // Kick
PlayerList(id)
}
case 3:
{
Style[id] = 2 // Ban
PlayerList(id)
}
case 4: client_cmd(id, "amx_gagmenu"); //Gag
case 5:
{
Style[id] = 3 // Warning
PlayerList(id)
}
case 6:
{
Style[id] = 4 // Nick
PlayerList(id)
}
case 7:
{
Style[id] = 5 // Transfer
PlayerList(id)
}
}
return PLUGIN_HANDLED;
}
public PlayerList(id) {
new Playermenu, Temp[64]
formatex(Temp, charsmax(Temp), "\r%s\y Admin Menu^n Choose a Player", TAG )
Playermenu = menu_create(Temp, "PlayerHandler");
new players[32], pnum, tempid;
new szName[32], szTempid[10];
get_players(players, pnum, "ch");
for( new i; i<pnum; i++ )
{
tempid = players[i];
get_user_name(tempid, szName, charsmax(szName));
num_to_str(tempid, szTempid, charsmax(szTempid));
formatex(Temp, charsmax( Temp ), "%s%s", szName, get_user_flags( tempid ) & ADMIN_LEVEL ? " - \d[\rImmunity\d]" : "");
menu_additem(Playermenu, Temp, szTempid, 0);
}
menu_display(id, Playermenu);
return PLUGIN_HANDLED;
}
public PlayerHandler(id, menu, item) {
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
Name[id] = str_to_num(data);
if(get_user_flags( Name[id] ) & ADMIN_LEVEL && id != Name[id] && get_user_flags( id ) & ADMIN_RCON)
{
ColorChat(id, GREY, "^4%s^3 You cant do actions on a^4 admin^3", TAG)
CmdMainMenu(id)
return PLUGIN_HANDLED
}
if(Style[id] != 2) client_cmd(id, "messagemode type_reason")
else BanList(id);
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public BanList(id) {
new menu, Temp[64]
formatex(Temp,63, "\r%s\y Admin Menu^n Choose Time", TAG )
menu = menu_create(Temp, "BanHandler");
new key[20]
for(new i=0; i < sizeof(BanName); i++)
{
num_to_str(i,key,sizeof(key)-1)
menu_additem(menu, BanName[i], key);
}
menu_display(id, menu, 0);
}
public BanHandler(id, menu, key) {
if( key == MENU_EXIT ) {
menu_destroy(menu);
return PLUGIN_HANDLED;
}
g_BanTime[id] = key
client_cmd(id, "messagemode type_reason");
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public CmdReason(id) {
if((get_user_flags( id ) & ADMIN_LEVEL ) )
{
new zReason[50]
read_argv(1,zReason,charsmax(zReason))
copy(Reason[id],charsmax(zReason), zReason)
get_user_name(id, Name2, charsmax(Name2))
get_user_name(Name[id], Name3, charsmax(Name3))
switch(Style[id])
{
case 0: SlayPlayer(id) // Slay
case 1: KickPlayer(id) // Kick
case 2: BanPlayer(id) // Ban
case 3: WarnPlayer(id) // Warning
case 4: ChangeNickPlayer(id) // Nick
case 5: TransferPlayer(id) // Transfer
}
}
}
public SlayPlayer(id) {
if(is_user_alive(Name[id]))
{
user_kill(Name[id])
ColorChat(0, GREY, "^4%s %s^3 slayed^4 %s^3 for ^4%s", TAG, Name2, Name3, Reason[id])
new message[200], Time[64]
get_time("%c", Time, charsmax(Time))
format ( message, charsmax(message), "[%s] %s slayed %s for %s", Time, Name2, Name3, Reason[id])
write_file ( "addons/amxmodx/logs/adminmenu.txt", message )
return PLUGIN_HANDLED;
}
else ColorChat(id, GREY, "^4%s %s^3 is already dead", TAG, Name3)
return PLUGIN_HANDLED;
}
public KickPlayer(id) {
if(is_user_connected(Name[id]))
{
client_cmd(id, "amx_kick #%d ^"Kicked by %s. Reason: %s^"",get_user_userid(Name[id]), Name2, Reason[id])
ColorChat(0, GREY, "^4%s %s^3 kicked^4 %s^3 for ^4%s", TAG, Name2, Name3, Reason[id])
new message[200], Time[64]
get_time("%c", Time, charsmax(Time))
format ( message, charsmax(message), "[%s] %s kicked %s for %s", Time, Name2, Name3, Reason[id])
write_file ( "addons/amxmodx/logs/adminmenu.txt", message )
return PLUGIN_HANDLED;
}
else ColorChat(id, GREY, "^4%s %s^3 is not connected", TAG, Name3)
return PLUGIN_HANDLED;
}
public BanPlayer(id) {
if(is_user_connected(Name[id]))
{
client_cmd(id, "amx_ban %d #%d ^"%s^"", BanTime[g_BanTime[id]], get_user_userid(Name[id]), Reason[id])
ColorChat(0, GREY, "^4%s %s^3 banned^4 %s^3 for ^4%s^3 (^4^%s^3)", TAG, Name2, Name3, Reason[id], BanName[g_BanTime[id]])
new message[200], Time[64]
get_time("%c", Time, charsmax(Time))
format ( message, charsmax(message), "[%s] %s banned %s for %s (%s)", Time, Name2, Name3, Reason[id], BanName[g_BanTime[id]])
return PLUGIN_HANDLED;
}
else ColorChat(id, GREY, "^4%s %s^3 is not connected", TAG, Name2)
return PLUGIN_HANDLED;
}
public ChangeNickPlayer(id) {
if(is_user_connected(Name[id]))
{
set_user_info(Name[id],"name",Reason[id])
ColorChat(0, GREY, "^4%s %s^3 changed^4 %s^3 name to ^4%s", TAG, Name2, Name3, Reason[id])
new message[200], Time[64]
get_time("%c", Time, charsmax(Time))
format ( message, charsmax(message), "[%s] %s changed %s name to %s", Time, Name2, Name3, Reason[id])
return PLUGIN_HANDLED;
}
else ColorChat(id, GREY, "^4%s %s^3 is not connected", TAG, Name3)
return PLUGIN_HANDLED;
}
public TransferPlayer(id) {
if(is_user_alive(Name[id]))
{
cs_set_user_team(Name[id], cs_get_user_team(Name[id]) == CS_TEAM_T ? CS_TEAM_CT : CS_TEAM_T);
ExecuteHamB(Ham_CS_RoundRespawn, Name[id]);
ColorChat(0, GREY, "^4%s %s^3 transfered^4 %s^3 to the other team. For ^4%s", TAG, Name2, Name3, Reason[id])
new message[200], Time[64]
get_time("%c", Time, charsmax(Time))
format ( message, charsmax(message), "[%s] %s transfered %s to the other team. For %s", Time, Name2, Name3, Reason[id])
return PLUGIN_HANDLED;
}
else ColorChat(id, GREY, "^4%s %s^3 is already dead", TAG, Name3)
return PLUGIN_HANDLED;
}
public WarnPlayer(id) {
new szAuthID[32]; get_user_authid(Name[id], szAuthID, charsmax(szAuthID));
if(is_user_connected(Name[id]))
{
g_iWarningsCount[Name[id]] += 1;
ColorChat(0, GREY, "^4%s %s^3 gave^4 %s^3 a warning for ^4%s^3 Total Warnings:^4 %i", TAG, Name2, Name3, Reason[id], g_iWarningsCount[Name[id]])
new message[200], Time[64]
get_time("%c", Time, charsmax(Time))
format ( message, charsmax(message), "[%s] %s gave %s a warning for %s Total Warnings: %i", Time, Name2, Name3, Reason[id], g_iWarningsCount[Name[id]])
if(g_iWarningsCount[Name[id]] == 5)
{
ColorChat(0, GREY, "^4%s %s^3 was banned^4 1 day^3 for having^4 5 warnings", TAG, Name3, g_iWarningsCount[Name[id]])
client_cmd(id, "amx_ban 1440 %s 5warnings", szAuthID)
return PLUGIN_HANDLED;
}
else if(g_iWarningsCount[Name[id]] == 10)
{
ColorChat(0, GREY, "^4%s %s^3 was banned^4 1 week^3 for having^4 10 warnings", TAG, Name3, g_iWarningsCount[Name[id]])
client_cmd(id, "amx_ban 10080 %s 10warnings", szAuthID)
return PLUGIN_HANDLED;
}
else if(g_iWarningsCount[Name[id]] == 20)
{
ColorChat(0, GREY, "^4%s %s^3 was banned^4 1 month^3 for having^4 20 warnings", TAG, Name3, g_iWarningsCount[Name[id]])
client_cmd(id, "amx_ban 43200 %s 20warnings", szAuthID)
return PLUGIN_HANDLED;
}
else if(g_iWarningsCount[Name[id]] == 30)
{
ColorChat(0, GREY, "^4%s %s^3 was banned^4 PERMANENT^3 for having^4 30 warnings", TAG, Name3, g_iWarningsCount[Name[id]])
client_cmd(id, "amx_ban 0 %s 30warnings", szAuthID)
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
else ColorChat(id, GREY, "^4%s %s^3 is not connected", TAG, Name3)
return PLUGIN_HANDLED;
}
public client_connect( id )
load_warnings( id )
public client_disconnect( id )
save_warnings( id )
stock save_warnings( index )
{
gVault = nvault_open( "Warnings" )
if( gVault == INVALID_HANDLE )
{
set_fail_state( "[Warnings] nValut ERROR: =-> Invalid-Handle" )
}
get_user_authid( index, gSteamID, charsmax( gSteamID ) )
formatex( vKey, charsmax( vKey ), "%sWARNINGS", gSteamID )
formatex( vData, charsmax( vData ), "%d", g_iWarningsCount[ index ] )
nvault_set( gVault, vKey, vData )
nvault_close( gVault )
}
stock load_warnings( index )
{
gVault = nvault_open( "Warnings" )
if( gVault == INVALID_HANDLE )
{
set_fail_state( "[Warnings] nValut ERROR: =-> Invalid-Handle" )
}
get_user_authid( index, gSteamID, charsmax( gSteamID ) )
formatex( vKey, charsmax( vKey ), "%sWARNINGS", gSteamID )
g_iWarningsCount[ index ] = nvault_get( gVault, vKey )
nvault_close( gVault )
}