Converting to SSCANF and ZCMD
#1

EDIT: I was able to get the CMD partially working but it is still bugged when I type /irc join 1 it says "invalid irc number" Anyone know what the bug causing this could be?

pawn Код:
CMD:irc(playerid, params[])
{
     new x_nr[256];
     x_nr = strtok(params, idx);
     if(IsPlayerConnected(playerid))
        {
            if(isnull(params)) {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: (/irc join [channelnr] or /irc join [channelnr] [password])  (/irc Leave)  (/irc Admins)");
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc [name] [channelnr]");
                SendClientMessage(playerid, COLOR_WHITE, "Available names: MOTD, Password, NeedPass, Lock, Kick, Status");
                return 1;
            }
            if(strcmp(params,"join",true) == 0)
            {
                tmp = strtok(params, idx);
                if(isnull(params)) {
                    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc join [channelnr] or /irc join [channelnr] [password]");
                    return 1;
                }
                new channel = strval(tmp);
                if(channel < 1 || channel > 10) { SendClientMessage(playerid, COLOR_GREY, "   Channel Number can't be below 1 or above 10 !"); return 1; }
                channel -= 1;
                if(IRCInfo[channel][iLock] == 0)
                {
                    if(IRCInfo[channel][iNeedPass] == 0)
                    {
                        JoinChannelNr(playerid, channel);
                    }
                    else
                    {
                        tmp = strtok(params, idx);
                        if(!strlen(tmp))
                        {
                            SendClientMessage(playerid, COLOR_WHITE, "There's a password required to join this Channel.");
                            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc join [channelnr] [password]");
                            return 1;
                        }
                        JoinChannel(playerid,channel,tmp);
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   That Channel is Locked, please choose a different one !");
                    return 1;
                }
            }
            else if(strcmp(params,"status",true) == 0)
            {
                for(new i = 0; i < sizeof(IRCInfo); i++)
                {
                    new string[128];
                    format(string, sizeof(string), "Channel %d: %d Players Connected.",i + 1, IRCInfo[i][iPlayers]);
                    SendClientMessage(playerid, COLOR_WHITE, string);
                }
                return 1;
            }
            else if(strcmp(params,"password",true) == 0)
            {
                tmp = strtok(params, idx);
                if(isnull(params))
                {
                    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc password [channelnr] [password]");
                    return 1;
                }
                new channel = strval(tmp);
                if(channel < 1 || channel > 10) { SendClientMessage(playerid, COLOR_GREY, "   Channel Number can't be below 1 or above 10 !"); return 1; }
                channel -= 1;
                new wstring[128];
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(wstring, sizeof(wstring), "%s", sendername);
                strmid(wstring, wstring, 0, strlen(wstring), 255);
                if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
                {
                    tmp = strtok(params, idx);
                    if(!strlen(tmp))
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc password [channelnr] [password]");
                        return 1;
                    }
                    new string[128];
                    strmid(IRCInfo[channel][iPassword], tmp, 0, strlen(tmp), 255);
                    format(string, sizeof(string), "You've changed the IRC Channel's Password to: %s.",IRCInfo[channel][iPassword]);
                    SendClientMessage(playerid, COLOR_YELLOW, string);
                    SaveIRC();
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not the Admin of that Channel !");
                    return 1;
                }
            }
            else if(strcmp(params,"needpass",true) == 0)
            {
                tmp = strtok(params, idx);
                if(isnull(params))
                {
                    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc needpass [channelnr]");
                    return 1;
                }
                new channel = strval(tmp);
                if(channel < 1 || channel > 10) { SendClientMessage(playerid, COLOR_GREY, "   Channel Number can't be below 1 or above 10 !"); return 1; }
                channel -= 1;
                new wstring[128];
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(wstring, sizeof(wstring), "%s", sendername);
                strmid(wstring, wstring, 0, strlen(wstring), 255);
                if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
                {
                    if(IRCInfo[channel][iNeedPass] != 0)
                    {
                        IRCInfo[channel][iNeedPass] = 0;
                        SendClientMessage(playerid, COLOR_YELLOW, "Players won't have to fill in a password in order to join the IRC Channel now.");
                    }
                    else
                    {
                        IRCInfo[channel][iNeedPass] = 1;
                        SendClientMessage(playerid, COLOR_YELLOW, "Players must fill in a password in order to join the IRC Channel now.");
                    }
                    SaveIRC();
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not the Admin of that Channel !");
                    return 1;
                }
            }
            else if(strcmp(params,"lock",true) == 0)
            {
                tmp = strtok(params, idx);
                if(isnull(params))
                {
                    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc lock [channelnr]");
                    return 1;
                }
                new channel = strval(tmp);
                if(channel < 1 || channel > 10) { SendClientMessage(playerid, COLOR_GREY, "   Channel Number can't be below 1 or above 10 !"); return 1; }
                channel -= 1;
                new wstring[128];
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(wstring, sizeof(wstring), "%s", sendername);
                strmid(wstring, wstring, 0, strlen(wstring), 255);
                if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
                {
                    if(IRCInfo[channel][iLock] != 0)
                    {
                        IRCInfo[channel][iLock] = 0;
                        SendClientMessage(playerid, COLOR_YELLOW, "You've unlocked the IRC Channel.");
                    }
                    else
                    {
                        IRCInfo[channel][iLock] = 1;
                        SendClientMessage(playerid, COLOR_YELLOW, "You've locked the IRC Channel.");
                    }
                    SaveIRC();
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not the Admin of that Channel !");
                    return 1;
                }
            }
            else if(strcmp(params,"motd",true) == 0)
            {
                tmp = strtok(params, idx);
                if(isnull(params))
                {
                    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc motd [channelnr] [motdtext]");
                    return 1;
                }
                new channel = strval(tmp);
                if(channel < 1 || channel > 10) { SendClientMessage(playerid, COLOR_GREY, "   Channel Number can't be below 1 or above 10 !"); return 1; }
                channel -= 1;
                new wstring[128];
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(wstring, sizeof(wstring), "%s", sendername);
                strmid(wstring, wstring, 0, strlen(wstring), 255);
                if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
                {
                    if(isnull(params))
                        return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /irc motd [motdtext]");


                    new result[128];
                    strmid(IRCInfo[channel][iMOTD], result, 0, strlen(result), 255);
                    SendClientMessage(playerid, COLOR_YELLOW, "You've adjusted the IRC Channel's MOTD Text.");
                    SaveIRC();
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not the Admin of that Channel !");
                    return 1;
                }
            }
            else if(strcmp(params,"leave",true) == 0)
            {
                if(PlayersChannel[playerid] < 999)
                {
                    new string[128];
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    format(string, sizeof(string), "* %s has left the Channel.", sendername);
                    SendIRCMessage(PlayersChannel[playerid], COLOR_GREEN, string);
                    IRCInfo[PlayersChannel[playerid]][iPlayers] -= 1;
                    PlayersChannel[playerid] = 999;
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not in an IRC Channel !");
                    return 1;
                }
            }
            else if(strcmp(params,"admins",true) == 0)
            {
                for(new i = 0; i < sizeof(IRCInfo); i++)
                {
                    new string[128];
                    format(string, sizeof(string), "Channel %d: %s.", i + 1, IRCInfo[i][iAdmin]);
                    SendClientMessage(playerid, COLOR_WHITE, string);
                }
                return 1;
            }
            else if(strcmp(params,"kick",true) == 0)
            {
                if(PlayersChannel[playerid] == 999)
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not in an IRC Channel !");
                    return 1;
                }
                new wstring[128];
                GetPlayerName(playerid, sendername, sizeof(sendername));
                format(wstring, sizeof(wstring), "%s", sendername);
                strmid(wstring, wstring, 0, strlen(wstring), 255);
                if(strcmp(IRCInfo[PlayersChannel[playerid]][iAdmin],wstring, true ) == 0 )
                {
                    tmp = strtok(params, idx);
                    if(isnull(params))
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc kick [playerid/PartOfName]");
                        return 1;
                    }
                    giveplayerid = ReturnUser(tmp);
                    if(IsPlayerConnected(giveplayerid))
                    {
                        if(giveplayerid != INVALID_PLAYER_ID)
                        {
                            if(PlayersChannel[giveplayerid] == PlayersChannel[playerid])
                            {
                                new string[128];
                                GetPlayerName(playerid, sendername, sizeof(sendername));
                                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                                format(string, sizeof(string), "* You've kicked %s out of your IRC Channel.",giveplayer);
                                SendClientMessage(playerid, COLOR_YELLOW, string);
                                format(string, sizeof(string), "* You've been kicked out of the IRC Channel by Channel Admin: %s.",sendername);
                                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                                format(string, sizeof(string), "* %s has left the Channel (Kicked).", sendername);
                                SendIRCMessage(PlayersChannel[playerid], COLOR_GREEN, string);
                                IRCInfo[PlayersChannel[giveplayerid]][iPlayers] -= 1;
                                PlayersChannel[giveplayerid] = 999;
                            }
                            else
                            {
                                SendClientMessage(playerid, COLOR_GREY, "   That player is not in your IRC Channel !");
                                return 1;
                            }
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   That player is Offline !");
                        return 1;
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You are not the Admin of the Channel !");
                    return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "   Invalid IRC Channel Number ! ");
                return 1;
            }
        }
        return 1;
    }
Reply
#2

I would do it for you, but is a very large command and you would learn nothing from other people just posting code. Just go read a shit-ton of ZCMD and SSCANF tutorials and learn how to add more and more parameters. I wish you luck.
Reply
#3

Quote:
Originally Posted by Walsh
Посмотреть сообщение
I would do it for you, but is a very large command and you would learn nothing from other people just posting code. Just go read a shit-ton of ZCMD and SSCANF tutorials and learn how to add more and more parameters. I wish you luck.
I been trying to do shit for the past 4 - 5 hours straight no bullshit. I have read every tutorial on strok to sscanf, I can do it for simpler commands. I was able to get /irc join 1 to work but if i tried to do /irc status or /irc admins it would send this message to me " USAGE: /irc kick [playerid/PartOfName] ". After trying to fix that for a bit my compiler decided not to responed after compiling. So I just deleted the cmd and was back at square one.

If you explain what you did I will be able to understand it, I am better at learning from reading code then I am from tutorials.
Reply
#4

well reading code is helpful it does not always explain what its doing by looking at it,

your best bet is to learn sscanf
all the specifiers and how to you it correctly on a small scale,
the best reference for sscanf is in the thread where its been released.

i know i said id rewrite this for you but i wont have the time,
(sorry I got a lil baby girl who will consume my time today!)
also iv never used zcmd or dcmd ect..
im new here and jumped right into ycmd for my command processor,

so if it was me I would convert all strok to sscanf
then once that is working id convert the hole command to zcmd. Which should be really easy.

where it will get hard is all the commands after /irc
I haven't yet made a command like this to do multiply things but I know
there is example code like that all over this site.

so i suggest you TRY to do it and when ya get stuck post your code here and we will help you threw it.
this is your best way to learn both sscanf and zcmd


good luck!
Reply
#5

Quote:
Originally Posted by Madd Kat
Посмотреть сообщение
well reading code is helpful it does not always explain what its doing by looking at it,

your best bet is to learn sscanf
all the specifiers and how to you it correctly on a small scale,
the best reference for sscanf is in the thread where its been released.

i know i said id rewrite this for you but i wont have the time,
(sorry I got a lil baby girl who will consume my time today!)
also iv never used zcmd or dcmd ect..
im new here and jumped right into ycmd for my command processor,

so if it was me I would convert all strok to sscanf
then once that is working id convert the hole command to zcmd. Which should be really easy.

where it will get hard is all the commands after /irc
I haven't yet made a command like this to do multiply things but I know
there is example code like that all over this site.

so i suggest you TRY to do it and when ya get stuck post your code here and we will help you threw it.
this is your best way to learn both sscanf and zcmd


good luck!
Edited my first post, I tried it and got it working partialy re read it for more info
Reply
#6

Fixed thanks to R0FLC0PTER helping me through the IRC chat
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)