їBest way to create textdraw? -
OdgFox - 17.02.2018
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 i = 0; i < MAX_PLAYERS; i++)
{
BackgroundTextDraw[i] = TextDrawCreate(2.000000, 208.000000, "usebox");
//(INFO)
ServerNameTextDraw[i] = TextDrawCreate(315.000000, 97.562500, "ServerNameRP");
//(INFO)
LoginTextDraw[i] = TextDrawCreate(308.000000, 120, "Login");
//(INFO)
RegisterTextDraw[i] = TextDrawCreate(308.000000, 121.625000, "Register");
//(INFO)
CreditsTextDraw[i] = TextDrawCreate(307.500000, 140, "Credits");
//(INFO)
RulesTextDraw[i] = TextDrawCreate(309.000000, 160, "Rules");
//(INFO)
TeamTextDraw[i] = TextDrawCreate(309.000000, 180, "Team");
//(INFO)
}
And here are the functions to load and hide the textdraws
PHP Code:
ShowLoginTextDraws(playerid)
{
TextDrawShowForPlayer(playerid, BackgroundTextDraw[playerid]);
TextDrawShowForPlayer(playerid, ServerNameTextDraw[playerid]);
TextDrawShowForPlayer(playerid, CreditsTextDraw[playerid]);
TextDrawShowForPlayer(playerid, RulesTextDraw[playerid]);
TextDrawShowForPlayer(playerid, TeamTextDraw[playerid]);
SelectTextDraw(playerid, -1);
return true;
}
HideLoginTextDraws(playerid)
{
TextDrawHideForPlayer(playerid, BackgroundTextDraw[playerid]);
TextDrawHideForPlayer(playerid, ServerNameTextDraw[playerid]);
TextDrawHideForPlayer(playerid, CreditsTextDraw[playerid]);
TextDrawHideForPlayer(playerid, RulesTextDraw[playerid]);
TextDrawHideForPlayer(playerid, TeamTextDraw[playerid]);
TextDrawHideForPlayer(playerid, LoginTextDraw[playerid]);
TextDrawHideForPlayer(playerid, RegisterTextDraw[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 ..
Re: їBest way to create textdraw? -
Fratello - 17.02.2018
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)
Re: їBest way to create textdraw? -
JustNothing - 17.02.2018
you don't need create per-player textdraws in this situation.
Re: їBest way to create textdraw? -
RogueDrifter - 17.02.2018
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.
Re: їBest way to create textdraw? -
OdgFox - 18.02.2018
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.000000, 208.000000, "usebox");
TextDrawLetterSize(BackgroundTextDraw, 0.000000, -14.170830);
TextDrawTextSize(BackgroundTextDraw, 637.500000, 0.000000);
TextDrawAlignment(BackgroundTextDraw, 1);
TextDrawColor(BackgroundTextDraw, 0);
TextDrawUseBox(BackgroundTextDraw, true);
TextDrawBoxColor(BackgroundTextDraw, 102);
TextDrawSetShadow(BackgroundTextDraw, 0);
TextDrawSetOutline(BackgroundTextDraw, 0);
TextDrawFont(BackgroundTextDraw, 0);
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 -?
Re: їBest way to create textdraw? -
OdgFox - 18.02.2018
So, for example for a text that has a different string for each player, that has created a textdraw per player?
PHP Code:
format(string, sizeof string, "Genero: %s", inputtext);
TextDrawSetString(Reg_GenderTextDraw, string);
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.
Re: їBest way to create textdraw? -
RogueDrifter - 18.02.2018
Quote:
Originally Posted by OdgFox
So, for example for a text that has a different string for each player, that has created a textdraw per player?
PHP Code:
format(string, sizeof string, "Genero: %s", inputtext);
TextDrawSetString(Reg_GenderTextDraw, string);
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.
Re: їBest way to create textdraw? -
Logic_ - 18.02.2018
Quote:
Originally Posted by RogueDrifter
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?
Re: їBest way to create textdraw? -
RogueDrifter - 18.02.2018
Quote:
Originally Posted by Logic_
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).
Re: їBest way to create textdraw? -
OdgFox - 18.02.2018
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!