Need Help with ZCMD+SSCANF (vPlate CMD)
#1

Hey folks,

Can you convert me this to ZCMD please, using SSCANF.

pawn Код:
if(strcmp(cmd, "/vplate", true) == 0)
    {
        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))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vplate [text]");
            return 1;
        }
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2])
        {
            new ownvehkey;
            new car = GetPlayerVehicleID(playerid);
            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
            else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
            else { return 1; }
            if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
            {
                if(GetPlayerMoney(playerid) < 200)
                {
                    SendClientMessage(playerid,COLOR_WHITE,"* You do not have $200, to change you're number plate with the DVLA!");
                    return 1;
                }
                strmid(CarInfo[car][cPlate], result, 0, strlen(result), 999);
                new vid = GetPlayerVehicleID(playerid);
                GivePlayerMoney(playerid,-5000);
                SetVehicleNumberPlate(vid, CarInfo[vid][cPlate]);
                SetVehicleToRespawn(GetPlayerVehicleID(playerid));
                OnPropUpdate(4,car);
                return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "  Please sit in your car before selling! ");
                return 1;
            }
       }
Reply
#2

What is the purpose of that command, exactly? After skimming through it, there's really nothing to do with the cmdtext/params.

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
Код:
COMMAND:vplate(playerid,params[])
    {
        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))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vplate [text]");
            return 1;
        }
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2])
        {
            new ownvehkey;
            new car = GetPlayerVehicleID(playerid);
            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
            else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
            else { return 1; }
            if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
            {
                if(GetPlayerMoney(playerid) < 200)
                {
                    SendClientMessage(playerid,COLOR_WHITE,"* You do not have $200, to change you're number plate with the DVLA!");
                    return 1;
                }
                strmid(CarInfo[car][cPlate], result, 0, strlen(result), 999);
                new vid = GetPlayerVehicleID(playerid);
                GivePlayerMoney(playerid,-5000);
                SetVehicleNumberPlate(vid, CarInfo[vid][cPlate]);
                SetVehicleToRespawn(GetPlayerVehicleID(playerid));
                OnPropUpdate(4,car);
                return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "  Please sit in your car before selling! ");
                return 1;
            }
       }
Done.
You have no idea what you're doing, so please stop.
Reply
#3

Код:
COMMAND:vplate(playerid,params[])
    {
        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))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vplate [text]");
            return 1;
        }
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2])
        {
            new ownvehkey;
            new car = GetPlayerVehicleID(playerid);
            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
            else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
            else { return 1; }
            if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
            {
                if(GetPlayerMoney(playerid) < 200)
                {
                    SendClientMessage(playerid,COLOR_WHITE,"* You do not have $200, to change you're number plate with the DVLA!");
                    return 1;
                }
                strmid(CarInfo[car][cPlate], result, 0, strlen(result), 999);
                new vid = GetPlayerVehicleID(playerid);
                GivePlayerMoney(playerid,-5000);
                SetVehicleNumberPlate(vid, CarInfo[vid][cPlate]);
                SetVehicleToRespawn(GetPlayerVehicleID(playerid));
                OnPropUpdate(4,car);
                return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "  Please sit in your car before selling! ");
                return 1;
            }
       }
Done.
Reply
#4

@Blackazur: Are you in any way familiar with ZCMD or how it is used?

@OP: You should look up how to use ZCMD yourself so you can convert all commands instead of coming here every time you need help with the library. Don't be lazy.
Reply
#5

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
Код:
COMMAND:vplate(playerid,params[])
    {
        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))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vplate [text]");
            return 1;
        }
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2])
        {
            new ownvehkey;
            new car = GetPlayerVehicleID(playerid);
            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
            else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
            else { return 1; }
            if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
            {
                if(GetPlayerMoney(playerid) < 200)
                {
                    SendClientMessage(playerid,COLOR_WHITE,"* You do not have $200, to change you're number plate with the DVLA!");
                    return 1;
                }
                strmid(CarInfo[car][cPlate], result, 0, strlen(result), 999);
                new vid = GetPlayerVehicleID(playerid);
                GivePlayerMoney(playerid,-5000);
                SetVehicleNumberPlate(vid, CarInfo[vid][cPlate]);
                SetVehicleToRespawn(GetPlayerVehicleID(playerid));
                OnPropUpdate(4,car);
                return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "  Please sit in your car before selling! ");
                return 1;
            }
       }
Done.
I know how to convert ZCMD+SSCANF. Apart from this one is just failing, I cannot get it to work... Already converted 100 commands, but this one is failing bad, the strlen(cmdtext), cmdtext is not used in the params
Reply
#6

@Bakr Yep i am.

@Unknown Yep that with
Quote:

if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)

is maybe the problem to convert. ^^
Reply
#7

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
@Bakr Yep i am.

@Unknown Yep that with is maybe the problem to convert. ^^
I'm just going to remove the whole command and re-make it with a dialog box, that'll probably just be fairly easier than mucking around with it.
Reply
#8

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
@Bakr Yep i am.

@Unknown Yep that with is maybe the problem to convert. ^^
Clearly you do not as you would know there is no need to split the parameters to find the input when there is only one he is searching for...

I should also point out there are MUCH more efficient manners of doing what he did in the first post (he basically used strtok() inside the command, just like GF does).
Reply
#9

Quote:
Originally Posted by Bakr
Посмотреть сообщение
Clearly you do not as you would know there is no need to split the parameters to find the input when there is only one he is searching for...

I should also point out there are MUCH more efficient manners of doing what he did in the first post (he basically used strtok() inside the command, just like GF does).
I only make Commands with ZCMD, but no loss to argue about it. ^^

@UnknownGamer kk.
Reply
#10

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
I only make Commands with ZCMD
Take a look at the command you offered, claiming that it was "converted and done."

pawn Код:
COMMAND:vplate(playerid,params[])
    {
        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))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /vplate [text]");
            return 1;
        }
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2])
        {
            new ownvehkey;
            new car = GetPlayerVehicleID(playerid);
            if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
            else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
            else { return 1; }
            if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
            {
                if(GetPlayerMoney(playerid) < 200)
                {
                    SendClientMessage(playerid,COLOR_WHITE,"* You do not have $200, to change you're number plate with the DVLA!");
                    return 1;
                }
                strmid(CarInfo[car][cPlate], result, 0, strlen(result), 999);
                new vid = GetPlayerVehicleID(playerid);
                GivePlayerMoney(playerid,-5000);
                SetVehicleNumberPlate(vid, CarInfo[vid][cPlate]);
                SetVehicleToRespawn(GetPlayerVehicleID(playerid));
                OnPropUpdate(4,car);
                return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "  Please sit in your car before selling! ");
                return 1;
            }
       }
There are still "cmdtext" variables being used, you didn't even bother to change that. You didn't even bother to realize that cmdtext isn't even necessary in this command. Nor is the use of "params" when it is converted the proper way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)