Switching Textdraws with Timer
#1

Hello there!
So I'd need some help because I don't know how to create a textdraws with timer.
I mean there would be 2 options textd1 and textd2. (These are the textdraws.)
And I need a timer what would delete textd1 and create textd2 then vice versa in every 3 mins.
Thank you in advance for your help.
Reply
#2

Frist way: (here the messages will not mix each others and can't be repeated more than 1 time at 3 minutes)

PHP код:
new
    
TEXT_STEP,
    
TD_AGAIN_X,
    
TD_AGAIN,
    
Text:your_TD[ MAX_PLAYERS ]
;
public 
OnGameModeInit( )
{
    
TD_AGAIN_X = SetTimer( "TDAgainX", 60 * 3, true );
    return 
1;
}
public 
OnPlayrSpawn( playerid )
{
    
TextDrawShowForPlayer( playerid, your_TD[ playerid ] );
    return 
1;
}
stock RandomTextDraw( )
{
    foreach(new 
i: Player)
    {
        if( 
TEXT_STEP == 1 )
        {
            
TextDrawSetString( your_TD[ i ], "Your first message here" );
        }
        if( 
TEXT_STEP == 0 )
        {
            
TextDrawSetString( your_TD[ i ], "Your second message here" );
        }
        
TextDrawShowForPlayer( playerid, your_TD[ i ] );
    }
    return 
1;
}
function 
TDAgainX( )
{
    
TEXT_STEP = 1;
    
RandomTextDraw( );
    
KillTimer( TD_AGAIN_X );
    
TD_AGAIN = SetTimer( "TDAgain", 60 * 3, true );
}
function 
TDAgain( )
{
    
TEXT_STEP = 0;
    
RandomTextDraw( );
    
KillTimer( TD_AGAIN );
    
TD_AGAIN_X = SetTimer( "TDAgainX", 60 * 3, true );
} 
Another way: (here one message can be repeated more than 1 time at 3 minutes)

PHP код:
new Text:your_TD[ MAX_PLAYERS ];
new 
RandomTextdraw[ ][ ] =
{
    
"Your first message",
    
"Your second message"
};
public 
OnGameModeInit( )
{
    
SetTimer( "RandomTextDrawTimer", 60 * 3, 1 );
    return 
1;
}
public 
OnPlayrSpawn( playerid )
{
    
TextDrawShowForPlayer( playerid, your_TD[ playerid ] );
    return 
1;
}
function 
RandomTextDrawTimer( )
{
    foreach(new 
i: Player)
    {
        
TextDrawSetString( your_TD[ i ], RandomTextdraw[ random( sizeof( RandomTextdraw ) ) ] );
    }
    return 
1;
} 
I literally think that you will use the first way that i gave you here.
I don't think that you want messages to repeat. So use first. It is ofc your choice.
Reply
#3

nice
Reply
#4

I guess you want random tips or messages??

PHP код:
#include <a_samp>
static Text:TD;
static 
timer;
static const 
RandM[][] =
{
    
"Message 1",
    
"Message 2",
    
"Message 3"
};
public 
OnFilterScriptInit()
{
    
TD = TextDrawCreate(315.0, 5.0, " ");
    
timer = SetTimer("RandMSG", 1000*60*3, true);
    return 
1;
}
public 
OnFilterScriptExit()
{
    
TextDrawDestroy(TD);
    
KillTimer(timer);
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
TextDrawShowForPlayer(playerid, TD);
    return 
1;
}
forward RandMSG();
public 
RandMSG()
{
    
TextDrawSetString(TD, RandM[random(sizeof(RandM))]);
    return 
1;
} 
Reply
#5

I'm not sure why FallenGirl made such a complicated snippet

You could simply:
PHP код:

new Text:textdraw[MAX_PLAYERS];
forward TextDrawDisplay(playerid, step);
public 
TextDrawDisplay(playerid, step)
{
       new 
nextstep = step;
       
TextDrawDestroy(textdraw[playerid]);
       if(
step == 2)
       {
          
SendClientMessage(playerid, -1, "That's the last of the textdraws");
          return 
1;
       }
       else if(
step == 0)
       {
          
textdraw[playerid] = TextDrawCreate(240.0,580.0,"Welcome to my SA-MP server");
       }
       else if(
step == 1)
       {
          
textdraw[playerid] = TextDrawCreate(240.0,580.0,"I hope you enjoy your stay");
       }
       
nextstep++;
       
SetTimerEx("TextDrawDisplay", 1000, false, "ii", playerid, nextstep);
} 
If you're having many textdraws, just make it a switch rather than an else if, else if, etc...
(Should work in theory, not tested :P)
Reply
#6

Quote:
Originally Posted by TadePoleMG
Посмотреть сообщение
nice
dude, this is scripting help section here all helps each other their is no need to say "nice " because here in scripting help all do well r u gonna say to all nice huh.
Reply
#7

Ohh thank you so much guys. You helped me a lot Nah i dont want random messages. I've already created some pop-up textdraws. I just want to make them to appier and disappier in a certain time. Just didnt know how to make it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)