ZCMD to STRCMP?
#1

How can i convert 3100 lines from ZCMD to STRCMP? I'm newbie and i'm afraid to make a mistake. Don't try to convince me that zcmd is better than strcmp. I know that but I want to learn STRCMP first.
Reply
#2

that's a mission to do just go and take the includes out for zcmd and then get a sample of strcmp and script the whole command over using zcmd's /commands to rescript your onplayercommand field.

( take whole zcmd field out and rescript the cmds to fit into strcmp sample ) only way I can think of lol
Reply
#3

If you used sscanf with zcmd, converting them will take you a lot of time.
But if you didn't, just copy all of them and paste them under OnPlayerCommandText, then replace
pawn Код:
CMD:cmd(playerid, params[])
with
pawn Код:
if (!strcmp(cmdtext, "/cmd", true))
Reply
#4

Why not to learn zcmd? why you take a backward movement instead of forward movment, you won't make mistakes if you make mistake in strcmp it will be the same as zcmd, i don't recommend you to do this. just watch some tutorials around about zcmd usage or just check THIS
Reply
#5

Also, it's not learning 'strcmp', strcmp is just a function to compare strings.
You learn strtok, but it's very complicated.
Reply
#6

Why bother take a step backward? ZCMD is so much simpler and faster (as you stated). You want to "learn" that 1+1-1+1-3+4=3 rather than 2+1=3: you're taking the harder way around. Once more: don't bother to use strcmp and take the most convinient way (use ZCMD).
Reply
#7

While I don't recommend learning strcmp, it's actually a good way to get familiar with the function and it'll actually improve your out-of-the-box thinking in the future. Stinged is completely right though, "strcmp" is an abbreviation for "string compare" (if I'm right) and is used to compare two strings. Strtok is similar to sscanf2 but highly unefficient and performance decreasing.

Also, if you want to learn things, make them yourself, don't convert anything or use prebuilt code because it'll take you longer to decipher and convert the existing code than it'll take you to start from 0. And if you know ZCMD is better, why use STRCMP as your command processor? That doesn't make any sense whatshowever.
Reply
#8

ZCMD is a command processor not an function like strcmp, strcmp is used to compare two strings and returns certain vaules which tell you if string is equal or not. I recommend you using strcmp in other way than using it for command proccessing, maybe create some simple snipet to compare something or what ever? Happy coding!
Reply
#9

I won't judge you and talk a lot, But ZCMD is better, You're just making it harder, Anyway, You won't make any mistakes, You can find tutorials which does show how to convert.
Reply
#10

Trust me, you will regret learning strtok for commands first. It's slow and it's complicated..
Learn ZCMD with sscanf2 instead. Just look at the differance!

This was my kick cmd in my old script which I used strcmp/strtok
pawn Код:
if(strcmp(cmd, "/kick", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SCM(playerid, COLOR_GRAD2, "USAGE: /kick [playerid/PartOfName] <reason>");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid != playerid && Untouchable[giveplayerid]) return SCM(playerid, COLOR_GREY, "* You Can't Do this on This player!");
            new targetlevel = PlayerInfo[giveplayerid][pAdmin];
            new playerlevel = PlayerInfo[playerid][pAdmin];
            if(targetlevel > playerlevel) return SCM(playerid, COLOR_GREY, "* You can not Kick People that is higher Than You!");
            if (PlayerInfo[playerid][pAdmin] >= 1 || IsPlayerAdmin(playerid))
            {
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID || !IsPlayerNPC(giveplayerid))
                    {
                        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                        new length = strlen(cmdtext);
                        while ((idx < length) && (cmdtext[idx] <= ' '))
                        {
                            idx++;
                        }
                        new offset = idx;
                        new result[128];
                        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                        {
                            result[idx - offset] = cmdtext[idx];
                            idx++;
                        }
                        result[idx - offset] = EOS;
                        if(!strlen(result))
                        {
                            new y, m, d;
                            new h,mi,s;
                            getdate(y,m,d);
                            gettime(h,mi,s);
                            format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has been kicked by %s, No Reason Given",d,m,y,h,mi,s,giveplayer,sendername);
                            KickLog(string);
                            format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] Kicked by %s - No Reason Given.",d,m,y,h,mi,s,sendername);
                            AddPunishment(giveplayerid, string);
                            format(string, sizeof(string), "%s (%d), Has been kicked by Administrator %s, No Reason Given", giveplayer, giveplayerid, sendername);
                            SCMToAll(COLOR_NICERED, string);
                            format(string, sizeof(string), "You have Been Kicked by Administrator %s, No Reason Given", sendername);
                            SCM(giveplayerid,COLOR_LIGHTBLUE, string);
                            SafeSetPlayerPos(giveplayerid,1601.8762,-1671.9099,-40.5941);
                            SafeSetPlayerInterior(giveplayerid, 0);
                            GameTextForPlayer(giveplayerid, "~r~~h~Admin Kicked: ~n~~r~No Reason Given", 6000, 3);
                            SetTimerEx("KickOut",500,false,"i",giveplayerid);
                            return 1;
                        }
                        new y, m, d;
                        new h,mi,s;
                        getdate(y,m,d);
                        gettime(h,mi,s);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has been kicked by %s for: %s",d,m,y,h,mi,s,giveplayer,sendername, (result));
                        KickLog(string);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] Kicked by %s - Reason: %s",d,m,y,h,mi,s,sendername,(result));
                        AddPunishment(giveplayerid, string);
                        format(string, sizeof(string), "%s (%d), Has been kicked by Administrator %s for: %s", giveplayer, giveplayerid, sendername, (result));
                        SCMToAll(COLOR_NICERED, string);
                        format(string, sizeof(string), "You have Been Kicked by Administrator %s for: %s", sendername, (result));
                        SCM(giveplayerid,COLOR_LIGHTBLUE, string);
                        SafeSetPlayerPos(giveplayerid,1601.8762,-1671.9099,-40.5941);
                        SafeSetPlayerInterior(giveplayerid, 0);
                        format(string, sizeof(string), "~r~~h~Admin Kicked: ~n~~r~%s",(result));
                        GameTextForPlayer(giveplayerid, string, 6000, 3);
                        SetTimerEx("KickOut",500,false,"i",giveplayerid);
                        return 1;
                    }
                }
            }
            else
            {
                format(string, sizeof(string), "** %d is not an active player.", giveplayerid);
                SCM(playerid, COLOR_GRAD1, string);
            }
        }
        return 1;
    }
This is how you could make it if you use ZCMD/sscanf2
pawn Код:
CMD:kick(playerid, params[])
{
    new id, idname[MAX_PLAYER_NAME], reason, string[128],name[MAX_PLAYER_NAME];
    if(sscanf(params,"us[128]",id,reason)) return SendClientMessage(playerid, -1, "SYNTAX: /kick [player] [reason]");
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerName(id, idname, sizeof(idname));
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Invalid Player ID");
    format(string, sizeof(string),"Player %s (%i) Kicked %s (%i) For reason: %s", name, playerid, idname, id, reason);
    SendClientMessageToAll(-1, string);
    Kick(id);
    return true;
}
This is just something quick I made just to show you how you could make it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)