SA-MP Forums Archive
Textdraw and Timers - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Textdraw and Timers (/showthread.php?tid=265446)



Textdraw and Timers - HydraX - 01.07.2011

So I'm just curious, I have this.

pawn Код:
public RemoveTextDraw()
{
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(gTeam[i] == TEAM_GREEN)
            {
                TextDrawHideForPlayer(i, SpawnObj_G);
            }
            if(gTeam[i] == TEAM_BLUE)
            {
                TextDrawHideForPlayer(i, SpawnObj_B);
            }
        }
    }
}
pawn Код:
SetPlayerToTeamColor(playerid);
    PlaySoundForAll(1186, 0.0, 0.0, 0.0); // Stops the music
    if(gTeam[playerid] == TEAM_GREEN)
    {
        TextDrawShowForPlayer(playerid, SpawnObj_G);
        SetTimer("RemoveTextDraw", 7000, 0);
    }
    else if(gTeam[playerid] == TEAM_BLUE)
    {
        TextDrawShowForPlayer(playerid, SpawnObj_B);
        SetTimer("RemoveTextDraw", 7000, 0);
    }
How can this be simplified? I'm trying to prevent using too many timers, I want the Textdraw to disappear after a couple of seconds. Can you help me?


Re: Textdraw and Timers - =WoR=Varth - 01.07.2011

Only one global timer.

pawn Код:
new bool:RTD1,
    bool:RTD2;
   
public OnGameModeInit()
{
    RTD1 = true;
    RTD2 = true;
    return 1;
}

public RemoveTextDraw()
{
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(gTeam[i] == TEAM_GREEN)
            {
                TextDrawHideForPlayer(i, SpawnObj_G);
            }
            if(gTeam[i] == TEAM_BLUE)
            {
                TextDrawHideForPlayer(i, SpawnObj_B);
            }
        }
    }
}

    SetPlayerToTeamColor(playerid);
    PlaySoundForAll(1186, 0.0, 0.0, 0.0); // Stops the music
    if(gTeam[playerid] == TEAM_GREEN)
    {
        TextDrawShowForPlayer(playerid, SpawnObj_G);
        if(RTD1 == true) SetTimer("RemoveTextDraw", 7000, 0),RTD1 = false;
    }
    else if(gTeam[playerid] == TEAM_BLUE)
    {
        TextDrawShowForPlayer(playerid, SpawnObj_B);
        if(RTD2 == true) SetTimer("RemoveTextDraw", 7000, 0),RTD2 = false;
    }



Re: Textdraw and Timers - HydraX - 01.07.2011

Can this work with any Textdraw I put?


Re: Textdraw and Timers - =WoR=Varth - 01.07.2011

Yes.
Remember it's one time timer. It will not started again unless you put this.
pawn Код:
RTD1 = true;
or
pawn Код:
RTD2 = true;