Convert strtok and strcmp to sscanf and zcmd
#1

I really would like to go a step forward and a major update with my script convering strcmp and strok commands to the most efficent way.
Can anybody convert this, for example? It will work as a base.
pawn Код:
if(strcmp("/kick", cmd, true) == 0)
    {
        if(PlayerInfo[playerid][pAdminLevel] >= 1)
        {
            tmp = strtok(cmdtext,idx);
            if(!strlen(tmp))
            {
                return SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /kick [id] [reason]");
            }
            new id = strval(tmp);
            new pid = playerid;
            new reason[128];
            reason = strrest(cmdtext, idx);
            if (!strlen(reason)) return SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /kick [id] [reason]");
            if(!IsPlayerConnected(id))
            {
                return SendClientMessage(playerid,COLOR_GRAY,"AdmCmd This player is not online!");
            }
           
            PlayHintSoundAtPos(playerid);
            new globalmsg[100];
            new adminid[MAX_PLAYERS], victimid[MAX_PLAYERS];
            GetPlayerName(pid, adminid, sizeof(victimid));
            GetPlayerName(id, victimid, sizeof(victimid));
            format(globalmsg,sizeof(globalmsg),"AdmWarn: Administrator %s has kicked player %s [%s]",adminid,victimid,reason);
            SendClientMessageToAll(COLOR_LIGHTBLUE,globalmsg);
            Kick(id);
            return 1;
        }
        else
        {
            SendClientMessage(playerid,COLOR_GRAY,"You don't have authorization.");
            return 1;
        }
    }
A guide to convert commands and use sscanf as their parameters is deeply appreciated
Regards,
Reply
#2

Try this:

I know that I've done a mistake, I can't see it though.

pawn Код:
COMMAND:kick(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdminLevel] >= 1)
        {
               new pid = playerid, reason[128], id = strval(tmp);
            if(sscanf(params, "us[128]", player, reason)) return SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /kick [id] [reason]");
            if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_GRAY,"AdmCmd This player is not online!");
            PlayHintSoundAtPos(playerid);
            new globalmsg[100];
            new adminid[MAX_PLAYERS], victimid[MAX_PLAYERS];
            GetPlayerName(pid, adminid, sizeof(victimid));
            GetPlayerName(id, victimid, sizeof(victimid));
            format(globalmsg,sizeof(globalmsg),"AdmWarn: Administrator %s has kicked player %s [%s]",adminid,victimid,reason);
            SendClientMessageToAll(COLOR_LIGHTBLUE,globalmsg);
            Kick(id);
        }
        else SendClientMessage(playerid,COLOR_GRAY,"You don't have authorization.");
            return 1;
    }
Reply
#3

In Final GM

pawn Код:
fcmd(kick,playerid)
{
    if(PlayerInfo[playerid][pAdminLevel] < 1)
        return SendClientMessage(playerid,COLOR_GRAY,"You don't have authorization.");
   
    if(!iParams[1] || !iParams[2])            
        return SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /kick [id] [reason]");
           
    static id;
    id = strval(iParams[1]);

    if(!IsPlayerConnected(id)            
        return SendClientMessage(playerid,COLOR_GRAY,"AdmCmd This player is not online!");
           
           
    PlayHintSoundAtPos(playerid);
    new globalmsg[100];
    new adminid[MAX_PLAYERS], victimid[MAX_PLAYERS];
    GetPlayerName(pid, adminid, sizeof(victimid));
    GetPlayerName(id, victimid, sizeof(victimid));
    format(globalmsg,sizeof(globalmsg),"AdmWarn: Administrator %s has kicked player %s [%s]",adminid,victimid,reason);
    SendClientMessageToAll(COLOR_LIGHTBLUE,globalmsg);
    Kick(id);
    return true;
}
And Use
https://sampforum.blast.hk/showthread.php?tid=213323
Reply
#4

^^If someone translate that thread(fcmd) to English, Japanese or Greek I would really appreciate it.
Reply
#5

Quote:
Originally Posted by PeteShag
Посмотреть сообщение
^^If someone translate that thread(fcmd) to English, Japanese or Greek I would really appreciate it.
(キック、playerid)fcmd
{
(PlayerInfo<1[をpAdminLevel][はplayerid])場合、
(playerid、COLOR_GRAY、"あなたは権限がない")SendClientMessage 返します。

場合(iParamsは、[1]|!|は!iParamsは、[2])
SendClientMessage返す(playerid、COLOR_LIGHTRED、"使用方法:/[ID]を蹴る[理由]");

静的なIDです。
イド= strval(iParams[1]);

(もしあれ!(id)をIsPlayerConnected
SendClientMessage返す(playerid、COLOR_GRAY、"!このプレーヤーは オンラインになっていないAdmCmd");


PlayHintSoundAtPos(playerid);
新しいglobalmsgの[100];
新しいadminid[MAX_PLAYERS] victimid[のMAX_PLAYERS];
GetPlayerName(sizeofはpidを、adminid(victimid));
GetPlayerName(sizeofはidは、victimid(victimid));
フォーマットは(globalmsgは、sizeof(globalmsg):adminid、victi mid、その理由"AdmWarn管理者%sはプレーヤー%は[%sを]のだ蹴りを持つ");
SendClientMessageToAll(COLOR_LIGHTBLUE、globalmsg);
キック(id)の;
trueを返します。
}
Reply
#6

pawn Код:
command(kick, playerid, params[])
{
    new ID, string[128], reason[66];
    if(PlayerInfo[playerid][pAdminLevel] >= 1) return SendClientMessage(playerid, 0xFFFF00AA,"You don't have authorization.");
    if(sscanf(params, "uS(No Reason Given)[65]", ID, reason)) SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /kick [id] [optional: reason]");
    else if(ID == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_LIGHTBLUE, "AdmCmd This player is not online!");
    else
    {
        format(string,sizeof(string), "You have been kicked by Administrator %s Reason: %s", adminid,reason);
        SendClientMessage(ID , COLOR_LIGHTBLUE, string);
        format(string, sizeof(string), "You have kicked %s %s", victimid, reason);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        format(string, sizeof(string), "Administrator/VIP %s has kicked %s %s",adminid,victimid,reason);
        SendClientMessageToAll( COLOR_LIGHTBLUE, string );
        TogglePlayerControllable(ID, false);
        Kick(ID);
    }
    return 1;
}
Use sscanf n zcmd

@[FeK]DraKiNs and PeteShag
It's 'S' not 's' for optional strings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)