#include <amxmodx>
#include <reapi>
new const PLUGIN_NAME[] = "Block flooding change nickname";
new const PLUGIN_VERSION[] = "0.1";
new const PLUGIN_AUTHOR[] = "bizon";
const Float: TIME_CHANGE_NAME_DELAY = 120.0; // Через сколько секунд можно вновь изменить ник
new Float: g_fTimeNextChangeNick[MAX_PLAYERS+1];
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
RegisterHookChain(RG_CBasePlayer_SetClientUserInfoName, "@CBasePlayer_SetClientUserInfoName_Pre");
}
@CBasePlayer_SetClientUserInfoName_Pre(pPlayer, const sInfoBuffer[], const sNewName[])
{
new Float: fGameTime;
fGameTime = get_gametime();
if(g_fTimeNextChangeNick[pPlayer] < fGameTime)
{
g_fTimeNextChangeNick[pPlayer] = fGameTime + TIME_CHANGE_NAME_DELAY;
return HC_CONTINUE;
}
static Float: fNextMessageTime[MAX_PLAYERS+1];
if(fNextMessageTime[pPlayer] < fGameTime)
{
static
iSeconds,
sCeconds[16];
iSeconds = floatround(g_fTimeNextChangeNick[pPlayer] - fGameTime);
if(iSeconds > 60)
{
new
iMinutes,
sMinutes[16];
iMinutes = iSeconds / 60
iSeconds = iSeconds % 60;
correct_word_minutes(iMinutes, sMinutes, charsmax(sMinutes));
correct_word_seconds(iSeconds, sCeconds, charsmax(sCeconds));
client_print_color(pPlayer, print_team_default, "^1[^4Block^1] Сменить ник можно через^4 %i %s ^1и^4 %i %s", iMinutes, sMinutes, iSeconds, sCeconds);
}
else
{
correct_word_seconds(iSeconds, sCeconds, charsmax(sCeconds));
client_print_color(pPlayer, print_team_default, "^1[^4Block^1] Сменить ник можно через^4 %i %s", iSeconds, sCeconds);
}
fNextMessageTime[pPlayer] = fGameTime + 1.0;
}
static sCurName[MAX_AUTHID_LENGTH];
get_user_name(pPlayer, sCurName, charsmax(sCurName));
set_entvar(pPlayer, var_netname, sCurName);
set_user_info(pPlayer, "name", sCurName);
SetHookChainArg(3, ATYPE_STRING, sCurName);
SetHookChainReturn(ATYPE_BOOL, false);
return HC_SUPERCEDE;
}
enum _:
{
Plural,
Singular,
Nominative
};
stock correct_word_minutes(iSeconds, sWords[], iWordsLen)
{
switch(get_numerical_noun_form(iSeconds))
{
case Plural: format(sWords, iWordsLen, "минут");
case Singular: format(sWords, iWordsLen, "минуты");
case Nominative: format(sWords, iWordsLen, "минуту");
}
}
stock correct_word_seconds(iSeconds, sWords[], iWordsLen)
{
switch(get_numerical_noun_form(iSeconds))
{
case Plural: format(sWords, iWordsLen, "секунд");
case Singular: format(sWords, iWordsLen, "секунды");
case Nominative: format(sWords, iWordsLen, "секунду");
}
}
// https://dev-cs.ru/threads/222/#post-2364
// by hunter
stock get_numerical_noun_form(iNum)
{
if(iNum > 10 && ((iNum % 100) / 10) == 1)
return Plural;
switch (iNum % 10)
{
case 1: return Nominative;
case 2, 3, 4: return Singular;
}
return Plural;
}