the ideea is that if a player connects with a name like: server.ro to my server i want to make his name: unnamed and disconnect him and after disconnect him, to print in client console a message asking him to connect after he changes his name... ( and also if the word "server" is part of his name it would react the same...) also i want the plugin to see if the player changes his name in game, search thru the list of restricted names and if is the same as with one of the restricted names turn it back to the old one...
here is what i made until now..
and pelase don`t tell me not to reinvent a plugin... i just want to learn and this i can learn only redoing some plugins...[yeah, i know a lot of plugins that do almost the same thing.. but i want to know what i`m doing wrong... here ]
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Name Restriction"
#define VERSION "0.1"
#define AUTHOR "DarKMaN"
//---------DEFINES------------
//Define max names from file.
#define MAXNAMES 60
new NumberOfNamesFromFile = 0
//Rember names from file to compare with players.
new names[MAXNAMES][]
//If user is with name from list, change it to:
#define SETNAME "unnamed"
//---------END OF DEFINES ----
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
LoadNameRestFile()
}
stock LoadNameRestFile()
{
new filepath[64]
get_configsdir(filepath, 63);
format(filepath, 63, "%s/namerestriction.ini", filepath);
if(file_exists(filepath))
{
new name[32];
//Open file
new fHandle = fopen(filepath, "rt");
//Checks for failure
if(!fHandle)
return PLUGIN_HANDLED;
//LOOP THRU LINES
for(new a = 0; a < MAXNAMES && !feof(fHandle); a++)
{
//Get line
fgets(fHandle, name, 31);
//Work away comments
if(name[0] == ';' || !name[0] || name[0] == ' ' || name[0] == 10)
{
//Line is not counted
a--;
continue;
}
copy(names[a], 31, name)
NumberOfNamesFromFile++;
}
}
return PLUGIN_CONTINUE;
}
public client_connects(id)
{
if(NumberOfNamesFromFile == 0 )
return PLUGIN_HANDLED
else
{
new playerconnects[32]
get_user_info(id, "name", playerconnects, 31)
for(new i=0; i < NumberOfNamesFromFile ; i++)
if(equali(playerconnects, names[i][]))
changeName(id)
else
{
checkIFnameISpartial(names[i], playerconnects, id)
}
}
return PLUGIN_HANDLED
}
public client_infochanged(id)
{
new newname[32],oldname[32]
get_user_info(id, "name", newname,31)
get_user_name(id, oldname, 31)
if(equali(newname,oldname))
return PLUGIN_HANDLED;
else
{
for(new i = 0; i < NumberOfNamesFromFile ; i++ )
if(equali(names[i],newname))
changeNameInGame(id, oldname)
else
checkIFnameISpartialINGAME(names[i], newname, id, oldname)
}
return PLUGIN_HANDLED
}
stock changeName(id)
{
client_cmd(id, "name %s", SETNAME)
client_cmd(id, "echo [DNK BOT] Kicked because:")
client_cmd(id, "echo [DNK BOT] Numele tau a fost schimbat in ^"%s^". Te rog conecteaza-te dupa ce ti-ai schimbat numele.", SETNAME)
client_cmd(id, "disconnect")
return PLUGIN_HANDLED
}
stock changeNameInGame(id, ChangeNameTo[])
{
client_cmd(id, "name %s", ChangeNameTo)
client_print(id, print_chat,"[DNK BOT] Nume interzis! Numele tau a fost schimbat in ^"%s^".", ChangeNameTo)
return PLUGIN_HANDLED
}
stock checkIFnameISpartial(Vector1[], Vector2[], id)
{
new pcnum = charsmax( Vector2 )
new numb = charsmax( Vector1 )
new OK = 0
new k = 0
for(new i = 0; i < pcnum; i++)
{
if(equali(Vector2[i], Vector1[k]))
k++
OK++
}
if(equali(OK,numb))
changeName(id)
return PLUGIN_CONTINUE;
}
stock checkIFnameISpartialINGAME(Vector1[], Vector2[], id, oldname2[])
{
new pcnum = charsmax( Vector2 )
new numb = charsmax( Vector1 )
new OK = 0
new k = 0
for(new i = 0; i < pcnum; i++)
{
if(equali(Vector2[i], Vector1[k])
k++
OK++
}
if(equali(OK,numb))
changeNameInGame(id, oldname2)
return PLUGIN_CONTINUE;
}