new Text:InfoText[MAX_PLAYERS], DisplayingText[MAX_PLAYERS], TextTiming[MAX_PLAYERS];
stock CreateInfoTextDraw(playerid)
{
InfoText[playerid] = TextDrawCreate(319.000000, 380.000000, "");
TextDrawAlignment(InfoText[playerid], 2);
TextDrawBackgroundColor(InfoText[playerid], 255);
TextDrawFont(InfoText[playerid], 1);
TextDrawLetterSize(InfoText[playerid], 0.320000, 1.500000);
TextDrawSetProportional(InfoText[playerid], 1);
TextDrawSetShadow(InfoText[playerid], 1);
}
stock DisplayInfoTextDraw(playerid, str[], duration)
{
if(DisplayingText[playerid])
{
KillTimer(TextTiming[playerid]);
}
TextDrawSetString(InfoText[playerid], str);
TextDrawShowForPlayer(playerid, InfoText[playerid]);
TextTiming[playerid] = SetTimerEx("HideInfoTextDraw", duration *1000, 0, "i", playerid);
DisplayingText[playerid] = 1;
return 1;
}
stock HideInfoTextDraw(playerid)
{
TextDrawHideForPlayer(playerid, InfoText[playerid]);
DisplayingText[playerid] = 0;
return 1;
}
stock MonthName(Month)
{
new MonthStr[15];
switch(Month)
{
case 1: MonthStr = "January";
case 2: MonthStr = "February";
case 3: MonthStr = "March";
case 4: MonthStr = "April";
case 5: MonthStr = "May";
case 6: MonthStr = "June";
case 7: MonthStr = "July";
case 8: MonthStr = "August";
case 9: MonthStr = "September";
case 10: MonthStr = "October";
case 11: MonthStr = "November";
case 12: MonthStr = "December";
}
return MonthStr;
}
CMD:time(playerid,params[])
{
new month, day, year, hour, minute, second, str[500];
getdate(year, month, day);
gettime(hour, minute, second);
if(Account[playerid][Prison] == 1)
{
format(str, sizeof(str), "~y~%02d %s, %d ~w~~n~%02d:%02d:%02d~n~Prison Sentence: %d minutes and %d seconds", day, MonthName(month), year, hour, minute, second, Account[playerid][PrisonTime] / 60, Account[playerid][PrisonTime] / 60 / 60);
}
else
{
format(str, sizeof(str), "~y~%02d %s, %d ~w~~n~%02d:%02d:%02d", day, MonthName(month), year, hour, minute, second);
}
DisplayInfoTextDraw(playerid, str, 8);
return 1;
}
new str[500]; new MonthStr[15];
Alright, few things ...
1. You're using global textdraws everywhere, that's not good, since you'll hit the max of 2048 quite quick. In your time command you show one of two things:
2. You don't initialize your textdraws, this can lead to very strange behaviour in the future. 3. You're also doing this: Код:
new str[500]; new MonthStr[15]; Other than that, I just tested you're code, and the time does show for me. |
I am getting this black box, how come it would work for you? I'm confused. What's wrong with making a textdraw like this? I don't want to make 200 different textdraws, just change the text based on what I want to tell the player at that time.
|
That's because most likely you've hit the global textdraw limit (just like I've told you you would) and the script is trying to display another textdraw and not the one you just created.
|
I understand, so how would I go over making it a player textdraw instead?
|
new PlayerText:InfoText[MAX_PLAYERS] = {PlayerText:INVALID_TEXT_DRAW, ...}, DisplayingText[MAX_PLAYERS], TextTiming[MAX_PLAYERS], AnimTiming[MAX_PLAYERS];
stock CreateInfoTextDraw(playerid)
{
InfoText[playerid] = CreatePlayerTextDraw(playerid, 319.000000, 380.000000, "");
PlayerTextDrawAlignment(playerid, InfoText[playerid], 2);
PlayerTextDrawBackgroundColor(playerid, InfoText[playerid], 255);
PlayerTextDrawFont(playerid, InfoText[playerid], 1);
PlayerTextDrawLetterSize(playerid, InfoText[playerid], 0.320000, 1.500000);
PlayerTextDrawSetProportional(playerid, InfoText[playerid], 1);
PlayerTextDrawSetShadow(playerid, InfoText[playerid], 1);
}
stock DisplayInfoTextDraw(playerid, str[], duration)
{
if(DisplayingText[playerid])
{
KillTimer(TextTiming[playerid]);
}
PlayerTextDrawSetString(playerid, InfoText[playerid], str);
PlayerTextDrawShow(playerid, InfoText[playerid]);
TextTiming[playerid] = SetTimerEx("HideInfoTextDraw", duration *1000, 0, "i", playerid);
AnimTiming[playerid] = SetTimerEx("AnimTimer", 2000, false, "i", playerid);
DisplayingText[playerid] = 1;
return 1;
}
forward HideInfoTextDraw(playerid);
public HideInfoTextDraw(playerid)
{
PlayerTextDrawHide(playerid, InfoText[playerid]);
DisplayingText[playerid] = 0;
return 1;
}
public OnPlayerConnect(playerid)
{
CreateInfoTextDraw(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
DisplayingText[playerid] = 0;
InfoText[playerid] = PlayerText:INVALID_TEXT_DRAW;
return 1;
}