sscanf + PlayerInfo (pEnum) + text + zcmd = impossible?
#1

Hello..
I'm trying to make /ban command, but now i'm thinking that it's impossible with sscanf.
Here how command looks now;

pawn Код:
CMD:ban(playerid, params[])
{
    new
        i,
        reason2[64],
        name2[MAX_PLAYER_NAME],
        string[64];
    GetPlayerName(playerid, name2, sizeof(name2));
    if(PlayerInfo[playerid][admin] == 0)
        return SendClientMessage( playerid, 0xFF0000FF, "Jūs neesat admins!" );
    if( sscanf( params, "uz", i, reason2 ))
        return SendClientMessage( playerid, 0xFFFF00FF, "/ban [id] [iemesls]" );
    if( INVALID_PLAYER_ID == i)
        return SendClientMessage( playerid, 0xFF0000FF, "Nepareizs ID!" );
    SendClientMessage(i, COLOR_RED, "********************************************" );
    SendClientMessage(i, COLOR_RED, "Tu tiki nobanots no servera!" );
    format(string, sizeof(string), "Iemesls: %s, Admins: %s", reason2,name2);
    SendClientMessage(i, COLOR_RED, string );
    SendClientMessage(i, COLOR_RED, "Ja bana iemesls ir nepamatots, lūdzu dodies uz http://dd.fate.lv/" );
    SendClientMessage(i, COLOR_RED, "********************************************" );
    PlayerInfo[i][ban] = 1;
    strcat(PlayerInfo[i][banreason],reason2);
    Kick(i);
    for (new slots = GetMaxPlayers(), i2; i2 < slots; i2++)
    {
        if(!IsPlayerConnected(i2)) continue;
        SendClientMessage(i2, COLOR_RED, "********************************************" );
        format(string, sizeof(string), "%s tika izbanots no servera!", PlayerInfo[i][Name]);
        SendClientMessage(i2, COLOR_RED, string );
        format(string, sizeof(string), "Iemesls: %s, Admins: %s", reason2,name2);
        SendClientMessage(i2, COLOR_RED, string );
        SendClientMessage(i2, COLOR_RED, "********************************************" );
    }
    return true;
}
When i'm typing /ban 1 reason, nothing happens. It just prints out /ban [id] [iemesls].
So i tried an example from wiki;

pawn Код:
CMD:ban(playerid, params[])
{
    new
        id,
        reason[64];
    if (sscanf(params, "uz", id, reason)) SendClientMessage(playerid, COLOR_RED, "/ban [id] [iemesls]");
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Spēlētājs netika atrasts");
    else
    {
//      BanEx(id, reason);
        PlayerInfo[playerid][ban] = 1;
        SendClientMessage(playerid, COLOR_RED, reason );
        strcat(PlayerInfo[id][banreason],reason);
        format(reason, sizeof (reason), "You have been banned%s%s.", reason[0] ? (" for: ") : (""), reason);
        SendClientMessage(id, 0xFF0000AA, reason);
        SendClientMessage(playerid, 0x00FF00AA, "Player banned");
        format(reason, sizeof(reason), "Banots! Iemesls: %s", PlayerInfo[playerid][banreason]);
        SendClientMessage(playerid, COLOR_RED, reason );
    }
    return 1;
}
result:

Is it possible to put ban reason in PlayerInfo somehow?
Reply
#2

If you use the new sscanf plugin that would ease your work alot!

Here is my /ban command using the new sscanf.

pawn Код:
CMD:ban( zParams )
{
    LoginCheck( playerid );
    LevelCheck( playerid, 5 );

    new Player, IpBan, Reason[ 40 ];
    if ( sscanf( params, "udS(No Reason)[40]", Player, IpBan, Reason ) || IpBan > 1 || IpBan < 0 ) return SendUsage( playerid, "/ban "GREY"<id> <ipban 1/0> [reason]     "GREY"(1 - It will IP Ban the player | 0 - Only account ban!)", "Will ban the specified player, a log of this ban will be created" );
    else
    {
        if ( playerid == Player ) return SendError( playerid,  "You can't ban yourself!");
        if ( Player  == (0xFFFF)) return SendError( playerid,  "Player not connected!");
        CheckImune( playerid, Player );

        if ( IpBan )    BanEx2( Player, Name( playerid ), Reason, 1);
        else
        {
            if ( !fexist( pFile( Player ) ) )
            {
                FormatMSG( playerid, Color:ORAN, "* Player "ORAN"%s"GREY" doesn't have an account to be account banned! Choose ipban!", Name( Player ) );
                return 1;
            }
            new INI:pAcc = INI_Open( pFile( Player ) );
            INI_WriteInt( pAcc, "Banned", 1 );
            INI_WriteString( pAcc, "Reason", Reason );
            INI_WriteString( pAcc, "BanDate", zDate( ) );
            INI_Close( pAcc );

            BanEx2( Player, Name( playerid ), Reason, 0);
        }
        SendAdminCMD( playerid, ""W"Player "ORAN"%s[%i]"W" has been %s by "ORAN"%s[%i] "W"with reason"ORAN" \"%s\"",Name( Player ),Player,( IpBan ) ? ("IP banned") : ("account banned"),Name( playerid ),playerid,Reason );
        FormatMSG( playerid, -1, "You have %s "ORAN"%s[%i] "W"from the server "GREE"["W" %s "GREE"]", ( IpBan ) ? ("IP banned") : ("account banned"), Name( Player ), Player, Reason );
    }
    return 1;
}
Ignore the other code, just watch the sscanf code.
Reply
#3

I'm not using files and you are not using penum. However, i inspired from your script and made it automacilly put reason into db (query), not playerinfo. Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)