SA-MP Forums Archive
The string get shrink why? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: The string get shrink why? (/showthread.php?tid=578731)



The string get shrink why? - Metharon - 21.06.2015

As can you see i'm typing " Vand casa " and it get "Casa " ...



pawn Код:
if(Mobile[playerid] == 2525)
        {
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREEN, "People CNN: Ok , what is the announce??");
                return 0;
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(text);
            while ((idx < length) && (text[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[643];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = text[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            new payout = idx * SBizzInfo[6][sbEntranceCost] * 2;
            if(GetPlayerMoney(playerid) < payout + 900)
            {
                format(string,sizeof(string), "~R~NO CASH~N~~R~(%d$ )", payout);
                GameTextForPlayer(playerid, string, 5000, 1);
                Mobile[playerid] = 255;
                return 1;
            }
            if(adds == 0)
            {
                format(string,sizeof(string), "~Y~WAIT PLEASE ~R~60~Y~ SEC", payout);
                GameTextForPlayer(playerid, string, 5000, 1);
                Mobile[playerid] = 255;
                return 1;
            }
            SafeGivePlayerMoney(playerid, - payout);
            SBizzInfo[6][sbTill] += payout;
            new stringnumar[456];
            if(PlayerInfo[playerid][pPnumber] != 0)
            {
                format(stringnumar, 456, "%d", PlayerInfo[playerid][pPnumber]);
                strins(stringnumar, "-", 3);
            }
            else
            {
                stringnumar = "000-000";
            }
            new stringcnn[456];
            format(stringcnn, sizeof(stringcnn), "(Anunt publicat de %s) -  %s, (Phone: %s)",  GetName(playerid), result, stringnumar);
            OOCNews(TEAM_GROVE_COLOR,stringcnn);
            format(string, sizeof(string), "~Y~Paid ~R~%d$~n~~Y~%d Characters", payout, idx);
            GameTextForPlayer(playerid, string, 5000, 4);
            SetTimer("AddsOn", addtimer, 0); adds = 0;
            Mobile[playerid] = 255;
        }



AW: The string get shrink why? - Nero_3D - 21.06.2015

You are removing the first word by using "strtok placed in a function - godfather style", after nearly 8 years this disease isn't dead yet

Long version
pawn Код:
if(Mobile[playerid] == 2525)
        {
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GREEN, "People CNN: Ok , what is the announce??");
                return 0;
            }
            //GetPlayerName(playerid, sendername, sizeof(sendername)); // never used
            //strtok part removed
            new payout = idx * SBizzInfo[6][sbEntranceCost] * 2;
            if(GetPlayerMoney(playerid) < payout + 900)
            {
                format(string,sizeof(string), "~R~NO CASH~N~~R~(%d$ )", payout);
                GameTextForPlayer(playerid, string, 5000, 1);
                Mobile[playerid] = 255;
                return 1;
            }
            if(adds == 0) // unclear variable name
            {
                format(string,sizeof(string), "~Y~WAIT PLEASE ~R~60~Y~ SEC", payout); // payout never formated (no %d in string)
                GameTextForPlayer(playerid, string, 5000, 1);
                Mobile[playerid] = 255;
                return 1;
            }
            SafeGivePlayerMoney(playerid, - payout);
            SBizzInfo[6][sbTill] += payout;
            new stringnumar[32] = "000-000"; // why 456 cells ?
            if(PlayerInfo[playerid][pPnumber] != 0)
            {
                format(stringnumar, sizeof stringnumar, "%d", PlayerInfo[playerid][pPnumber]); // why format ? use strcat to copy a string
                strins(stringnumar, "-", 3);
            }
            new stringcnn[128]; // yeah you like the number 456
            format(stringcnn, sizeof(stringcnn), "(Anunt publicat de %s) -  %s, (Phone: %s)",  GetName(playerid), text, stringnumar);
            OOCNews(TEAM_GROVE_COLOR,stringcnn);
            format(string, sizeof(string), "~Y~Paid ~R~%d$~n~~Y~%d Characters", payout, idx);
            GameTextForPlayer(playerid, string, 5000, 4);
            SetTimer("AddsOn", addtimer, 0);
            Mobile[playerid] = 255;
            adds = 0;
        }
Short version - change in that line "result" to "text"
pawn Код:
format(stringcnn, sizeof(stringcnn), "(Anunt publicat de %s) -  %s, (Phone: %s)",  GetName(playerid), result, stringnumar);