Command won't perform
#1

I have worked some more on my /fedit command and when I try to use it, it doesn't do anything can any one point any of my mistakes.

pawn Код:
CMD:fedit(playerid,params[]) //This is the family edit command
{
    new ranks[10], motd[50], option[50];
    if(pInfo[playerid][USER_FACTION] < 1 && pInfo[playerid][USER_FACTIONRANK] < 10)
    {
        SendClientMessage(playerid, -1, "You have no permission to use this command.");
        return 1;
    }
    if(pInfo[playerid][USER_FACTION] > 0 && pInfo[playerid][USER_FACTIONRANK] == 10)
    {
        if(sscanf(params, "s[50]", option))
        {
            SendClientMessage(playerid, -1, "[USAGE]: /fedit (facname | rank (1-10) | motd)");
            return 1;
        }
        if(!strcmp(option, "facname", true))
        {
            new Query[256], string[256], factionname[50];
            format(factionname, 50, "%s", params);
            if(strlen(factionname) <= 50)
            {
                fInfo[pInfo[playerid][USER_FACTION]][FNAME] = factionname;
                format(Query, sizeof(Query), "UPDATE factioninfo SET fname = '%s' WHERE fid = %d", fInfo[pInfo[playerid][USER_FACTION]][FNAME], fInfo[pInfo[playerid][USER_FACTION]][FID]);
                db_query(FDatabase, Query);
                format(string, sizeof(string), "You have changed the faction name to %s.", fInfo[pInfo[playerid][USER_FACTION]][FNAME]);
                SendClientMessage(playerid, -1, string);
                return 1;
            }
        }
        if(!strcmp(option, "rank", true))
        {
            new Query[256], string[256], rankname[10], rank;
            if(sscanf(params, "ds[10]", rank, rankname))
            {
                SendClientMessage(playerid, -1, "[USAGE]: /fedit rank (rank number) (rank name)");
                return 1;
            }
            switch(rank)
            {
                case 1:
                {
                    format(rankname, 10, "%s", params);
                    if(strlen(rankname) <= 10)
                    {
                        fInfo[pInfo[playerid][USER_FACTION]][FRANK1] = rankname;
                        format(Query, sizeof(Query), "UPDATE factioninfo SET frank1 = '%s' WHERE fid = %d'", fInfo[pInfo[playerid][USER_FACTION]][FRANK1], fInfo[pInfo[playerid][USER_FACTION]][FID]);
                        db_query(FDatabase, Query);
                        format(string, sizeof(string), "You have changed the faction rank name to %s.", fInfo[pInfo[playerid][USER_FACTION]][FRANK1]);
                        SendClientMessage(playerid, -1, string);
                    }
                }
            }
        }
    }
    return true;
}
Reply
#2

You had some issues on your code and I made some improvements, my friend:
pawn Код:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

CMD:fedit(playerid, params[])
{
    new string[144], option[128];
    if(pInfo[playerid][USER_FACTION] <= 0 && pInfo[playerid][USER_FACTIONRANK] >= 11) return SendClientMessage(playerid, -1, "You have no permission to use this command.");
    if(isnull(params)) return SendClientMessage(playerid, -1, "[USAGE]: /fedit (facname/rank/motd)");

    if(strcmp(params, "facname", true, 7) == 0)
    {
        new query[256], faction_name[50];
        if(sscanf(params, "s[128]s[128]", option, faction_name)) return SendClientMessage(playerid, -1, "[USAGE]: /fedit facname (faction name)");

        if(strlen(faction_name) <= 50)
        {
            strcpy(fInfo[pInfo[playerid][USER_FACTION]][FNAME], faction_name, 50);

            format(query, sizeof(query), "UPDATE factioninfo SET fname = '%s' WHERE fid = %d", DB_Escape(faction_name), fInfo[pInfo[playerid][USER_FACTION]][FID]);
            db_query(FDatabase, query);

            format(string, sizeof(string), "You have changed the faction name to %s.", faction_name);
            SendClientMessage(playerid, -1, string);
        }
        else return SendClientMessage(playerid, -1, "Faction name is too long, please shorten it.");
    }
    else if(strcmp(params, "rank", true, 4) == 0)
    {
        new query[256], rank_number, rank_name[10];
        if(sscanf(params, "s[128]is[128]", option, rank_number, rank_name)) return SendClientMessage(playerid, -1, "[USAGE]: /fedit rank (rank number) (rank name)");

        switch(rank)
        {
            case 1:
            {
                if(strlen(rank_name) <= 10)
                {
                    strcpy(fInfo[pInfo[playerid][USER_FACTION]][FRANK1], rank_name, 50);

                    format(query, sizeof(query), "UPDATE factioninfo SET frank1 = '%s' WHERE fid = %d'", DB_Escape(rank_name), rank_number);
                    db_query(FDatabase, query);

                    format(string, sizeof(string), "You have changed the faction rank name to %s.", rank_name);
                    SendClientMessage(playerid, -1, string);
                }
                else return SendClientMessage(playerid, -1, "Rank name is too long, please shorten it.");
            }
        }
    }
    return 1;
}

stock DB_Escape(text[])
{
    new ret[80 * 2], ch, i, j;
   
    while((ch = text[i ++]) && j < sizeof(ret))
    {
        if(ch == '\'')
        {
            if(j < sizeof(ret) - 2)
            {
                ret[j ++] = '\'';
                ret[j ++] = '\'';
            }
        }
        else if(j < sizeof(ret)) ret[j ++] = ch;
        else j ++;
    }

    ret[sizeof(ret) - 1] = '\0';
    return ret;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)