SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 20/07/2010, 03:25 PM   #1
snoob
Big Clucker
 
snoob's Avatar
 
Join Date: Aug 2008
Posts: 132
Reputation: 0
Default News ticker

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
__________________



Last edited by snoob; 20/07/2010 at 03:37 PM. Reason: sig missing
snoob is offline   Reply With Quote
Old 20/07/2010, 03:27 PM   #2
Jackster
Banned
 
Join Date: Apr 2010
Posts: 221
Reputation: 0
Default Re: News ticker

Sweet!.......
Jackster is offline   Reply With Quote
Old 20/07/2010, 04:43 PM   #3
Zh3r0
High-roller
 
Join Date: Mar 2008
Posts: 4,510
Reputation: 398
Default Re: News ticker

Awesome! I was looking for this! GJ.
__________________
Zh3r0 is offline   Reply With Quote
Old 20/07/2010, 09:00 PM   #4
Adriano499
Big Clucker
 
Adriano499's Avatar
 
Join Date: May 2010
Posts: 137
Reputation: 0
Default Respuesta: News ticker

VeRY NICE !!!!!!!!!
Adriano499 is offline   Reply With Quote
Old 20/07/2010, 09:26 PM   #5
markokk888
Little Clucker
 
markokk888's Avatar
 
Join Date: Mar 2010
Posts: 34
Reputation: 0
Default Re: Respuesta: News ticker

Quote:
Originally Posted by Adriano499 View Post
VeRY NICE !!!!!!!!!
not very ....................
markokk888 is offline   Reply With Quote
Old 20/07/2010, 09:56 PM   #6
[L3th4l]
Guest
 
Posts: n/a
Default Re: News ticker

How is it not nice, this is a script i have not seen in a long time. Good Job Snoob cough**214**cough
  Reply With Quote
Old 21/03/2011, 10:33 AM   #7
Mr.Jvxmc
Huge Clucker
 
Mr.Jvxmc's Avatar
 
Join Date: Mar 2010
Posts: 306
Reputation: 0
Default Re: News ticker

Seems nice , but how i can add messages ?
__________________
Mr.Jvxmc is offline   Reply With Quote
Old 21/03/2011, 10:35 AM   #8
Medal Of Honor team
Gangsta
 
Medal Of Honor team's Avatar
 
Join Date: Feb 2011
Location: Osama Bin Laden's house ;)
Posts: 505
Reputation: 2
Default Re: News ticker

how to add message?
__________________
Making a Social Website from scratch. Need a PHP partner
Medal Of Honor team is offline   Reply With Quote
Old 21/03/2011, 11:07 AM   #9
[ProX]BlueFire
Huge Clucker
 
[ProX]BlueFire's Avatar
 
Join Date: Mar 2011
Location: on the toilet xD
Posts: 331
Reputation: 6
Default Re: News ticker

awasome thx!
__________________
NEW NAME!
NEW ACCOUNT!
my new account name is:xkirill!!
my RP name is:Kirill_Forth
[ProX]BlueFire is offline   Reply With Quote
Old 21/03/2011, 06:55 PM   #10
Master_Gangster
Huge Clucker
 
Master_Gangster's Avatar
 
Join Date: Jan 2009
Posts: 269
Reputation: 0
Default Re: News ticker

Same question here, how do we add more news?
Master_Gangster is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 07:49 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.