SA-MP Forums Archive
Text draw won't show after adding an additional color code... - 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: Text draw won't show after adding an additional color code... (/showthread.php?tid=457860)



Text draw won't show after adding an additional color code... - Scenario - 13.08.2013

Okay, so here's the deal. I am trying to dynamically list the characters in a faction and put them into a text draw. I ended up with this sliver of code:

pawn Code:
new
    szString[150],
    szFirstName[2],
    szMainString[1000];

foreach(new iTarget : Player)
{
    if(IsPlayerInFactionID(iTarget, pStats[playerid][iPlayerFaction][i]))
    {
        strmid(szFirstName, pStats[iTarget][pFirstName], 0, 1);
        format(szString, sizeof(szString), "~y~%s. %s", szFirstName, pStats[iTarget][pLastName]);
        strcat(szMainString, szString);
        strcat(szMainString, "~w~, "); // this is the problem line
    }
}

strins(szMainString, "Online Members: ", 0);
PlayerTextDrawSetString(playerid, textPlayerFactionList[2], szMainString);
Notice the commented line? Whenever that line is there, the text-draw doesn't show up. However, when I remove it, it works absolutely fine. I don't see a problem with this though because the text-draw only has (at this point) 2 color codes in it.

Does anyone have any idea why the commented line of code (basically) disables the text draw?


Re: Text draw won't show after adding an additional color code... - -Prodigy- - 13.08.2013

I've suffered through this problems before. The problem is because you leave a blank space after finishing up the list of players.

To solve it, delete the last character after you finish listing all players. So something like:

pawn Code:
strdel(szMainString, strlen(szMainString), strlen(szMainString) - 1);



Re: Text draw won't show after adding an additional color code... - Scenario - 13.08.2013

Unfortunately, that didn't solve the problem. I tried doing this:

pawn Code:
foreach(new iTarget : Player)
            {
                if(IsPlayerInFactionID(iTarget, pStats[playerid][iPlayerFaction][i]))
                {
                    strmid(szFirstName, pStats[iTarget][pFirstName], 0, 1);
                    format(szString, sizeof(szString), "~y~%s~w~. ~y~%s", szFirstName, pStats[iTarget][pLastName]);
                    strcat(szMainString, szString);
                }
            }
.. and even that didn't work right. There's something with the color codes, but I've never had an issue with them like this before so I'm just not sure why it wouldn't work!


Re: Text draw won't show after adding an additional color code... - Dokins - 13.08.2013

I'm not an expert in this field, but would it not make more sense to switch these two around?

pawn Code:
strcat(szMainString, szString);
strcat(szMainString, "~w~, "); // this is the problem line
it looks like you're trying to cat the string before it's there?
Like this..
pawn Code:
strcat(szMainString, "~w~, "); // this is the problem line
strcat(szMainString, szString);



Re: Text draw won't show after adding an additional color code... - Scenario - 13.08.2013

No it has to come after the contents of "szString". I was able to get it working with this:

pawn Code:
foreach(new iTarget : Player)
{
    if(IsPlayerInFactionID(iTarget, pStats[playerid][iPlayerFaction][0]))
    {
        strcat(szMainString, "~w~,");
        format(szString, sizeof(szString), " ~y~%s %s", pStats[iTarget][pFirstName], pStats[iTarget][pLastName]);
        strcat(szMainString, szString);
    }
}
Although it's not really what I wanted. I don't know, perhaps the period ( . ) had something to do with it..?