Help with a /ban cmd -
tomnidi - 12.02.2009
I need help to create a /ban cmd.
I searched in a lot of GMs and all I found its a /ban CMD that bans your IP.
I need a help to make a normal /ban CMD that will make a file in the ScritpFiles, and after I will /ban someone's name, its will be saved there and he will not be able to connect with this name.
I really need this help, I got only /banip CMD, and there is no /ban CMD in my GM.
Help please.
Re: Help with a /ban cmd -
[RP]Rav - 12.02.2009
Код:
if (strcmp(cmdtext, "/ban", true) == 0)
{
// other code goes here
new File: file, playername[32],filename[36];
GetPlayerName(playerid, playername, 32);
format (filename, 36, "%s.ban", playername);
file = fopen(filename, io_readwrite);
fwrite(file, "1"); // make sure it's filled with something, doesn't really matter though
fclose(file);
return 1;
}
Код:
// in OnPlayerConnect
new playername[32],filename[36];
GetPlayerName(playerid, playername, 32);
format (filename, 36, "%s.ban", playername);
if (fexist(filename))
Ban(playerid); // or kick, whatever you want
Re: Help with a /ban cmd -
tomnidi - 12.02.2009
Thanks, But what file should I create and what to write in?
Re: Help with a /ban cmd -
MenaceX^ - 12.02.2009
You shouldn't create any file or else you want the ban will be saves.
Use ReturnUser function and bigstrtok if you want it with a reason /ban [playerid] [reason]
Re: Help with a /ban cmd -
tomnidi - 12.02.2009
Hmm.. I want to use /ban [playerid] [reason] to ban
player's name,,
I want him to be viable to register with another accounts,
Re: Help with a /ban cmd -
[RP]Rav - 12.02.2009
use my code above in your ban command, it's exactly what you requested..
Re: Help with a /ban cmd -
Think - 12.02.2009
pawn Код:
(top of script)
new playername[30];
new sendername[30];
new giveplayer[30];
new string[128];
enum Ban
{
Banned,
};
new Banned[MAX_PLAYERS][Ban];
(OnPlayerConnect)
new File: file = fopen(string, io_read);
if (file)
{
fread(file, valtmp);Banned[playerid][Ban] = strval(valtmp);DelPrint(valtmp);
if(Banned[playerid][Ban] == 1)
{
SendClientMessage(playerid, COLOR_(ADD YOUR COLOR HERE), "Your banned.");
Kick(playerid); (or Ban(playerid); )
}
fclose(file);
return 1;
}
Banned[playerid][Ban] = 0;
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "/%s.txt", playername);
new File:hFile;
hFile = fopen(string, io_append);
format(var, 32, "%d Ban\n", Banned[playerid][Ban]);fwrite(hFile, var);
(On player command text)
if(strcmp(cmd, "/ban", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_(ADD YOUR COLOR HERE, "USAGE: /ban [playerid] [reason]");
return 1;
}
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new reason[64];
while ((idx < length) && ((idx - offset) < (sizeof(reason) - 1)))
{
reason[idx - offset] = cmdtext[idx];
idx++;
}
reason[idx - offset] = EOS;
new playa = strval(tmp);
GetPlayerName(playa, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
if ((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][pAdmin] >= 1)
{
format(string, sizeof(string), "AdmCmd: %s Banned %s's name. Reason: %s",sendername, giveplayer, reason);
printf("%s",string);
SendClientMessageToAll(COLOR HERE, string);
Banned[playerid][Ban] = 1;
Kick(playerid);
return 1;
}
else
{
SendClientMessage(playerid, ADD YOUR COLOR, " you are not authorized to use that command!");
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new string3[32];
new playername3[30];
GetPlayerName(playerid, playername3, sizeof(playername3));
format(string3, sizeof(string3), "/%s.txt", playername3);
new File: pFile = fopen(string3, io_append);
if (pFile)
{
new var[32];
format(var, 32, "%s Ban\n", Banned[playerid][Ban]);fwrite(pFile, var);
fclose(pFile);
return 1;
}
return 1;
}
try this > untested <