[FilterScript] News ticker
#1

simple news ticker.
This script will add a news ticker at the bottom of your screen. Those line hide 1 by one after a certain time.
to send some news from other filterscript or your game mode I recomend you to use this macro:
pawn Code:
#define SendNews(%0,%1) if(!CallRemoteFunction("SendNewsMessage", "is", %0, %1)) SendClientMessageToAll(%0,%1)
This way, if the news ticker script is not loaded, the text will be sent as a client message.

video demo:
[ame]http://www.youtube.com/watch?v=hqssz3k5aAw[/ame]

the script:
pawn Code:
/******************************************************************************/
#define SendNews(%0,%1) if(!CallRemoteFunction("SendNewsMessage", "is", %0, %1)) SendClientMessageToAll(%0,%1)
// copy this #define in any script you wish to use the News ticker system
// usage: SendNews(color, text[])
// using this macro, if the news script is loaded the text will show in the news ticker
// if the news script is NOT loaded, the text will show as a client message.
/******************************************************************************/
 
 
#define FILTERSCRIPT // its a filterscript
#define NEWS_LEN 128 //
#define NO_MASTER_TIMER // comment this line if you are using SnooB master timer infrastructure
#define TOTAL_LINE 6
#define HIDE_RATE 150
#define posX 135.0
#define start_posY 348.0
#define LINE_SPACE 10.0
#define LETTER_SIZE_X 0.252
#define LETTER_SIZE_Y 1.008
 
// isnull
#if !defined isnull
    #define isnull(%1) \
        ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
 
 
#include <a_samp>
 
 
#if defined NO_MASTER_TIMER
new LocaleTimer;
#endif
 
new
    Float:posY[TOTAL_LINE],
    NewsLine[TOTAL_LINE][NEWS_LEN],
    NewsColor[TOTAL_LINE],
    Text:News[TOTAL_LINE],
    DoNotHideNews[MAX_PLAYERS],
    NewsTimeCount;
 
 
public OnFilterScriptInit()
{
#if defined NO_MASTER_TIMER
    SetTimer("TimerSec", 1000, true);
#endif
    inittxt();
    return 1;
}
 
public OnFilterScriptExit()
{
#if defined NO_MASTER_TIMER
    KillTimer(LocaleTimer);
#endif
    for( new i = 0; i < TOTAL_LINE; i++ ) TextDrawDestroy(News[i]);
    return 1;
}
 
forward SendNewsMessage(color, text[]);
public SendNewsMessage(color, text[])
{
    NewsTimeCount = 20;
    new message[128];
    format(message, sizeof(message), "%s %s", timestamp(), text);
    ChkColorTag(message);
    printf("* [NEWS] - %s", message);
 
    for( new i = TOTAL_LINE-1; i > 0; i-- )
    {
        format(NewsLine[i], NEWS_LEN, "%s", NewsLine[i-1]);
        if(i == 3) NewsColor[i] = (NewsColor[i-1] - 0x0000001F);
        else if(i==2) NewsColor[i] = (NewsColor[i-1] - 0x0000003F);
        else if(i==1) NewsColor[i] = (NewsColor[i-1] - 0x0000003F);
        else NewsColor[i] = NewsColor[i-1];
    }
 
    format(NewsLine[0], NEWS_LEN, "%s", message);
    NewsColor[0] = color;
 
    for( new i = 0; i < TOTAL_LINE; i++ )
    {
        TextDrawColor(News[i], NewsColor[i]);
        TextDrawSetString(News[i], NewsLine[i]);
        TextDrawShowForAll(News[i]);
    }
    return 1;
}
 
inittxt()
{
    for( new i = 0; i < TOTAL_LINE; i++ )
    {
        if(i == 0) posY[i] = start_posY;
        else posY[i] = start_posY + (LINE_SPACE * i);
 
        format(NewsLine[i], NEWS_LEN, "  ");
        News[i] = TextDrawCreate(posX, posY[i],"News line"); //
        TextDrawFont(News[i],1);
        TextDrawLetterSize(News[i],LETTER_SIZE_X,LETTER_SIZE_Y);
        TextDrawColor(News[i],0xD7D7D799); //
        TextDrawSetShadow(News[i],0);
        TextDrawSetOutline(News[i],1);
        if(i < 1)TextDrawBackgroundColor(News[i],0x00000099);
        else if(i < 3)TextDrawBackgroundColor(News[i],0x3F3F3F3F);
        else TextDrawBackgroundColor(News[i],0x3F3F3F3F);
        TextDrawUseBox(News[i],0);
    }
    new str[64];
    GetServerVarAsString("hostname", str, sizeof(str));
    new line[128];
    format(line, sizeof(line),"News ticker Loaded at %s for %s.", timestamp(), str);
    print(line);
    SendNewsMessage(0xFFFFFFFF, line);
    return 1;
}
 
forward TimerSec();
public TimerSec()
{
    NewsTimeCount--;
    if(!NewsTimeCount) HideNews();
 
    return 1;
}
 
HideNews()
{
    new line_order = (TOTAL_LINE - 1);
    HideLine(TOTAL_LINE - 1);
    for( new i = 0; i < (TOTAL_LINE - 1); i++ )
    {
        SetTimerEx("HideLine", (HIDE_RATE * line_order), false, "i", i);
        line_order--;
    }
    return 1;
}
 
forward HideLine(line);
public HideLine(line)
{
    if(NewsTimeCount > 0) return 1;
    for( new playerid = 0; playerid < MAX_PLAYERS; playerid++ )
    {
        if(DoNotHideNews[playerid]) continue;
        TextDrawHideForPlayer(playerid, News[line]);
    }
    return 1;
}
 
forward HideNewsForPlayer(playerid);
public HideNewsForPlayer(playerid)
{
    if(NewsTimeCount <= 0)
    {
        for( new i = 0; i < TOTAL_LINE; i++ ) TextDrawHideForPlayer(playerid, News[i]);
    }
    DoNotHideNews[playerid] = 0;
    return 1;
}
 
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/shownews", cmdtext, true, 9) == 0)
    {
        DoNotHideNews[playerid] = 1;
        SetTimerEx("HideNewsForPlayer", 15000, false, "i", playerid);
        for( new i = 0; i < TOTAL_LINE; i++ )
        {
            TextDrawShowForPlayer(playerid, News[i]);
        }
        return 1;
    }
    return 0;
}
 
forward ChkColorTag(txtstr[]);
public ChkColorTag(txtstr[])
{
    // this function will remove any color ~TAG~ that are ~INCOMPLETE or ~WRONG~
    // this function conssider the string as valid. ( not null )
    new tag;
    new startpos;
    for(new i = 0; i < strlen(txtstr); i++)
    {
        switch (tag)
        {
            case 0: //look for any ~ in the string
            {
                if(txtstr[i] == '~')
                {
                    tag = 1; // we found a openning ~.
                    startpos = i; // we keep track of the starting position.
                }
            }
            case 1: //after we found a ~ we look if the letter is valid.
            {
                if(IsValidTagLetter(txtstr[i])) tag = 3; // letter is valid we need closing ~
                else tag = 4; // letter is not valid, we check anyway for a closing ~
            }
            case 3: // letter was valid we need a closing ~.
            {
                if(txtstr[i] != '~') strdel(txtstr,startpos, startpos + 2); // this ~TAG~ is not valid. We delete the ~ and the letter.
                // if the tag is valid we leave it there
                tag = 0; // we keep on looking for ~TAG~ in the string
            }
            case 4: // we foung a ~ and an invalid letter.
            {
                if(txtstr[i] == '~') strdel(txtstr, startpos, startpos + 3); //we found a closing ~. We delete all the ~TAG~
                else strdel(txtstr, startpos, startpos + 2); // we delete the ~ and the letter.
                tag = 0; // we keep on looking for ~TAG~ in the string
            }
        }
    }
    return 1;
}
 
IsValidTagLetter(letter)
{
    //here you can choos wich tag are valid or not.
    //if(letter == 'n') return 1; // New line
    if(letter == 'r') return 1; // Red
    if(letter == 'g') return 1; // Green
    if(letter == 'b') return 1; // Blue
    if(letter == 'w') return 1; // White
    if(letter == 'y') return 1; // Yellow
    if(letter == 'p') return 1; // Purple
    if(letter == 'l') return 1; // Black
    if(letter == 'h') return 1; // Turn text colour lighter (used too much will make your text white, doesnt work on black)
    if(letter == 'u') return 1; // up arrow (grey)
    if(letter == 'd') return 1; // down arrow (grey)
    if(letter == '<') return 1; // left arrow (grey) => i like and use that one
    if(letter == '>') return 1; // right arrow (grey) => i like and use that one
    return 0;
}
 
stock timestamp()
{
    new srvtime[3];
    gettime(srvtime[0], srvtime[1], srvtime[2]);
    new secstr[4];
    new minstr[5];
    new timestring[10];
    if(srvtime[2] < 10) format(secstr, sizeof(secstr),"0%i", srvtime[2]);
    else format(secstr, sizeof(secstr),"%i", srvtime[2]);
 
    if(srvtime[1] < 10) format(minstr, sizeof(minstr),"0%i:", srvtime[1]);
    else format(minstr, sizeof(minstr),"%i:", srvtime[1]);
 
    if(srvtime[0] < 10) format(timestring, sizeof(timestring),"0%i:%s%s", srvtime[0],minstr,secstr);
    else format(timestring, sizeof(timestring),"%i:%s%s", srvtime[0],minstr,secstr);
    return timestring;
}
 
//EOF
also available from http://snoob-community.wikispaces.com/News+ticker
Reply
#2

Sweet!.......
Reply
#3

Awesome! I was looking for this! GJ.
Reply
#4

VeRY NICE !!!!!!!!!
Reply
#5

Quote:
Originally Posted by Adriano499
View Post
VeRY NICE !!!!!!!!!
not very ....................
Reply
#6

How is it not nice, this is a script i have not seen in a long time. Good Job Snoob cough**214**cough
Reply
#7

Seems nice , but how i can add messages ?
Reply
#8

how to add message?
Reply
#9

awasome thx!
Reply
#10

Same question here, how do we add more news?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)