/**
* Nick Change Menu original idea by Mikhail Smirnov
* by serfreeman1337 http://gf.hldm.org/
**/
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Nick Change Menu"
#define VERSION "0.1.1"
#define AUTHOR "serfreeman1337"
const menu_keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9
#if AMXX_VERSION_NUM < 183
#define MAX_PLAYERS 33
ArrayFindValue(Array:which,cell)
{
for(new i,length = ArraySize(which) ; i < length ; i++)
{
if(ArrayGetCell(which,i) == cell)
return i
}
return -1
}
#endif
new player_menudata[MAX_PLAYERS][9]
new Array:players_array
new Array:nick_names
new is_colored
new pcvar_nicks
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("amx_nickmenu","Cmd_OpenMenu",ADMIN_SLAY,"- opens nick change menu")
register_clcmd("new_nick","Cmd_AddNewNick",ADMIN_SLAY)
pcvar_nicks = register_cvar("amx_nickmenu_var","Player;The Suspect;VOLODYA")
register_menu("ChangeNickMenu",
menu_keys,
"Menu_Handler"
)
register_dictionary("common.txt")
register_dictionary("nickchange_menu.txt")
is_colored = colored_menus()
}
public plugin_cfg()
{
players_array = ArrayCreate()
new nick_string[512]
get_pcvar_string(pcvar_nicks,nick_string,charsmax(nick_string))
new stPos,ePos,nick[32]
// parse levels entry
do {
ePos = strfind(nick_string[stPos],";")
formatex(nick,ePos,nick_string[stPos])
if(nick[0])
{
if(!nick_names)
nick_names = ArrayCreate(32)
ArrayPushString(nick_names,nick)
}
stPos += ePos + 1
} while (ePos != -1)
}
public Cmd_OpenMenu(id,level,cid)
{
if(!cmd_access(id,level,cid,0))
return PLUGIN_HANDLED
Menu_Show(id)
return PLUGIN_HANDLED
}
public Cmd_AddNewNick(id,level,cid)
{
if(!cmd_access(id,level,cid,0))
return PLUGIN_HANDLED
new args[34]
read_args(args,charsmax(args))
remove_quotes(args)
trim(args)
if(!args[0])
{
return Menu_Show(id)
}
if(!nick_names)
nick_names = ArrayCreate(32)
ArrayPushString(nick_names,args)
client_print(id,print_chat,"%L",id,"NEW_NICK_NOTIFY2",args)
return Menu_Show(id)
}
/**
* Add players to array
*/
public client_putinserver(id)
{
Update_ArrayPos(id)
}
/**
* Remove player from array
*/
public client_disconnect(id)
{
new pos
if((pos = ArrayFindValue(players_array,id)) != -1)
{
ArrayDeleteItem(players_array,pos)
}
}
/**
* Shift up a cell to array top on player nick change
*/
public client_infochanged(id)
{
new arg1[4]
read_argv(0,arg1,charsmax(arg1))
if(arg1[0] == 's' && arg1[1] == 'e' && arg1[2] == 't')
{
new arg2[4]
read_argv(1,arg2,charsmax(arg2))
if(arg2[0] == 'n' && arg2[1] == 'a' && arg2[2] == 'm')
{
Update_ArrayPos(id)
}
}
}
/**
* Shift up a cell to array top
*/
Update_ArrayPos(cell)
{
new pos
if((pos = ArrayFindValue(players_array,cell)) != -1)
{
ArrayDeleteItem(players_array,pos)
}
ArraySize(players_array) ? ArrayInsertCellBefore(players_array,0,cell) : ArrayPushCell(players_array,cell)
}
/**
* Show main menu for player
* id - player id
* page - menu page
*/
Menu_Show(id,page = 0)
{
player_menudata[id][7] = page
new keys = menu_keys
new menu_text[1024],len
new pnum = ArraySize(players_array)
len += formatex(menu_text[len],charsmax(menu_text) - len,"%s%L^n^n",
is_colored ? "\y" : "",
id,"NICK_MENU")
// build players list
for(new i = 7 * page, name[32],pos,player_id ; i < min(pnum,7 * (page + 1)); i++)
{
player_id = ArrayGetCell(players_array,i)
// remember players for menu
pos = i - (7 * page)
player_menudata[id][pos] = player_id
get_user_name(player_id,name,charsmax(name))
len += formatex(menu_text[len],charsmax(menu_text) - len,"%s%d. %s%s^n",
is_colored ? "\r" : "",
pos + 1,
is_colored ? "\w" : "",
name)
}
len += formatex(menu_text[len],charsmax(menu_text) - len,"^n%s8. %s%s^n^n",
is_colored ? "\r" : "",
is_colored ? "\w" : "",
Switcher_Vodka(id))
// add "NEXT" button
if(pnum > 7 * (page + 1))
len += formatex(menu_text[len],charsmax(menu_text) - len,"%s9. %s%L^n",
is_colored ? "\r" : "",
is_colored ? "\w" : "",
id,"MORE")
else // no "NEXT" button for this page
{
keys ^= MENU_KEY_9
}
len += formatex(menu_text[len],charsmax(menu_text) - len,"%s0. %s%L",
is_colored ? "\r" : "",
is_colored ? "\w" : "",
id,page ? "BACK" : "EXIT")
show_menu(id,keys,menu_text,-1,"ChangeNickMenu")
return PLUGIN_HANDLED
}
Switcher_Vodka(id)
{
new msg[64]
if(!nick_names)
{
formatex(msg,charsmax(msg),"%L",id,"NEW_NICK")
}
else
{
if(player_menudata[id][8] >= ArraySize(nick_names))
formatex(msg,charsmax(msg),"%L",id,"NEW_NICK")
else
formatex(msg,charsmax(msg),"%L %s%a",id,"CHANGE_NICK",
is_colored ? "\y" : "",
ArrayGetStringHandle(nick_names,player_menudata[id][8]))
}
return msg
}
/**
* Menu action handler
*/
public Menu_Handler(id,key)
{
switch(key)
{
case 7: // hz kak nazvatb button
{
if(nick_names)
{
if(player_menudata[id][8] > ArraySize(nick_names) - 1)
player_menudata[id][8] = 0
else
player_menudata[id][8]++
}
Menu_Show(id,player_menudata[id][7])
}
case 8: // next button
{
if(ArraySize(players_array) > 7 * (player_menudata[id][7]+ 1))
Menu_Show(id,player_menudata[id][7] + 1)
}
case 9: // back or exit button
{
if(player_menudata[id][7]) // back
Menu_Show(id,player_menudata[id][7] - 1)
}
default:
{
if(player_menudata[id][8] > ArraySize(nick_names) - 1)
{
client_print(id,print_chat,"%L",id,"NEW_NICK_NOTIFY1")
client_cmd(id,"messagemode new_nick")
return
}
new player_id = player_menudata[id][key]
if(!is_user_connected(player_id)) // target player disconnected
{
Menu_Show(id)
return
}
new arg2[32],authid[32], name[32], authid2[32], name2[32]
get_user_authid(id, authid, charsmax(authid))
get_user_name(id, name, charsmax(name))
get_user_authid(player_id, authid2, charsmax(authid2))
get_user_name(player_id, name2, charsmax(name2))
ArrayGetString(nick_names,player_menudata[id][8],arg2,charsmax(arg2))
set_user_info(player_id,"name",arg2)
log_amx("Cmd: ^"%s<%d><%s><>^" change nick to ^"%s^" ^"%s<%d><%s><>^"", name, get_user_userid(id), authid, arg2, name2, get_user_userid(player_id), authid2)
show_activity_key("ADMIN_NICK_1", "ADMIN_NICK_2", name, name2, arg2)
Menu_Show(id,player_menudata[id][7])
}
}
}
#if AMXX_VERSION_NUM < 182
public plugin_precache() // i don't support outdated software
{
new lang[3]
get_cvar_string("amx_language",lang,charsmax(lang))
if(lang[0] != 'r' && lang[1] != 'u')
{
log_amx("This plugin requires AMXX182 or higher. Compile it with AMXX182 compiler please, on http://aghl.ru/webcompiler/ for example.")
log_amx("But for now i shutdown your server to prevent further damage to amxx community.")
}
else
{
log_amx("SUKA BLYATB OBNOVI AMXX, MUDLO!1!!!!111")
}
server_cmd("quit")
server_exec() // shutdown with TERRIBLE DAMAGE
}
#endif