їBest way to create textdraw?
#1

I see that I have in my game mode at least 40 global textdraws, but I do not think that the way they are created is the most optimal.

For example, I have this from my registration system...
PHP Code:
new Text:BackgroundTextDraw[MAX_PLAYERS];
new 
Text:ServerNameTextDraw[MAX_PLAYERS];
new 
Text:LoginTextDraw[MAX_PLAYERS];
new 
Text:RegisterTextDraw[MAX_PLAYERS];
new 
Text:CreditsTextDraw[MAX_PLAYERS];
new 
Text:RulesTextDraw[MAX_PLAYERS];
new 
Text:TeamTextDraw[MAX_PLAYERS]; 
And this in OnGameModeInit
PHP Code:
    for(new 0MAX_PLAYERSi++)
    {
        
BackgroundTextDraw[i] = TextDrawCreate(2.000000208.000000"usebox");
        
//(INFO)
        
ServerNameTextDraw[i] = TextDrawCreate(315.00000097.562500"ServerNameRP");
        
//(INFO)
        
LoginTextDraw[i] = TextDrawCreate(308.000000120"Login");
        
//(INFO)
        
RegisterTextDraw[i] = TextDrawCreate(308.000000121.625000"Register");
        
//(INFO)
        
CreditsTextDraw[i] = TextDrawCreate(307.500000140"Credits");
        
//(INFO)
        
RulesTextDraw[i] = TextDrawCreate(309.000000160"Rules");
        
//(INFO)
        
TeamTextDraw[i] = TextDrawCreate(309.000000180"Team");
        
//(INFO)
    

And here are the functions to load and hide the textdraws
PHP Code:
ShowLoginTextDraws(playerid)
{
    
TextDrawShowForPlayer(playeridBackgroundTextDraw[playerid]);
    
TextDrawShowForPlayer(playeridServerNameTextDraw[playerid]);
    
TextDrawShowForPlayer(playeridCreditsTextDraw[playerid]);
    
TextDrawShowForPlayer(playeridRulesTextDraw[playerid]);
    
TextDrawShowForPlayer(playeridTeamTextDraw[playerid]);
    
SelectTextDraw(playerid, -1);
    return 
true;
}
HideLoginTextDraws(playerid)
{
    
TextDrawHideForPlayer(playeridBackgroundTextDraw[playerid]);
    
TextDrawHideForPlayer(playeridServerNameTextDraw[playerid]);
    
TextDrawHideForPlayer(playeridCreditsTextDraw[playerid]);
    
TextDrawHideForPlayer(playeridRulesTextDraw[playerid]);
    
TextDrawHideForPlayer(playeridTeamTextDraw[playerid]);
    
TextDrawHideForPlayer(playeridLoginTextDraw[playerid]);
    
TextDrawHideForPlayer(playeridRegisterTextDraw[playerid]);
    
CancelSelectTextDraw(playerid);
    return 
true;

Straight to the point, the question is whether it is better to create the registration and login textdraws for the MAX_PLAYERS when you start the server, or create these when the player connects. (Thinking about minimizing the slowness of the server), take into account that I have at least 40 textdraws created in the same way .. I have no problem compiling but I see that the server is somewhat slower since it implements these ..
Reply
#2

The loop will create 40 textdraws for max players. You don't need a loop to create textdraws with different name. You could use the loop if you're hiding more textdraws (arrays) under a callback (OnPlayerDeath etc)
Reply
#3

you don't need create per-player textdraws in this situation.
Reply
#4

Lose the array, i don't see the need for global textdraws with player arrays unless you exceed the player tdraw limit.

EDIT: and just so you know, you also don't need an array for player textdraws as they are already per-player.
Reply
#5

I changed this, I do not know if it would be the best way ..
(Sorry if I did not understand you, my language is not English)

Remove MAX_PLAYERS arrays
PHP Code:
new Text:BackgroundTextDraw
Also remove the loop and playerid arrays
PHP Code:
    BackgroundTextDraw TextDrawCreate(2.000000208.000000"usebox");
    
TextDrawLetterSize(BackgroundTextDraw0.000000, -14.170830);
    
TextDrawTextSize(BackgroundTextDraw637.5000000.000000);
    
TextDrawAlignment(BackgroundTextDraw1);
    
TextDrawColor(BackgroundTextDraw0);
    
TextDrawUseBox(BackgroundTextDrawtrue);
    
TextDrawBoxColor(BackgroundTextDraw102);
    
TextDrawSetShadow(BackgroundTextDraw0);
    
TextDrawSetOutline(BackgroundTextDraw0);
    
TextDrawFont(BackgroundTextDraw0); 
So, it is better to define the registration system at a certain amount (since not all users will use it at the same time), so doing a count every time it is shown by adding ++ and when it is hidden by subtracting -?
Reply
#6

So, for example for a text that has a different string for each player, that has created a textdraw per player?
PHP Code:
format(stringsizeof string"Genero: %s"inputtext);
TextDrawSetString(Reg_GenderTextDrawstring); 
Since if 2 players are registering at the same time, they are likely to use the same textdraw at the same time and change information ... (eg 1 male and one female)

Excuse so many questions, I am learning about this and I do not get any well-explained guide.
Reply
#7

Quote:
Originally Posted by OdgFox
View Post
So, for example for a text that has a different string for each player, that has created a textdraw per player?
PHP Code:
format(stringsizeof string"Genero: %s"inputtext);
TextDrawSetString(Reg_GenderTextDrawstring); 
Since if 2 players are registering at the same time, they are likely to use the same textdraw at the same time and change information ... (eg 1 male and one female)

Excuse so many questions, I am learning about this and I do not get any well-explained guide.
No problem and yes, any text draw that shows different info for players at the same time you need to use playertextdraw not global ones with an array AND don't put an array for playertextdraws because they are already per player.
Reply
#8

Quote:
Originally Posted by RogueDrifter
View Post
No problem and yes, any text draw that shows different info for players at the same time you need to use playertextdraw not global ones with an array AND don't put an array for playertextdraws because they are already per player.
Have you tried using them without array before for per player TDs, Mister Arrogance?
Reply
#9

Quote:
Originally Posted by Logic_
View Post
Have you tried using them without array before for per player TDs, Mister Arrogance?
Matter of a fact, I did, i totally think you did the right thing by leaving samp, if you create the player text draw and don't destroy it then you won't need an array (keeping in mind that player textdraws are automatically destroyed upon disconnection).
Reply
#10

I have adjusted all the textdraws of my gamemode .. those that use different strings for each player I have changed them to CreatePlayerTextdraw and put on OnPlayerConnect for now testing with 2 people goes well .. let's see the time to restart the server with about 30 active users: S Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)