Need help with scripting a /nameban command -
Ed2ka49 - 13.02.2009
Before I posted this topic, I searched A LOT OF TIMES for an answer for my problem, but I couldn't find anything.
My question: I need a /nameban [playerid] [reason] commands, that will ban the Player's NAME (Not an IP ban), and he will not be allowed to log in with this name.
I really need a help with scripting this commands, I hope someone will help me.
Thanks
Re: Need help with scripting a /nameban command -
Lazarus - 13.02.2009
pawn Код:
#define red 0xFF0000AA
#define green 0x33FF33AA
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], File:file=fopen("samp-names.ban", io_read), string[256]; //256 not 128 for reading files
GetPlayerName(playerid, pname, sizeof(pname));
while(fread(file, string))
{
if(strfind(string, pname, true) == 0)
{
SendClientMessage(playerid, red, "Sorry, that username has been banned. Please join with a diffrent undername!");
Kick(playerid);
}
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp("/nameban", cmdtext, true, 8) == 0)
{
if(IsPlayerAdmin(playerid) == 0) return SendClientMessage(playerid, red, "You are not an admin");
if(strlen(cmdtext[9]) == 0) return SendClientMessage(playerid, red, "Usage: /nameban [id] [reason]");
new pos = strfind(cmdtext, " ", true, 9);
if(pos == -1) return SendClientMessage(playerid, red, "Usage: /nameban [id] [reason]");
if(strlen(cmdtext[pos++]) == 0) return SendClientMessage(playerid, red, "Usage: /nameban [id] [reason]");
if(IsPlayerConnected(strval(cmdtext[9])) == 0) return SendClientMessage(playerid, red, "That player is not connected");
new pname[MAX_PLAYER_NAME], File:file=fopen("samp-names.ban", io_write), string[MAX_PLAYER_NAME + 5];
GetPlayerName(strval(cmdtext[9]), pname, sizeof(pname));
format(string, sizeof(string), "%s\r\n", pname);
fwrite(file, string);
fclose(file);
format(string, sizeof(string), "%s has been banned from the name (reason: %s)", pname, cmdtext[pos++]);
SendClientMessageToAll(green, string);
Ban(strval(cmdtext[9]));
return 1;
}
return 0;
}
No idea if it works.
Re: Need help with scripting a /nameban command -
MenaceX^ - 13.02.2009
Name Ban? How do you mean? :X, Like bans the player by his name?
Re: Need help with scripting a /nameban command -
Lazarus - 13.02.2009
I'm guessing, so they can't just change their IP and have access to their account.
Re: Need help with scripting a /nameban command -
Ed2ka49 - 13.02.2009
Thank you, its works but there is one little problem.;
I successfully compiled it, but I got an warning: 219: local variable "string" shadows a variable at a preceding level
after I typed /nameban Name reason - its ban the player and adds his name to the file samp-names.ban file, BUT its ban his IP too in the samp.ban file in my main folder.
Do you know how to make it ONLY name ban? For using as CK in a RP servers?
Thank you.
Re: Need help with scripting a /nameban command -
Ed2ka49 - 13.02.2009
I fixed the first problem, but now when I ban more names, its always only the last name stay banned.
How to make it to ban more names?
Re: Need help with scripting a /nameban command -
Lazarus - 13.02.2009
Try changing "io_write" (in the command) to "io_append".
Re: Need help with scripting a /nameban command -
Ed2ka49 - 14.02.2009
Great! Its finally works fine
But I got a little problem.. When I write somethin with SendClienMessage its always writes my the first 17 laters and then its just doesn't write anything..
Like : format(string, sizeof(string), "%s , you are banned from this server", pname);
SendAdminMessage(ADMIN_RED, string);
Its send me a message in game only: "%s , you are b"
Do you know how to fix that?
Re: Need help with scripting a /nameban command -
Soeren - 14.02.2009
That is probably because your string is too small:
"%s , you are banned from this server"
(34 + 26 + 1) = 61 // 34 letters, 26 MAX_PLAYER_NAME, +1 by default
So make sure you have "new string[61];"
Re: Need help with scripting a /nameban command -
Danut - 14.02.2009
Quote:
Originally Posted by Seif_
sBanMachine has that.
|
Seif owns it , but got a bug at /tempban