Just answer me a thing about STRTOK:
#1

Everyone should know that on dcmd you basically do it for 1 parament:
pawn Код:
dcmd_kick(playerid,params[])
{
    new id = strval(params); // Basic example
    if(IsPlayerConnected(id)) Kick(id);
    return 1;
}
And with 2 or more paraments, you have to do it:
pawn Код:
dcmd_kick(playerid,params[])
{
    new id, reason,tmp[256],tmp2[256],Index;  
    tmp = strtok(params,Index);
    tmp2 = strtok(params, Index);
    if(!strval(tmp) && !strval(tmp2)) return false;
    else return Kick(id);
    return 1;
}

And on strtok/strcmp, for 1 parament:
pawn Код:
if(strcmp("/kick",cmdtext,true,10) == 0)
{
    new tmp[256],idx; tmp = strtok(cmdtext, idx);
    new id = strval(tmp);
    Kick(id);
    return 1;
}
But the question is: how do I do with over 1 parament using strcmp?
Reply
#2

Can't. Use sscanf.
Reply
#3

Well using your example, this is how:

pawn Код:
if(strcmp("/kick",cmdtext,true,10) == 0)
{
    new tmp[256],tmp2[256],idx; tmp = strtok(cmdtext, idx); tmp2 = strtok(cmdtext,idx);
    new id = strval(tmp);
    Kick(id);
    return 1;
}
Although I don't know why your strings are so long!

Anyway I recommend using sscanf as opposed to strtok, much cleaner, easier and has a lot more functionality.
Reply
#4

There's no params to use on sscanf, as on dcmd does has.

Dcmd:
pawn Код:
if(sscanf(params,"ui",id,amount))
strcmp: ??
Reply
#5

Well using sscanf and strcmp, just do:

pawn Код:
if(strcmp("/kick",cmdtext,true,5) == 0)
{
    new var,reason[128];
    if(sscanf(cmdtext,"sus",cmdtext,var,reason)) return SendClientMessage(playerid,color,"/kick playerid reason");
    else
    {
        // Your kick function.
    }
    return 1;
}
Reply
#6

I think this might work, you should be able to type /kick 4 5 9 10 ( any number of parameters ) and kick them all
pawn Код:
new tmp[16];
tmp = strtok(cmdtext,idx);
if(!strcmp(tmp,"/kick",true))
{
    new target;
    tmp = strtok(cmdtext,idx);
    while(strlen(tmp))
    {
        target = strval(tmp);
        if(IsPlayerConnected(target))
        {
            Kick(target);
        }
        tmp = strtok(cmdtext, idx);
    }
    return 1;
}
Reply
#7

thx 4all :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)