[How To] How do I make an announcement system using a textdraw?
#1

I have this: (textdraw location)

pawn Код:
Announcements = TextDrawCreate(3.000000, 430.000000, " ");
    TextDrawAlignment(Announcements,0);
    TextDrawBackgroundColor(Announcements, 255);
    TextDrawFont(Announcements, 1);
    TextDrawLetterSize(Announcements, 0.300000, 1.000000);
    TextDrawColor(Announcements, -1);
    TextDrawSetOutline(Announcements, 0);
but I want to make about 30 different messages appear there, changing every 1 minute. How would I do that?
Reply
#2

by using
TextDrawSetString
Reply
#3

Quote:
Originally Posted by cessil
by using
TextDrawSetString
Can you please give me an example?
Reply
#4

Код:
new Text:Textan;
Top of script.

Код:
        Textan = TextDrawCreate(3.000000, 430.000000, " ");
        TextDrawAlignment(Textan,0);
	    TextDrawBackgroundColor(Textan, 255);
	    TextDrawFont(Textan, 1);
	    TextDrawLetterSize(Textan, 0.300000, 1.000000);
	    TextDrawColor(Textan, -1);
	    TextDrawSetOutline(Textan, 0)
GameModeInit


Код:
    if(strcmp(cmd,"/antd",true)==0)
    {
        new tmp[30];
        tmp = strtok(cmdtext,idx);
        new antd = strval(tmp);
        TextDrawSetString(playerid, antd);  
        TextDrawShowForPlayer(playerid, Textan);
        return 1;
    }

THIS MIGHT TURN OUT TO BE A EPIC FAIL. I don't guarantee it.
Reply
#5

Quote:
Originally Posted by www.******.com
THIS MIGHT TURN OUT TO BE A EPIC FAIL.
Its almost exactly that.

This will set random announcement for textdraw every minute and show it for everyone:
pawn Код:
new aMessage[4][128] =
{
  {"Announcement 1"},
  {"Announcement 2"},
  {"Announcement 3"},
  {"Announcement 4"}
};

public MinuteTimer() //SetTimer OnGameModeInit
{
  TextDrawSetString(Text:text, aMessage[random(sizeof(aMessage))]);
  TextDrawShowForAll(Text:text);
}
Reply
#6

here you are
Код:
#define FILTERSCRIPT

#include <a_samp>
#include <sscanf>// credits to ******
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

#define MSGCOMM_COLOR 0x55aaff77

new TextClearCounter;
new Text:TDTSBackground;
new TDTSBackgroundAlpha;
new TDTSBackgroundColor;
new Text:TDTSMessage;
new TDTSBackgroundText[320]="________________________________________________________________________________________________________________________~n~________________________________________________________________________________________________________________________";
new  TDTSMessageText[8192]="________________________________________________________________________________________________________________________newsticker textdraw filterscript loaded.";

new gScrollTimer;
new gCommercialDelay;

new CommercialOld;
new Commercials[][]=
{
	"blablablabla",
	"(samp) type /pagesize 20 to maximize the chatwindow.",
	"(cmd) type /an <text> to announce some text in the newsticker.",
	"(cmd) type /aq <text> to announce w/o the players' id/name."
};

forward ShowTDTS();
//---------------
public ShowTDTS()
//---------------
{
	TextDrawSetString(TDTSBackground,TDTSBackgroundText);
	TextDrawShowForAll(TDTSBackground);
	TextDrawSetString(TDTSMessage,TDTSMessageText);
	TextDrawShowForAll(TDTSMessage);
	return 1;
}

//-------------------------
public OnFilterScriptInit()
//-------------------------
{
	TDTSBackground=TextDrawCreate(0,435,"_");
	TextDrawLetterSize(TDTSBackground,0.198,1.28);//120
	TextDrawFont(TDTSBackground,2);
	TextDrawSetProportional(TDTSBackground,0);
	TextDrawUseBox(TDTSBackground,1);
	TextDrawBoxColor(TDTSBackground,0x3f3f3f3f);
	TextDrawSetShadow(TDTSBackground,0);
	TextDrawSetOutline(TDTSBackground,0);
	TextDrawBackgroundColor(TDTSBackground,55555555);
	TDTSMessage=TextDrawCreate(0,435,"_");
	TextDrawLetterSize(TDTSMessage,0.198,1.28);
	TextDrawFont(TDTSMessage,2);
	TextDrawSetProportional(TDTSMessage,0);
	TextDrawUseBox(TDTSMessage,0);
	TextDrawSetShadow(TDTSMessage,-1);
	TextDrawSetOutline(TDTSMessage,1);
	gScrollTimer=SetTimer("ScrollTimer",100,1);
	gCommercialDelay=SetTimer("CommercialDelay",60000,1);
	return 1;
}

public OnFilterScriptExit()
{
	TextDrawDestroy(TDTSBackground);
	TextDrawDestroy(TDTSMessage);
	KillTimer(gScrollTimer);
	KillTimer(gCommercialDelay);
	return 1;
}

forward ScrollTimer(s,Text[128]);
//----------------------------
public ScrollTimer(s,Text[128])
//----------------------------
{
	strdel(TDTSMessageText,0,1);
	new Len=strlen(TDTSMessageText);
	if(Len<120)
	{
		TextClearCounter++;
		format(TDTSMessageText,sizeof(TDTSMessageText),"%s_",TDTSMessageText);
		if(TextClearCounter>120)
		{
			TDTSBackgroundAlpha-=4;
			if(TDTSBackgroundAlpha<0)
			{
			  TDTSBackgroundAlpha=0;
			}
		}
	}
	else
	{
	  TextClearCounter=0;
		TDTSBackgroundAlpha+=2;
		if(TDTSBackgroundAlpha>127)
		{
		  TDTSBackgroundAlpha=127;
		}
	}
	TextDrawBoxColor(TDTSBackground,256*TDTSBackgroundColor+TDTSBackgroundAlpha);
	ShowTDTS();
	return 1;
}

forward CommercialDelay();
//----------------------
public CommercialDelay()
//----------------------
{
	new Rnd=(1+CommercialOld+(random(sizeof(Commercials)-1)))%sizeof(Commercials);
	AddNews(Commercials[Rnd]);
	CommercialOld=Rnd;
	return 1;
}

//---------------------------------------------
public OnPlayerCommandText(playerid, cmdtext[])
//---------------------------------------------
{
	dcmd(An, 2, cmdtext);
	dcmd(Aq, 2, cmdtext);
	return 0;
}

forward AddNews(Text[]);
//--------------------
public AddNews(Text[])
//--------------------
{
	format(TDTSMessageText,sizeof(TDTSMessageText),"%s%s_",TDTSMessageText,Text);
	ShowTDTS();
	return 1;
}

//++++++++++++++++++++++++
dcmd_An(playerid,params[])
//++++++++++++++++++++++++
{
	new Text[128];
	if (sscanf(params,"s",Text))
	{
		SendClientMessage(playerid,MSGCOMM_COLOR, "Usage: \"/An <Text>\"");
		return 1;
	}
	new playername[MAX_PLAYER_NAME];
	GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
	format(TDTSMessageText,sizeof(TDTSMessageText),"%s ]]] (%d) %s: ",TDTSMessageText,playerid,playername);
	AddNews(Text);
	return 1;
}

//++++++++++++++++++++++++
dcmd_Aq(playerid,params[])
//++++++++++++++++++++++++
{
	new Text[128];
	if (sscanf(params,"s",Text))
	{
		SendClientMessage(playerid,MSGCOMM_COLOR, "Usage: \"/Aq <Text>\"");
		return 1;
	}
	AddNews(Text);
	return 1;
}

public OnPlayerConnect(playerid)
{
	new name[MAX_PLAYER_NAME], string[48];
	GetPlayerName(playerid, name, sizeof(name));
	format(string,sizeof(string),"]]] %s joined the game.",name);
	CallRemoteFunction("AddNews","s",string);
	return 1;
}
that piece of shit was just fiddled together out of my GM, tested and working, but not optimized, give it a try!
Reply
#7

Ah, thank you all. I guess I should have gotten on xFire and asked you first Babul... :PPP
Reply
#8

nah, maybe someone else can take usage of this scrolltext. its not optimized in any way, but its working well for me ^^
maybe i will make the text scrolling each 50 ms, with 1/2 character off so the scroll looks smoother...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)