Code: Select all
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Restrict Names"
#define VERSION "1.9"
#define AUTHOR "www.extreamcs.ro"
#define server "extreamcs"
new Array:g_Things = Invalid_Array
new g_NamesCount = 0
new g_Default = 0
new g_New = 0
new g_MinCaracters
new g_MaxCaracters
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_Default = register_cvar("amx_default_name", "extreamcs", FCVAR_PROTECTED)
g_New = register_cvar("amx_new_name", "CS-Player", FCVAR_PROTECTED)
g_MinCaracters = register_cvar("amx_min_name", "3", FCVAR_PROTECTED)
g_MaxCaracters = register_cvar("amx_max_name", "20", FCVAR_PROTECTED)
if(g_Default == 0)
{
return
}
static File, Location[256], ConfigurationFilesDirectory[128], Line[64]
get_localinfo("amxx_configsdir", ConfigurationFilesDirectory, charsmax(ConfigurationFilesDirectory))
formatex(Location, charsmax(Location), "%s/restrict_names.ini", ConfigurationFilesDirectory)
if(!file_exists(Location))
{
File = fopen(Location, "w+")
switch (File)
{
case 0:
{
}
default:
{
fclose(File)
}
}
}
File = fopen(Location, "r")
if(!File)
{
return
}
g_Things = ArrayCreate(64)
if(g_Things == Invalid_Array)
{
return
}
while(!feof(File))
{
fgets(File, Line, charsmax(Line))
trim(Line)
if(strlen(Line) && Line[0] != ';')
{
ArrayPushString(g_Things, Line)
}
}
fclose(File)
if(g_Things == Invalid_Array || !ArraySize(g_Things))
{
}
}
public client_putinserver(Client)
{
if(g_Things == Invalid_Array || !ArraySize(g_Things))
{
return
}
static Name[32], Default[32], Iterator, Thing[32], New[32]
get_user_name(Client, Name, charsmax(Name))
get_user_name(Client, Name, sizeof(Name)-1)
get_pcvar_string(g_Default, Default, charsmax(Default))
get_pcvar_string(g_New, New, charsmax(New))
if(containi(Name, Default) != -1)
{
return
}
if(strlen(Name) < get_pcvar_num(g_MinCaracters) || strlen(Name) >= get_pcvar_num(g_MaxCaracters))
{
formatex(Name, charsmax(Name), "%s [%d]", New, ++g_NamesCount)
set_user_info(Client, "name", Name)
client_cmd(Client, "name ^"%s^"", Name)
}
for(Iterator = 0; Iterator < ArraySize(g_Things); Iterator++)
{
ArrayGetString(g_Things, Iterator, Thing, charsmax(Thing))
if(containi(Name, Thing) != -1)
{
formatex(Name, charsmax(Name), "%s [%d]", New, ++g_NamesCount)
set_user_info(Client, "name", Name)
client_cmd(Client, "name ^"%s^"", Name)
break
}
}
}
public client_infochanged(Client)
{
if(g_Things == Invalid_Array || !ArraySize(g_Things))
{
return
}
static OldName[32], Name[32], Default[32], Iterator, Thing[32], New[32]
get_user_name(Client, OldName, charsmax(OldName))
get_user_name(Client, OldName, sizeof(OldName)-1)
get_pcvar_string(g_Default, Default, charsmax(Default))
get_user_info(Client, "name", Name, charsmax(Name))
get_pcvar_string(g_New, New, charsmax(New))
if(equali(Name, OldName))
{
return
}
if(containi(Name, Default) != -1)
{
return
}
if(strlen(Name) < get_pcvar_num(g_MinCaracters) || strlen(Name) >= get_pcvar_num(g_MaxCaracters))
{
formatex(Name, charsmax(Name), "%s [%d]", New, ++g_NamesCount)
set_user_info(Client, "name", Name)
client_cmd(Client, "name ^"%s^"", Name)
color_chat(Client, "^x04[%s]^x01 You must have between^x03 3^x01 and^x03 20^x01 characters in your name.", server)
client_print(Client, print_center, "Your name is to short or to long!")
}
for(Iterator = 0; Iterator < ArraySize(g_Things); Iterator++)
{
ArrayGetString(g_Things, Iterator, Thing, charsmax(Thing))
if(containi(Name, Thing) != -1)
{
formatex(Name, charsmax(Name), "%s [%d]", New, ++g_NamesCount)
set_user_info(Client, "name", Name)
client_cmd(Client, "name ^"%s^"", Name)
break
}
}
}
stock color_chat(const id, const input[], any:...)
{
new count = 1, players[32]
static msg[191]
vformat(msg, 190, input, 3)
replace_all(msg, 190, "^x01", "^1")
replace_all(msg, 190, "^x03", "^3")
replace_all(msg, 190, "^x04", "^4")
if(id) players[0] = id; else get_players(players, count, "ch")
{
for(new i = 0; i < count; i++)
{
if(is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
write_byte(players[i])
write_string(msg)
message_end()
}
}
}
}