SA-MP Forums Archive
two commands in one [sscanf] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: two commands in one [sscanf] (/showthread.php?tid=284529)



two commands in one [sscanf] - Unknown123 - 19.09.2011

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;
}



Re: two commands in one [sscanf] - =WoR=Varth - 19.09.2011

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;
}



Re: two commands in one [sscanf] - Unknown123 - 19.09.2011

but i want with reason on ban


Re: two commands in one [sscanf] - =WoR=Varth - 19.09.2011

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;
}



Re: two commands in one [sscanf] - Unknown123 - 19.09.2011

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


Re: two commands in one [sscanf] - =WoR=Varth - 19.09.2011

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;
}



Re: two commands in one [sscanf] - [MWR]Blood - 19.09.2011

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.


Re: two commands in one [sscanf] - wups - 19.09.2011

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;
}



Re: two commands in one [sscanf] - =WoR=Varth - 19.09.2011

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.


Re: two commands in one [sscanf] - DRIFT_HUNTER - 19.09.2011

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