Textdraw with string?
#1

Hey.

Made a very simple textdraw using a textdraw editor. I'm trying to find out how it works, and was wondering how it works with text that is "dynamic". For instance I have made a stock called ServerMSG which basically will print SERVER: %s. So when I use it I just write ServerMSG(playerid, "message here"); right.

How could I print that text in a textdraw? I'm a bit confused. So this is what I exported from the textdraw editor - by the way, are these [0]'s after [playerid] needed? I assume it is textdraw IDs, but if you name them uniquely will it be a problem without that ID? Here's my textdraw:

Код:
MSGTextdraw[playerid][0] = CreatePlayerTextDraw(playerid, 357.333526, 423.126220, "SERVER: %s");
PlayerTextDrawLetterSize(playerid, MSGTextdraw[playerid][0], 0.400000, 1.600000);
PlayerTextDrawAlignment(playerid, MSGTextdraw[playerid][0], 2);
PlayerTextDrawColor(playerid, MSGTextdraw[playerid][0], -1);
PlayerTextDrawSetShadow(playerid, MSGTextdraw[playerid][0], 0);
PlayerTextDrawSetOutline(playerid, MSGTextdraw[playerid][0], 0);
PlayerTextDrawBackgroundColor(playerid, MSGTextdraw[playerid][0], 255);
PlayerTextDrawFont(playerid, MSGTextdraw[playerid][0], 1);
PlayerTextDrawSetProportional(playerid, MSGTextdraw[playerid][0], 1);
PlayerTextDrawSetShadow(playerid, MSGTextdraw[playerid][0], 0);
My stock:
Код:
stock ServerMSG(playerid, message[])
{
	format(msg, sizeof(msg), "[SERVER]:{FFFFFF} %s", message);
	ServerMSG[playerid] = CreatePlayerTextDraw(playerid, 357.333526, 423.126220, msg);
	TextDrawShowForPlayer(playerid, MSGTextdraw:msg);
	PlayerTextDrawShow(playerid, ServerMSG[playerid]);
}
That didn't work out well.. not sure how it is supposed to be. Any tips?
Reply
#2

PHP код:
stock ServerMSG(playeridmessage[])
{
    new 
msg[100];//Don't really need that high value
    
format(msgsizeof(msg), "[SERVER]:{FFFFFF} %s"message);
    
PlayerTextDrawSetString(playerid,MSGTextdraw[playerid][0],msg); 
    
PlayerTextDrawShow(playeridServerMSG[playerid]);

Reply
#3

If this is a global textdraw that is the same for all players then you should use a normal textdraw and create it in OnGameModeInit. Saves the headache of using arrays and lowers the load in OnPlayerConnect. Then use TextDrawSetString to update the text. Textdraw does not need to be reshown if the text is updated.

Pet peeve of mine: It's "a function" or "a stock function" but never just "a stock". This terminology is misunderstood and consequently misused by many people.
Reply
#4

Quote:
Originally Posted by WhiteGhost
Посмотреть сообщение
PHP код:
stock ServerMSG(playeridmessage[])
{
        new 
msg[100];//Don't really need that high value
    
format(msgsizeof(msg), "[SERVER]:{FFFFFF} %s"message);
    
PlayerTextDrawSetString(playerid,MSGTextdraw[0][playerid],msg); 
    
PlayerTextDrawShow(playeridServerMSG[playerid]);

There's no changes expect for that new variable which is a global variable that I have. I get two errors messages though, and that is

Код:
MSGTextdraw[playerid][0] = CreatePlayerTextDraw(playerid, 357.333526, 423.126220, "-"); // rror 010: invalid function or declaration
PlayerTextDrawLetterSize(playerid, MSGTextdraw[playerid][0], 0.400000, 1.600000);
PlayerTextDrawAlignment(playerid, MSGTextdraw[playerid][0], 2);
PlayerTextDrawColor(playerid, MSGTextdraw[playerid][0], -1);
PlayerTextDrawSetShadow(playerid, MSGTextdraw[playerid][0], 0);
PlayerTextDrawSetOutline(playerid, MSGTextdraw[playerid][0], 0);
PlayerTextDrawBackgroundColor(playerid, MSGTextdraw[playerid][0], 255);
PlayerTextDrawFont(playerid, MSGTextdraw[playerid][0], 1);
PlayerTextDrawSetProportional(playerid, MSGTextdraw[playerid][0], 1);
PlayerTextDrawSetShadow(playerid, MSGTextdraw[playerid][0], 0); // symbol is never used
1 error and 1 warning. Invalud function or delcaration and symbol is never used (well it's used in the stock?)

Update: It is only supposed to be shown for a player. I'm thinking about adding a timer, so it'll just be visible for a few seconds before it dissapears. Example: SERVER: You have logged in. (3 seconds later it dissapears).
Reply
#5

Код:
PlayerTextDrawSetString(playerid,MSGTextdraw[playerid][0],msg);
Was An Example Though..

Edit: What you wanna hide the textdraw after 3s?
Reply
#6

Quote:
Originally Posted by WhiteGhost
Посмотреть сообщение
Код:
PlayerTextDrawSetString(playerid,MSGTextdraw[playerid][0],msg);
Was An Example Though..

Edit: What you wanna hide the textdraw after 3s?
Don't really get your question, but I want to hide the textdraw because it is just supposed to show a short message. Whether it tells the person that he has logged in or if he has bought something for instance. It's just like a popup message, not gonna stay there forever.


Tried fixing it, but this weird thing shows up:
Код:
PlayerTextDrawLetterSize(playerid, MSGTextdraw[playerid][0], 0.400000, 1.600000);
PlayerTextDrawAlignment(playerid, MSGTextdraw[playerid][0], 2);
PlayerTextDrawColor(playerid, MSGTextdraw[playerid][0], -1);
PlayerTextDrawSetShadow(playerid, MSGTextdraw[playerid][0], 0);
PlayerTextDrawSetOutline(playerid, MSGTextdraw[playerid][0], 0);
PlayerTextDrawBackgroundColor(playerid, MSGTextdraw[playerid][0], 255);
PlayerTextDrawFont(playerid, MSGTextdraw[playerid][0], 1);
PlayerTextDrawSetProportional(playerid, MSGTextdraw[playerid][0], 1);
PlayerTextDrawSetShadow(playerid, MSGTextdraw[playerid][0], 0);
"symbol already defined: PlayerTextDrawLetterSize", if I remove PlayerTextDrawLetterSize it continues down on PlayerTextDrawAlignment. I do not even try to define it, what's going on?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)