Textdraw and Timers
#1

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?
Reply
#2

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;
    }
Reply
#3

Can this work with any Textdraw I put?
Reply
#4

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


Forum Jump:


Users browsing this thread: 2 Guest(s)