An offline ban command
#1

pawn Код:
YCMD:offlineban(playerid, params[], help)
{
    new
        TargetID;
    if( !sscanf(params, "u", TargetID))
    {
        new string[32];
        format(string,sizeof(string),PATH,TargetID);
        new INI:File = INI_Open(PATH);
        if(!fexist(string)) return SendClientMessage(playerid, -1, "Invalid player name.");
        INI_WriteInt(File,"Banned",true);
        //BanEx( TargetID, "offlineban" );
        SendClientMessage(playerid,-1, "You have now banned the player..");
        INI_Close(File);
    }
    else
        return SendClientMessage(playerid, -1, "USAGE: /offlineban [playername]");
    return 1;
}
Not sure if I got this right, I would love some help!
Reply
#2

For people not sure what the problem is, I get an Invalid Player Name even when I type in the right player name.

P.S. I'd also want to know if it's possible to add the name into the samp.ban file.
then when you want to unban the player, you remove the name automatically.
Reply
#3

You need to use a string specifier instead of the u specifier

pawn Код:
new TargetID;
if( !sscanf(params, "u", TargetID))
would be
pawn Код:
new TargetID[MAX_PLAYER_NAME];
if( !sscanf(params, "s[24]", TargetID))
Reply
#4

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
You need to use a string specifier instead of the u specifier

pawn Код:
new TargetID;
if( !sscanf(params, "u", TargetID))
would be
pawn Код:
new TargetID[MAX_PLAYER_NAME];
if( !sscanf(params, "s[24]", TargetID))
Did not work. It saved a %s file.
Reply
#5

try:
pawn Код:
YCMD:offlineban(playerid, params[])
{
       new playerb[32], string[128], file[32];
       if(sscanf(params, "s[32]s[128]", playerb, params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /offlineban [playername] [reason]");
       format(file, sizeof(file), "users/%s.ini", playerb);
    if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_GREY, "Player name not found.");
    format(string, sizeof(string), "AdmCmd: %s has been offline-banned by %s, reason: %s", playerb, RPN(playerid), params);
    SendClientMessageToAll(COLOR_LIGHTRED, string);
    format(string, sizeof(string), "AdmCmd: %s has been offline-banned by %s (%s), reason: %s", playerb, GetPlayerName(playerid) , PIP(playerid), params);
    // Banning
    dini_IntSet(file, "pBanned", 1);
    // BanList
    new File:ban = fopen("ban.cfg", io_append);
    format(string, sizeof(string), "%s\r\n", dini_Get(file, "IP"));
    fwrite(ban, string);
    fclose(ban);
    return 1;
}

//and somewhere on the bottom of the script
stock PIP(playerid)
{
    new ip[16];
    GetPlayerIp(playerid, ip, sizeof(ip));
    return ip;
}
Reply
#6

This is a dini layout..
Reply
#7

pawn Код:
YCMD:offlineban(playerid, params[], help)
{
    new
        name[24]; //Name instead (string)
    if( !sscanf(params, "s[24]", name)) //Cannot be 'u' because the player is not online.
    {
        new string[32];
        format(string,sizeof(string),PATH,name);
        // Changed from TargetID -> Name. You may need to change the path
        //because you were using an integer before (TargetID wasn't a string).
        new INI:File = INI_Open(string); //Shouldn't be path, should be string.
        if(!fexist(string)) return SendClientMessage(playerid, -1, "Invalid player name."); //All good here
        INI_WriteInt(File,"Banned",1); //Just put a 1, makes it easier.
        //BanEx( TargetID, "offlineban" ); <--- No need for that :).
        SendClientMessage(playerid,-1, "You have now banned the player.."); //Sweet.
        INI_Close(File); //Closed
    }
    else
        return SendClientMessage(playerid, -1, "USAGE: /offlineban [playername]"); //Yep
    return 1; //Sweet
}
Reply
#8

Not really sure as i'm not familiar with Y_INI, but i think you have to use 1, instead of true as true will be readen as a string and not an interager..

INI_WriteInt(File,"Banned",1);

I repeat, i'm not sure how Y_INI reads it.
Reply
#9

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
pawn Код:
YCMD:offlineban(playerid, params[], help)
{
    new
        name[24]; //Name instead (string)
    if( !sscanf(params, "s[24]", name)) //Cannot be 'u' because the player is not online.
    {
        new string[32];
        format(string,sizeof(string),PATH,name);
        // Changed from TargetID -> Name. You may need to change the path
        //because you were using an integer before (TargetID wasn't a string).
        new INI:File = INI_Open(string); //Shouldn't be path, should be string.
        if(!fexist(string)) return SendClientMessage(playerid, -1, "Invalid player name."); //All good here
        INI_WriteInt(File,"Banned",1); //Just put a 1, makes it easier.
        //BanEx( TargetID, "offlineban" ); <--- No need for that :).
        SendClientMessage(playerid,-1, "You have now banned the player.."); //Sweet.
        INI_Close(File); //Closed
    }
    else
        return SendClientMessage(playerid, -1, "USAGE: /offlineban [playername]"); //Yep
    return 1; //Sweet
}
Thanks TheKiller! Once again saving my time!

Glad to see you're back!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)