/gov string length problem
#1

Well, I haven't used strmid much so I'm a bit inexperienced with it. Anyways, when I type a message that's longer than 128 characters, instead of continuing the text in the next line, it repeats the last part of the part1.

Ie:
Should be:
Код:
[Government:] Hello this is a length test, this is just done for testing. Blah blah this is a test and...
...just ignore it. Thank you.
But instead, it's like this:
Код:
[Government:] Hello this is a length test, this is just done for testing. Blah blah this is a test and...
lah blah this is a test and just ignore it. Thank you.

// And if it's even longer than this then I only get the second line shown which is weird :/
This is my code:
pawn Код:
if(strcmp(cmd, "/government", true) == 0 || strcmp(cmd, "/gov", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pFaction] != 255 && (DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 1 || DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 2 || DynamicFactions[PlayerInfo[playerid][pFaction]][fType] == 3))
            {
                if(PlayerInfo[playerid][pRank] != 1 && PlayerInfo[playerid][pRank] != 2 && PlayerInfo[playerid][pRank] != 3)
                {
                    SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] Only the top three ranks can use this command.");
                    return 1;
                }
                new length = strlen(cmdtext);
                while ((idx < length) && (cmdtext[idx] <= ' '))
                {
                    idx++;
                }
                new offset = idx;
                new result[256];
                while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                {
                    result[idx - offset] = cmdtext[idx];
                    idx++;
                }
                result[idx - offset] = EOS;
                if(!strlen(result))
                {
                    SendClientMessage(playerid, COLOR_USAGE, "[USAGE:] /(gov)ernment [text]");
                    return 1;
                }
                    if(PlayerInfo[playerid][pRank] == 1)
                    {
                        if(strlen(result)<129)
                        {
                            new faction = PlayerInfo[playerid][pFaction];
                            format(string, sizeof(string), "[Government:] %s %s: %s", DynamicFactions[faction][fRank1],GetPlayerNameEx(playerid), result);
                            SendClientMessageToAll(COLOR_POLICE, string);
                        }
                        else
                        {
                            new part1[54];
                            new part2[74];
                            strmid(part1,result,0,128,128);
                       
                            new faction = PlayerInfo[playerid][pFaction];
                            format(string, sizeof(string), "[Government:] %s %s: %s", DynamicFactions[faction][fRank1],GetPlayerNameEx(playerid), part1);
                            SendClientMessageToAll(COLOR_POLICE, string);
                       
                            strmid(part2,result,129,256,127);
                            format(string, sizeof(string), "...%s",part2);
                            SendClientMessageToAll(COLOR_POLICE, string);
                        }
                    }
                    if(PlayerInfo[playerid][pRank] == 2)
                    {
                        if(strlen(result)<54)
                        {
                            new faction = PlayerInfo[playerid][pFaction];
                            format(string, sizeof(string), "[Government:] %s %s: %s", DynamicFactions[faction][fRank2],GetPlayerNameEx(playerid), result);
                            SendClientMessageToAll(COLOR_POLICE, string);
                        }
                        else
                        {
                            new part1[54];
                            new part2[74];
                            strmid(part1,result,0,54,54);

                            new faction = PlayerInfo[playerid][pFaction];
                            format(string, sizeof(string), "[Government:] %s %s: %s", DynamicFactions[faction][fRank2],GetPlayerNameEx(playerid), result);
                            SendClientMessageToAll(COLOR_POLICE, string);

                            strmid(part2,result,55,128,74);
                            format(string, sizeof(string), "...%s",part2);
                            SendClientMessageToAll(COLOR_POLICE, string);
                        }
                    }
                    if(PlayerInfo[playerid][pRank] == 3)
                    {
                        if(strlen(result)<54)
                        {
                            new faction = PlayerInfo[playerid][pFaction];
                            format(string, sizeof(string), "[Government:] %s %s: %s", DynamicFactions[faction][fRank3],GetPlayerNameEx(playerid), result);
                            SendClientMessageToAll(COLOR_POLICE, string);
                        }
                        else
                        {
                            new part1[54];
                            new part2[74];
                            strmid(part1,result,0,54,54);

                            new faction = PlayerInfo[playerid][pFaction];
                            format(string, sizeof(string), "[Government:] %s %s: %s", DynamicFactions[faction][fRank3],GetPlayerNameEx(playerid), result);
                            SendClientMessageToAll(COLOR_POLICE, string);

                            strmid(part2,result,55,128,74);
                            format(string, sizeof(string), "...%s",part2);
                            SendClientMessageToAll(COLOR_POLICE, string);
                        }
                    }
            }
            else
            {
                SendClientMessage(playerid, COLOR_ORANGE, "[ERROR:] You're not in a valid faction.");
            }
        }
        return 1;
    }
Reply


Messages In This Thread
/gov string length problem - by Makaveli93 - 05.08.2012, 12:47
Re: /gov string length problem - by Jikesh - 05.08.2012, 14:10
Re: /gov string length problem - by Sig Hansen - 05.08.2012, 14:20

Forum Jump:


Users browsing this thread: 1 Guest(s)