SA-MP Forums Archive
Switching TextDraw string.. - 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: Switching TextDraw string.. (/showthread.php?tid=492710)



Switching TextDraw string.. - Tayab - 05.02.2014

I don't know how to explain this but I'll try my best.

I am trying to make a Joining/Parting text draw which will show the last four players either joined or parted. When player connects I want it to add latest in the bottom. Like this


JOIN: Alex Sanchez
PART: Leo Messi
JOIN: Nemyar
JOIN: Xavi

Now if Renaldo comes on, it shows "JOIN: Renoldo" in place of "JOIN: Xavi" and "JOIN: Xavi will slide up and so will Nemyar and all above it. But "JOIN: Alex Sahchez will just disappear and in place of that will come "PART: Leo Messi"

I hope it's understandable. Here's what I've got so far.

OnGameModeInit();
pawn Код:
JoinPart[0] = TextDrawCreate(550.0,352.0,"Empty1");
    JoinPart[1] = TextDrawCreate(550.0,368.0,"Empty2");
    JoinPart[2] = TextDrawCreate(550.0,384.0,"Empty3");
    JoinPart[3] = TextDrawCreate(550.0,400.0,"Empty4");
    for(new i = 0; i < 4; i++)
    {
        TextDrawTextSize(JoinPart[i],0.5, 1.0);
        TextDrawColor(JoinPart[i],0xFFFFFFFF);
        TextDrawAlignment(JoinPart[i],1);
        TextDrawFont(JoinPart[i],2);
        TextDrawSetOutline(JoinPart[i],1);
        TextDrawSetProportional(JoinPart[i],1);
        TextDrawSetShadow(JoinPart[i],1);
    }
Don't know what to do after that. Please help me get going!


Re: Switching TextDraw string.. - CuervO - 05.02.2014

pawn Код:
new joinorder = 0;
new JoinText[4][38];

public OnPlayerConnect(playerid)
{
    if(joinorder == 3)
    {
        for(new i = 2; i >= 0; i --)
        {//descending loop starting from 2.
        //This will put whatever it was in 2 at 3, 1 at 2 and 0 at 1.
            TextDrawSetString(JoinPart[i+1], JoinText[i]);
            format(JoinText[i+1], 38, "%s", JoinText[i]);
        }
        joinorder = 0; //reset variable.
       
    }

    format(JoinText[joinorder],38,"~G~JOIN: ~w~%s.", PlayerName(playerid)); //assuming you've got this stock, otherwise create it.
    TextDrawSetString(JoinPart[joinorder], JoinText[joinorder]);
    joinorder ++;

    return 1;
}

public OnPlayerDisconnect(playerid)
{
    if(joinorder == 3)
    {
        for(new i = 2; i >= 0; i --)
        {//descending loop starting from 2.
        //This will put whatever it was in 2 at 3, 1 at 2 and 0 at 1.
            TextDrawSetString(JoinPart[i+1], JoinText[i]);
            format(JoinText[i+1], 38, "%s", JoinText[i]);
        }
        joinorder = 0; //reset variable.

    }

    format(JoinText[joinorder],38,"~r~PART: ~w~%s.", PlayerName(playerid)); //assuming you've got this stock, otherwise create it.
    TextDrawSetString(JoinPart[joinorder], JoinText[joinorder]);
    joinorder ++;

    return 1;
}
You've got to store somewhere each line's text and the text order. When a player connect it sets the first line (Textdraw ID stored at [0]) and then raises the internal order count. The next player that connects will get it at [1] and so on until it reaches the third array ([3]). If that happens then a descending loop will move whatever it was from line 2 to line 3, from line 1 to line 2 and from line 0 to line 1. Then it'll proceed to put the new text on line 0. I haven't tested this.


Re: Switching TextDraw string.. - Tayab - 06.02.2014

Thanks so much.. That makes a lot more sense!