Help with making a new file after banning.
#1

Hello, I have been trying to make a ban system where it writes in it's own file, so when an admin bans a player it will save their IP, the ban reason and the admins name for later use, but I am having problems with putting this together, i've tried writing the code but it does not seem to work... The way I've wrote it, is as you use the command /ban, it will make a new file, with the players name and write everything in it, so I can load it up in a dialog for when the banned player joins. here is my code:

pawn Код:
enum banInfo
{
    BanReason,
    BanAdmin,
}
new bInfo[MAX_PLAYERS][banInfo];

stock bPath(playerid)
{
    GetPlayerName(playerid,pName,sizeof(pName));
    format(ustr,sizeof(ustr),UserPath,pName);
    return ustr;
}
pawn Код:
ACMD:ban(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 2)return 0;
    new reason[128];
    if(sscanf(params, "us[128]",ID, reason))
    return SCM(playerid, orange, "Ban a player: /ban <ID> <Reason>");
    if(ID == IPI)return SCM(playerid, red, "Player is not connected!");
    GetPlayerName(playerid,pName,sizeof(pName)); //Get player's name
    if(fexist(bPath(playerid)))
    new INI:file = INI_Open(bPath(playerid));
    INI_WriteInt(file,"BanReason", bInfo[playerid][BanReason]);
    INI_WriteInt(file, "BanAdmin", bInfo[playerid][BanAdmin]);
    INI_Close(file);
    GetPlayerName(ID,pName,MAX_PLAYER_NAME);
    GetPlayerName(playerid,pName, MAX_PLAYER_NAME);
    SetTimerEx("KickTimer", 10, false, "i", playerid);
    format(ustr, sizeof(ustr), "%s %s has banned %s for %s", AdminLevelName(playerid),pName, pName, reason);
    SCMToAll(red, ustr);
    SetTimerEx("KickTimer", 1000, false, "d", playerid);
    return 1;
}
If you know how to help please do so! I'll give rep to anyone who can help me solve this. Thank you
Reply
#2

send you pPath...
Reply
#3

ACMD:ban(playerid, params[])
{
if (pInfo[playerid][Adminlevel] < 2)return 0;
new reason[128];
new ID;
new ustr[128];
new pName[MAX_PLAYER_NAME];
new pName2[MAX_PLAYER_NAME];
if(sscanf(params, "us",ID, reason)) return SendClientMessage(playerid, orange, "Ban a player: /ban <ID> <Reason>");
if(!reason) return SendClientMessage(playerid, red, "You must type reason!");
if(!IsPlayerConnected(ID))return SendClientMessage(playerid, red, "Player is not connected!");
GetPlayerName(playerid,pName,sizeof(pName)); //Get player's name
if(fexist(bPath(playerid)))
new INI:file = INI_Open(bPath(playerid));
INI_WriteInt(file,"BanReason", bInfo[playerid][BanReason] = reason);
INI_WriteInt(file, "BanAdmin", bInfo[playerid][BanAdmin] = pName);
INI_Close(file);
GetPlayerName(pName2);
GetPlayerName(playerid,pName2, MAX_PLAYER_NAME);
format(ustr, sizeof(ustr), "Administrator %s has banned %s Reason: %s", pName,pName2,reason);
SendClientMessageToAll(red, ustr);
SetTimerEx("BanTimer", 1000, false, "d", playerid);
return 1;
}

forward BanTimer(playerid);
public BanTimer(playerid)
{
Kick(playerid);
}

Try this
Reply
#4

I am sorry for the late reply, been busy, but I've just tested it and I was getting errors, if anyone else could help me that would be great! thanks anyway
Reply
#5

Код:
stock bPath(playerid)
{
    GetPlayerName(playerid,pName,sizeof(pName));
    format(ustr,sizeof(ustr),UserPath,pName);
    return ustr;
}
If im right bPath is taking player name and format ustr to something like Playername.ini and when you write new INI:file = INI_Open(bPath(playerid));
It create new file with player name so i suggest you instead use bPath,use file name ex. new INI:file = INI_Open("bans.ini");
Reply
#6

I don't really understand, like which part to edit, sorry, I am bad at parts like this :S
Reply
#7

replace
Код:
new INI:file = INI_Open(bPath(playerid));
with
Код:
new INI:file = INI_Open("Bans.ini");
and after ban player check in scriptfiles in file Bans.ini
Reply
#8

Wouldn't take save all the bans in 1 file? I wanted it so when a player gets banned it creates a new file with the information inside of it.
Reply
#9

It looks like i didn't understand you.Sorry,you want to create when player get banned to create player file.But what is problem then ?
Reply
#10

No problem. Well as you can see this is my code so far:
pawn Код:
ACMD:ban(playerid, params[])
{
    if (pInfo[playerid][Adminlevel] < 2)return 0;
    new reason[128];
    if(sscanf(params, "us[128]",ID, reason))
    return SCM(playerid, orange, "Ban a player: /ban <ID> <Reason>");
    if(ID == IPI)return SCM(playerid, red, "Player is not connected!");
    GetPlayerName(playerid,pName,sizeof(pName)); //Get player's name
    if(fexist(bPath(playerid)))
    new INI:file = INI_Open(bPath(playerid));
    INI_WriteInt(file,"BanReason", bInfo[playerid][BanReason]);
    INI_WriteInt(file, "BanAdmin", bInfo[playerid][BanAdmin]);
    INI_Close(file);
    GetPlayerName(ID,pName,MAX_PLAYER_NAME);
    GetPlayerName(playerid,pName, MAX_PLAYER_NAME);
    SetTimerEx("KickTimer", 10, false, "i", playerid);
    format(ustr, sizeof(ustr), "%s %s has banned %s for %s", AdminLevelName(playerid),pName, pName, reason);
    SCMToAll(red, ustr);
    SetTimerEx("KickTimer", 1000, false, "d", playerid);
    return 1;
}
pawn Код:
enum banInfo
{
    BanReason,
    BanAdmin,
}
new bInfo[MAX_PLAYERS][banInfo];

stock bPath(playerid)
{
    GetPlayerName(playerid,pName,sizeof(pName));
    format(ustr,sizeof(ustr),UserPath,pName);
    return ustr;
}
but I am getting these errors, I don't know if i've wrote the command right or not
Код:
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts1.0.pwn(1637) : error 003: declaration of a local variable must appear in a compound block
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts1.0.pwn(1637) : warning 221: label name "INI" shadows tag name
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts1.0.pwn(1637) : error 017: undefined symbol "file"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts1.0.pwn(1638) : error 017: undefined symbol "file"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts1.0.pwn(1639) : error 017: undefined symbol "file"
C:\Users\BLACK\Desktop\Test\filterscripts\Accounts1.0.pwn(1640) : error 017: undefined symbol "file"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)