/makeclan (this drives me crazy)
#1

So been working on this for too long.. stupid thing just doesnt work..:

pawn Код:
if(strcmp(cmd, "/setclan", true) == 0)
    {
        if(AccountInfo[playerid][AdminLevel] >= 4)
        {
            new clanname, clantag;
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");
                return 1;
            }

            clanname = strval(tmp);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");

            tmp = strtok(cmdtext, idx);
            clantag = strval(tmp);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");

            format(string, sizeof(string), "clans/%s.ini", clanname);
            if(dini_Exists(string)) return SendClientMessage(playerid,COLOR_RED, "Clan exists already");
            if(!dini_Exists(string))
            {
                    dini_Create(string);
            }

            dini_Set(string, "clantag", clantag);
            format(string, sizeof(string), "Clan %s using clantag %s was successfully created", clanname, clantag);
            SendClientMessage(playerid, COLOR_GREEN, string);
            SendClientMessage(playerid, COLOR_GREEN, "Use /setclanmember [clan name] [player ID] to add a clanmember");
            return 1;
        }
        else return SendClientMessage(playerid,COLOR_RED, "You're not authorized to use that command");
    }
What happens in I /setclan TestClan [clan]

Clientmessage: Clan using clantag was successfully created (so no names).
A file is made in clans folder called ".ini" (so no name).

Please help me I'm desperite :P
Reply
#2

Add some indentation and I'll be more than willing to help, currently it's just a straight block of code
Reply
#3

Quote:
Originally Posted by Redgie
Add some indentation and I'll be more than willing to help, currently it's just a straight block of code
It wasnt that bad :/
Only 2 lines were jumped. Fixed it
(ps. I use firefox, maybe it doesnt show good in IE??)
Reply
#4

Hypar how did you fix it because I think I got the same problem with /factionname
Reply
#5

Quote:
Originally Posted by Benne
Hypar how did you fix it because I think I got the same problem with /factionname
I didn't I posted this question 2 hours ago and still don't have an awnser :P
I'm trying to fix it myself so I will definitly let you know if I fixed it.
Reply
#6

Shouldn't It Be:

pawn Код:
new clanname[128], clantag[10];
Or something, don't know how big you want the strings...
Reply
#7

The whole thing isn't working -_-
Even if I cahnge it to that it's just not working. I have to use

pawn Код:
new length = strlen(cmdtext);
                while ((idx < length) && (cmdtext[idx] <= ' '))
                {
                    idx++;
                }
                new offset = idx;
                new clanname[128];
                while ((idx < length) && ((idx - offset) < (sizeof(clanname) - 1)))
                {
                    clanname[idx - offset] = cmdtext[idx];
                    idx++;
                }
                clanname[idx - offset] = EOS;
twice, for the clanname and clantag but I dont know where and how to use that stupid code.
Reply
#8

pawn Код:
if(strcmp(cmd, "/setclan", true) == 0)
    {
        if(AccountInfo[playerid][AdminLevel] >= 4)
        {
            new clanname[32], clantag[32];
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");
                return 1;
            }
            format(clanname, sizeof(clanname), tmp);

            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");
            format(clantag, sizeof(clantag), tmp);

            format(string, sizeof(string), "clans/%s.ini", clanname);
            if(dini_Exists(string)) return SendClientMessage(playerid,COLOR_RED, "Clan exists already");
            else
            {
                    dini_Create(string);
            }

            dini_Set(string, "clantag", clantag);
            format(string, sizeof(string), "Clan %s using clantag %s was successfully created", clanname, clantag);
            SendClientMessage(playerid, COLOR_GREEN, string);
            SendClientMessage(playerid, COLOR_GREEN, "Use /setclanmember [clan name] [player ID] to add a clanmember");
            return 1;
        }
        else return SendClientMessage(playerid,COLOR_RED, "You're not authorized to use that command");
    }
Reply
#9

I've never used strtok but use sscanf, but i think i've realised a problem.

Here you have:

pawn Код:
if(strcmp(cmd, "/setclan", true) == 0)
Then a few lines later you have:
pawn Код:
new clanname, clantag;
            tmp = strtok(cmdtext, idx); /// "cmdtext" should be "cmd"
Shouldn't "cmdtext" should be "cmd" or vice versa?

So your whole command should look like this:

pawn Код:
if(strcmp(cmd, "/setclan", true) == 0)
    {
        if(AccountInfo[playerid][AdminLevel] >= 4)
        {
            new clanname, clantag;
            tmp = strtok(cmd, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");
                return 1;
            }

            clanname = strval(tmp);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");

            tmp = strtok(cmd, idx);
            clantag = strval(tmp);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");

            format(string, sizeof(string), "clans/%s.ini", clanname);
            if(dini_Exists(string)) return SendClientMessage(playerid,COLOR_RED, "Clan exists already");
            if(!dini_Exists(string))
            {
                    dini_Create(string);
            }

            dini_Set(string, "clantag", clantag);
            format(string, sizeof(string), "Clan %s using clantag %s was successfully created", clanname, clantag);
            SendClientMessage(playerid, COLOR_GREEN, string);
            SendClientMessage(playerid, COLOR_GREEN, "Use /setclanmember [clan name] [player ID] to add a clanmember");
            return 1;
        }
        else return SendClientMessage(playerid,COLOR_RED, "You're not authorized to use that command");
    }
or ( i think the one above is the one you need)

pawn Код:
if(strcmp(cmdtext, "/setclan", true) == 0)
    {
        if(AccountInfo[playerid][AdminLevel] >= 4)
        {
            new clanname, clantag;
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");
                return 1;
            }

            clanname = strval(tmp);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");

            tmp = strtok(cmdtext, idx);
            clantag = strval(tmp);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /setclan [clan name] [tag]");

            format(string, sizeof(string), "clans/%s.ini", clanname);
            if(dini_Exists(string)) return SendClientMessage(playerid,COLOR_RED, "Clan exists already");
            if(!dini_Exists(string))
            {
                    dini_Create(string);
            }

            dini_Set(string, "clantag", clantag);
            format(string, sizeof(string), "Clan %s using clantag %s was successfully created", clanname, clantag);
            SendClientMessage(playerid, COLOR_GREEN, string);
            SendClientMessage(playerid, COLOR_GREEN, "Use /setclanmember [clan name] [player ID] to add a clanmember");
            return 1;
        }
        else return SendClientMessage(playerid,COLOR_RED, "You're not authorized to use that command");
    }
Reply
#10

Quote:
Originally Posted by [B2K
Hustler ]
Shouldn't "cmdtext" should be "cmd" or vice versa?
No, they were correct.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)