26.09.2015, 15:03
(
Последний раз редактировалось Ritzy2K; 26.09.2015 в 17:20.
)
Global Textdraws!
Introduction
Hello, today i explain everything about textdraws . This tutorial is specially focused for newbies, it may help some average scripters too. I'd try to explain everything i know. All the questions, any bugs (in the tutorial code), Constructive criticism are welcomed in the comments below. Lets begin !
What is a textdraw?
First of all, a textdraw is Different from Gametext, never get confused within these two. a textdraw can appear for indefined time and is only limited to your imagination. Textdraws can be made anywhere on the screen at any size and can use different kind of fonts.
There are basically 2 types of textdraws -
1. Global Textdraws
2. Player Textdraws
1. Global textdraws are textdraws which can be shown to all players at a single time. They can be used for basically textdraws which wont change player to player. A global textdraw is easier to create in my opinion than player textdraws. Global Textdraws can be used for example to display Welcome Message for the server. or your website url or any other textdraws which remains constant.
2. Player Textdraws are different than global textdraws. They are created for each player, they may or may not be same. Player textdraws can be used to show stuffs like their stats, which wont be same for each player of course. or maybe for the speedometer for the car. which displays fuel health etc.I'd cover player textdraw in next tutorial. Sorry for that
How to create a textdraw?
Textdraws seems hard to create right? But they're relatively easy.
sooo this is how we do it!
We need to tell our script about the textdraw we are going to create (Dont think im drunk. m trying to explain it to newbs). Like. we need to declare a textdraw Everytime we create a new textdraw at the top of the script so its useable anywhere in the script below since we already told the script above about it
For example -
Код:
new Text:hi; // we just told the script that we are going to create a textdraw called hi. now you can use it throught the script. public OnGameModeInit() { hi = TextDrawCreate(123.456, 789.1011, "Hi bro"); return 1; }
Time to explain the native we used
TextDrawCreate(float,float:y,"text");
TextDrawCreate - it is the function which creates the textdaw, note - all the textdraw that we create needs to come under OnGameModeInit. since our textdraw should be created when the gamemode begins (intializes). this function has 3 arguements/ parameters. which are -
float - it is the x coordinate of the textdraw. (cartesian components, hope you know that.). i mean, the x coordinate of the textdraw that we created.
float:y - it is the y coordinate of the textdraw we created.
we used the float, not int because, our coordinates may have decimal.
Text- the text needs to come under double quotes ALWAYS. the text can be anything. whatever we like, keep it under double quotes though.
Okay, we created the textdraw but its not visible!!
well, after creating the textdraw we need to manually show it to the player using another samp function.
Код:
public OnPlayerConnect(playerid) { TextDrawShowForPlayer(playerid, hi); return 1; }
TextDrawShowForPlayer is the native which is used to show textdraw to the player, it has 2 parameters / arguements which are -
playerid - its the playerid that just connected to the server. and the playerid who'd see the textdraw.
textdrawid - its the id of the textdraw. i.e the textdraw we told the script above in the top remember?
Its not important that we show the textdraw when player connects, we can show it anywhere according to the scripters. it be OnPlayerSpawn OnPlayerDeath etc.
Similarly we can hide the textdraw for the specific player like we showed. (dope right?)
the native used for it is-
TextDrawHideForPlayer(playerid, textdrawid); i hope i dont really need to explain both the parameters again.
Showing our textdraws to everyone
we can show the textdraws for all the players and hide it for the players using -
TextDrawShowForAll(textdrawid); - it doesnt have the playerid parameter because we are showing it to all the players so we dont need an specific player id. textdrawid is the id of the textdraw that we will show to all players.
TextDrawHideForAll(textdrawid); - works the same as TextDrawShowForAll. just hides it rather than showing it.
I dont really like the texdraw i created, what to do?
Textdraws can be destroyed, using an default samp native which is -
TextDrawDestroy(textdrawid); - it has only one params. which is textdrawid, it is important to specify the textdrawid because our script wants to know what textdraw we exactly need to destroy.
How to set textdraw colors.
Textdraw color can be set by another native function called TextDrawColor
TextDrawColor(textdrawid, color); - this function has 2 parameters.
textdrawid - the id of the texdraw whom we are willing to change color.
color - the color that we want to apply
GAMETEXT COLORS CAN BE USED INTO TEXTDRAWS TO REDUCE HASSLE! THIS PART WILL BE COVERED IN MISCELLANEOUS BELOW
How to change the style of the text of the textdraw.
the style in which in the text is written, i.e its font can be changed with TextDrawFont, its an existing samp native.
TextDrawFont(textdrawid, fontid);
textdrawid - if you are reading the tutorial with concentration, this doesnt need an explanation.
fontid - there are 4 types of font, all of which have 4 different ids, - 0, 1, 2, 3. please check samp.wiki for their appearance, sorry for any issue.
i'd consider the textdraw we created above, which was 'hi'. if we want to change it to orignal gta sa style font. we'd do.
Код:
TextDrawFont(hi, 0);
Miscellaneous
Coding textdraws manually was the trend of the past, nowadays. textdraw creation tools are used. One of my fav textdraw editor is iPLEOMAX textdraw editor, its really simple and magical.
I strongly recommend using any textdraw editor. It makes textdraw much much easier.
All the gametext color available for Textdraws
Код:
~n~ New line ~r~ Red ~g~ Green ~b~ Blue ~w~ White ~y~ Yellow ~p~ Purple ~l~ Black (lower case L) ~h~ Turn text color lighter (used too much will make your text white, doesn't work on black)
it took me around 1 hour to write the tutorial, hope its worth it
Thanks a lot for reading this.
Credits.
Internet - for letting me write.
[ND]xXZeusXx - for writing the tutorial.
Kalcor - for writing the functions :P
samp.wiki - for helping me to write
you - to read what i wrote.
Good bye
[ND]xXZeusXx