TD Color changer
#1

How do I make this Textdraw change colors every 3 seconds or so?

Код:
	PYWNICA1[playerid] = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(PYWNICA1[playerid], 255);
	TextDrawFont(PYWNICA1[playerid], 1);
	TextDrawLetterSize(PYWNICA1[playerid], 0.490000, 1.400000);
	TextDrawColor(PYWNICA1[playerid], -1);
	TextDrawSetOutline(PYWNICA1[playerid], 0);
	TextDrawSetProportional(PYWNICA1[playerid], 1);
	TextDrawSetShadow(PYWNICA1[playerid], 1);
	TextDrawUseBox(PYWNICA1[playerid], 1);
	TextDrawBoxColor(PYWNICA1[playerid], 100);
	TextDrawTextSize(PYWNICA1[playerid], 370.000000, 0.000000);
	
	PYWNICA2[playerid] = TextDrawCreate(282.000000, 1.000000, "LSDM");
	TextDrawBackgroundColor(PYWNICA2[playerid], 255);
	TextDrawFont(PYWNICA2[playerid], 1);
	TextDrawLetterSize(PYWNICA2[playerid], 0.629999, 1.200000);
	TextDrawColor(PYWNICA2[playerid], -1);
	TextDrawSetOutline(PYWNICA2[playerid], 0);
	TextDrawSetProportional(PYWNICA2[playerid], 1);
	TextDrawSetShadow(PYWNICA2[playerid], 1);
?
Reply
#2

Set a timer? Set a timer to tick every 3 seconds and set the textdraw color through there.
Reply
#3

Try this
Код:
new Text:firstcolor;
new Text:secondcolor;
new Text:thirdcolor;
new havecolor[MAX_PLAYERS] = 0;

public OnGameModeInit()
{
	firstcolor = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(firstcolor, 255);
	TextDrawFont(firstcolor, 1);
	TextDrawLetterSize(firstcolor, 0.490000, 1.400000);
	TextDrawColor(firstcolor, -1);
	TextDrawSetOutline(firstcolor, 0);
	TextDrawSetProportional(firstcolor, 1);
	TextDrawSetShadow(firstcolor, 1);
	TextDrawUseBox(firstcolor, 1);
	TextDrawBoxColor(firstcolor, 100);
	TextDrawTextSize(firstcolor, 370.000000, 0.000000);

	secondcolor = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(secondcolor, 255);
	TextDrawFont(secondcolor, 1);
	TextDrawLetterSize(secondcolor, 0.490000, 1.400000);
	TextDrawColor(secondcolor, -1);
	TextDrawSetOutline(secondcolor, 0);
	TextDrawSetProportional(secondcolor, 1);
	TextDrawSetShadow(secondcolor, 1);
	TextDrawUseBox(secondcolor, 1);
	TextDrawBoxColor(secondcolor, 100);
	TextDrawTextSize(secondcolor, 370.000000, 0.000000);
	
	thirdcolor = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(thirdcolor, 255);
	TextDrawFont(thirdcolor, 1);
	TextDrawLetterSize(thirdcolor, 0.490000, 1.400000);
	TextDrawColor(thirdcolor, -1);
	TextDrawSetOutline(thirdcolor, 0);
	TextDrawSetProportional(thirdcolor, 1);
	TextDrawSetShadow(thirdcolor, 1);
	TextDrawUseBox(thirdcolor, 1);
	TextDrawBoxColor(thirdcolor, 100);
	TextDrawTextSize(thirdcolor, 370.000000, 0.000000);
	return 1;
}
public OnPlayerConnect(playerid)
{
	havecolor[playerid] = 1;
	SetTimerEx("changingcolor", 3000, true, "i", playerid);r
	return 1;
}
forward changingcolor(playerid);
public changingcolor(playerid)
{
	if(havecolor[playerid] == 1)
	{
	    TextDrawHideForPlayer(playerid, thirdcolor);
	    TextDrawShowForPlayer(playerid, firstcolor);
		havecolor[playerid] = 2;
	}
	else if(havecolor[playerid] == 2)
	{
 	    TextDrawHideForPlayer(playerid, firstcolor);
	    TextDrawShowForPlayer(playerid, secondcolor);
	    havecolor[playerid] = 3;
	}
	else if(havecolor[playerid] == 3)
	{
 		TextDrawHideForPlayer(playerid, secondcolor);
	    TextDrawShowForPlayer(playerid, thirdcolor);
		havecolor[playerid] = 1;
	}
	return 1;
}
Reply
#4

Quote:
Originally Posted by AstroPoid
Посмотреть сообщение
Try this
Код:
new Text:firstcolor;
new Text:secondcolor;
new Text:thirdcolor;
new havecolor[MAX_PLAYERS] = 0;

public OnGameModeInit()
{
	firstcolor = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(firstcolor, 255);
	TextDrawFont(firstcolor, 1);
	TextDrawLetterSize(firstcolor, 0.490000, 1.400000);
	TextDrawColor(firstcolor, -1);
	TextDrawSetOutline(firstcolor, 0);
	TextDrawSetProportional(firstcolor, 1);
	TextDrawSetShadow(firstcolor, 1);
	TextDrawUseBox(firstcolor, 1);
	TextDrawBoxColor(firstcolor, 100);
	TextDrawTextSize(firstcolor, 370.000000, 0.000000);

	secondcolor = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(secondcolor, 255);
	TextDrawFont(secondcolor, 1);
	TextDrawLetterSize(secondcolor, 0.490000, 1.400000);
	TextDrawColor(secondcolor, -1);
	TextDrawSetOutline(secondcolor, 0);
	TextDrawSetProportional(secondcolor, 1);
	TextDrawSetShadow(secondcolor, 1);
	TextDrawUseBox(secondcolor, 1);
	TextDrawBoxColor(secondcolor, 100);
	TextDrawTextSize(secondcolor, 370.000000, 0.000000);
	
	thirdcolor = TextDrawCreate(251.000000, 0.000000, "_");
	TextDrawBackgroundColor(thirdcolor, 255);
	TextDrawFont(thirdcolor, 1);
	TextDrawLetterSize(thirdcolor, 0.490000, 1.400000);
	TextDrawColor(thirdcolor, -1);
	TextDrawSetOutline(thirdcolor, 0);
	TextDrawSetProportional(thirdcolor, 1);
	TextDrawSetShadow(thirdcolor, 1);
	TextDrawUseBox(thirdcolor, 1);
	TextDrawBoxColor(thirdcolor, 100);
	TextDrawTextSize(thirdcolor, 370.000000, 0.000000);
	return 1;
}
public OnPlayerConnect(playerid)
{
	havecolor[playerid] = 1;
	SetTimerEx("changingcolor", 3000, true, "i", playerid);r
	return 1;
}
forward changingcolor(playerid);
public changingcolor(playerid)
{
	if(havecolor[playerid] == 1)
	{
	    TextDrawHideForPlayer(playerid, thirdcolor);
	    TextDrawShowForPlayer(playerid, firstcolor);
		havecolor[playerid] = 2;
	}
	else if(havecolor[playerid] == 2)
	{
 	    TextDrawHideForPlayer(playerid, firstcolor);
	    TextDrawShowForPlayer(playerid, secondcolor);
	    havecolor[playerid] = 3;
	}
	else if(havecolor[playerid] == 3)
	{
 		TextDrawHideForPlayer(playerid, secondcolor);
	    TextDrawShowForPlayer(playerid, thirdcolor);
		havecolor[playerid] = 1;
	}
	return 1;
}
, why the hell would you create 3 textdraws JUST to change the color? that's just irrelevant memory & time taken for those extra variables and textdraws created.
Reply
#5

you can simply change textdraw's colors with TextDrawColor, than hide and show to the player.
Reply
#6

Took me a while to get this working and I thank Max for his precious help.

This is the code you replace the original with:

pawn Код:
PYWNICA1[playerid] = TextDrawCreate(251.000000, 0.000000, "_");
    TextDrawBackgroundColor(PYWNICA1[playerid], tdC); //Background color becomes a variable.
    TextDrawFont(PYWNICA1[playerid], 1);
    TextDrawLetterSize(PYWNICA1[playerid], 0.490000, 1.400000);
    TextDrawColor(PYWNICA1[playerid], -1);
    TextDrawSetOutline(PYWNICA1[playerid], 0);
    TextDrawSetProportional(PYWNICA1[playerid], 1);
    TextDrawSetShadow(PYWNICA1[playerid], 1);
    TextDrawUseBox(PYWNICA1[playerid], 1);
    TextDrawBoxColor(PYWNICA1[playerid], 100);
    TextDrawTextSize(PYWNICA1[playerid], 370.000000, 0.000000);
   
    PYWNICA2[playerid] = TextDrawCreate(282.000000, 1.000000, "LSDM");
    TextDrawBackgroundColor(PYWNICA2[playerid], tdC); //Background color becomes a variable.
    TextDrawFont(PYWNICA2[playerid], 1);
    TextDrawLetterSize(PYWNICA2[playerid], 0.629999, 1.200000);
    TextDrawColor(PYWNICA2[playerid], -1);
    TextDrawSetOutline(PYWNICA2[playerid], 0);
    TextDrawSetProportional(PYWNICA2[playerid], 1);
    TextDrawSetShadow(PYWNICA2[playerid], 1);

pawn Код:
new tdColorArr[4] = {255, 74, 22, 138};
new tdC = 255;

// printf("%d", tdC); --> used for debug

forward changeColor();
public changeColor() {
    // printf("%d", tdColorArr[tdC]);  --> used for debug
    tdC = (tdC + 1) % sizeof(tdColorArr);
    return 1;
}
pawn Код:
//Under OnGameModeInit
setTimer("changeColor", 3000, true);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)