two commands in one [sscanf]
#1

why dont this work

i want it like

/stuff <ban> <id> <reason>
/stuff <kick> <id>

here is code
pawn Код:
CMD:stuff(playerid,params[])
{
    new cmd[128], otherid, reason[128];
    if(sscanf(params,"s[128]",cmd))
    {
        if(strcmp(cmd, "kick", true))
        {
            if(sscanf(params,"u",otherid))
            {
                Kick(otherid);
            }
        }
       
        if(strcmp(cmd, "ban", true))
        {
            if(sscanf(params,"us[128]",otherid,reason))
            {
                BanEx(otherid,reason);
            }
        }
    }
    return 1;
}
Reply
#2

pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            Kick(otherid);
        }
       
        if(sscanf(params,"'ban'd",otherid))
        {
            Ban(otherid);
        }
    }
    return 1;
}
Reply
#3

but i want with reason on ban
Reply
#4

pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            Kick(otherid);
        }
       
        if(sscanf(params,"'ban'ds",otherid,params))
        {
            BanEx(otherid,params);
        }
    }
    return 1;
}
Reply
#5

dont work

pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            printf("kick: %d", otherid);
        }

        if(sscanf(params,"'ban'ds",otherid,params))
        {
            printf("ban: %d - %s", otherid, params);
        }
    }
    return 1;
}
/stuff ban 2 LOL return kick: 0
Reply
#6

pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(strfind(params,"kick"))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            printf("kick: %d", otherid);
        }
    }
    if(strfind(params,"ban"))
    {
        if(sscanf(params,"'ban'ds",otherid,params))
        {
            printf("ban: %d - %s", otherid,params);
        }
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by =WoR=Varth
Посмотреть сообщение
pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(strfind(params,"kick"))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            printf("kick: %d", otherid);
        }
    }
    if(strfind(params,"ban"))
    {
        if(sscanf(params,"'ban'ds",otherid,params))
        {
            printf("ban: %d - %s", otherid,params);
        }
    }
    return 1;
}
Do you know what is strfind used for?!
https://sampwiki.blast.hk/wiki/Strfind
So if you do like, /stuff kicktrolololol it would still work.
And you can't use sscanf like that.
Reply
#8

People! So much examples, but you forget that sscanf returns 0 when used INCORRECTLY
So this:
pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            Kick(otherid);
        }
       
        if(sscanf(params,"'ban'd",otherid))
        {
            Ban(otherid);
        }
    }
    return 1;
}
Should be
pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(!sscanf(params,"'kick'd",otherid))
        {
            Kick(otherid);
        }
       
        if(!sscanf(params,"'ban'd",otherid))
        {
            Ban(otherid);
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by wups
Посмотреть сообщение
People! So much examples, but you forget that sscanf returns 0 when used INCORRECTLY
So this:
pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(sscanf(params,"'kick'd",otherid))
        {
            Kick(otherid);
        }
       
        if(sscanf(params,"'ban'd",otherid))
        {
            Ban(otherid);
        }
    }
    return 1;
}
Should be
pawn Код:
CMD:stuff(playerid,params[])
{
    new otherid;
    if(!isnull(params))
    {
        if(!sscanf(params,"'kick'd",otherid))
        {
            Kick(otherid);
        }
       
        if(!sscanf(params,"'ban'd",otherid))
        {
            Ban(otherid);
        }
    }
    return 1;
}
Meh, my bad.
I owe you cokiees.

EDIT: I think there's no need isnull check.
Reply
#10

Quote:
Originally Posted by wups
Посмотреть сообщение
People! So much examples, but you forget that sscanf returns 0 when used INCORRECTLY
No sscanf return 1 when its fail (used INCORRECTLY)

Here is how i use it for my server and every cmd works like a charm
pawn Код:
if(sscanf(params, "dd", weapon,ammo)) return SendUsage(playerid,"/w2 [Weapon ID][Ammo]");
The code says if sscanf return true/1 than i will SendUsage to playerid


Now lets go back to these command request
I didnt tested these but i think it will work

pawn Код:
CMD:stuff(playerid, params[])
{
    new cmd[5],playerid2,reason[50];
    if(sscanf(params, "s[24]uS()[50])", cmd, playerid2, reason)) return SendClientMessage(playerid, red, "/stuff [Kick/Ban] (Reason)]");
    {
        //These is same as strfind but i just like these way
        if(cmd[0] == 'k' && cmd[1] == 'i' && cmd[2] == 'c' && cmd[3] == 'k')
        {
            Kick(playerid2);
            return 1;
        }
        else if(cmd[0] == 'b' && cmd[1] == 'a' && cmd[2] == 'n')
        {
            if(isnull(reason)) return SendClientMessage(playerid, red, "You need reason for ban");
            BanEx(playerid2, reason);
            return 1;
        }
    }
    return 1;
}
And people please read first post in https://sampforum.blast.hk/showthread.php?tid=120356
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)