/**
* 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
[ru]
CHANGE_NICK = Сменить ник на
NEW_NICK = Добавить ник
NEW_NICK_NOTIFY1 = Введите новый ник...
NEW_NICK_NOTIFY2 = Ник "%s" был добавлен.
NICK_MENU = Ник меню
[en]
CHANGE_NICK = Change nick to
NEW_NICK = Add new nick
NEW_NICK_NOTIFY1 = Please input new nick...
NEW_NICK_NOTIFY2 = New nick "%s" has been added.
NICK_MENU = Nick menu
amx_nickmenu_var "Смени Ник;Noob;Рак" // и т.д
вот решение на вопросKomap, только в табе нет нельзя, можно поменять везде. Ну разве что только в чате использовать старое и то нужно править код чм.
#include <amxmodx>
#include <cstrike>
#include <reapi>
#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32;
#endif
#if !defined MAX_NAME_SIZE
const MAX_NAME_SIZE = 32;
#endif
// who's whom
new Float:g_playerDamage[MAX_PLAYERS + 1][MAX_PLAYERS + 1];
new HookChain:g_deathNoticePostHook;
public plugin_init() {
if (!is_regamedll() || !is_rehlds()) {
set_fail_state("Needs CS ReGameDLL and ReHLDS");
}
RegisterHookChain(RG_CBasePlayer_Spawn, "OnPlayerSpawn_Post", true);
RegisterHookChain(RG_CBasePlayer_TakeDamage, "OnPlayerTakeDamage_Post", true);
RegisterHookChain(RG_CSGameRules_DeathNotice, "OnDeathNotice", false);
g_deathNoticePostHook = RegisterHookChain(RG_CSGameRules_DeathNotice, "OnDeathNotice_Post", true);
DisableHookChain(g_deathNoticePostHook);
}
public client_connect(playerEntIndex) {
arrayset(_:g_playerDamage[playerEntIndex], 0, sizeof(g_playerDamage[]));
}
public OnPlayerSpawn_Post(playerEntIndex) {
for (new i = 1; i <= MAX_PLAYERS; i++) {
g_playerDamage[i][playerEntIndex] = 0.0;
}
}
public OnPlayerTakeDamage_Post(playerEntIndex, inflictorEntIndex, attackerEntIndex, Float:damage, damageType) {
if (attackerEntIndex != playerEntIndex
&& is_user_connected(attackerEntIndex)
&& !IsTeammates(attackerEntIndex, playerEntIndex))
{
g_playerDamage[attackerEntIndex][playerEntIndex] += damage;
}
}
public OnDeathNotice(victimEntIndex, killerEntIndex, inflictorEntIndex) {
if (killerEntIndex != victimEntIndex
&& is_user_connected(killerEntIndex)
&& !IsTeammates(killerEntIndex, victimEntIndex))
{
new Float:maxDamage = 0.0;
new bestAttackerEntIndex = 0;
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (g_playerDamage[i][victimEntIndex] > maxDamage) {
maxDamage = g_playerDamage[i][victimEntIndex];
bestAttackerEntIndex = i;
}
}
// Assistant must have more damage than killer
if (bestAttackerEntIndex != killerEntIndex
&& is_user_connected(bestAttackerEntIndex)
&& !IsTeammates(bestAttackerEntIndex, victimEntIndex)
&& cs_get_user_team(bestAttackerEntIndex) != CS_TEAM_SPECTATOR)
{
new name1[MAX_NAME_SIZE], name2[MAX_NAME_SIZE], name[MAX_NAME_SIZE];
get_user_name(killerEntIndex, name1, charsmax(name1));
get_user_name(bestAttackerEntIndex, name2, charsmax(name2));
// TODO: cut nicknames if big length (> 14) and add ...
// TODO: UTF-8 cut correctly
if (strlen(name1) + strlen(name2) > 28) {
formatex(name, charsmax(name), "%.14s + %.14s", name1, name2);
} else {
formatex(name, charsmax(name), "%s + %s", name1, name2);
}
message_begin(MSG_ALL, SVC_UPDATEUSERINFO);
write_byte(killerEntIndex - 1);
write_long(get_user_userid(killerEntIndex));
write_char('\');
write_char('n');
write_char('a');
write_char('m');
write_char('e');
write_char('\');
write_string(name);
for (new i = 0; i < 16; i++) {
write_byte(0);
}
message_end();
EnableHookChain(g_deathNoticePostHook);
}
}
}
public OnDeathNotice_Post(victimEntIndex, killerEntIndex, inflictorEntIndex) {
rh_update_user_info(killerEntIndex);
DisableHookChain(g_deathNoticePostHook);
}
bool:IsTeammates(lhsPlayerEntIndex, rhsPlayerEntIndex) {
static pCvarFreeForAll = 0;
if (!pCvarFreeForAll) {
pCvarFreeForAll = get_cvar_pointer("mp_freeforall");
}
return !get_pcvar_num(pCvarFreeForAll) && cs_get_user_team(lhsPlayerEntIndex) == cs_get_user_team(rhsPlayerEntIndex);
}
@changeName(iTask) {
new iPlayer; iPlayer = iTask - iTask_Player;
new szName[33]; get_user_name(iPlayer, szName, charsmax(szName));
new szBuffer[64]; formatex(szBuffer, charsmax(szBuffer), "[LVL %d] %s", rpgApi_getUser(iPlayer, RPGDATA_LVL), szName);
message_begin(MSG_ALL, SVC_UPDATEUSERINFO);
write_byte(iPlayer - 1);
write_long(get_user_userid(iPlayer));
write_char('\');
write_char('n');
write_char('a');
write_char('m');
write_char('e');
write_char('\');
write_string(szBuffer);
for (new i = 0; i < 16; i++) {
write_byte(0);
}
message_end();
}
}