Textdraw sйlectionnable. -
Scol-Ben - 19.09.2015
[CENTER]Bonjour а tous et а toutes !
Voici un tutoriel permettant la crйation d'un textdraw sйlectionnable permettant l'affichage de la date.
[COLOR="Red"]Pour avoir un rйsultat parfait, veuillez bien suivre le tutoriel. Si vous avez encore un problиme au rйsultat final contacter moi en privй.
Sachez qu'apprendre sans COPIER/COLLER n'est pas une chose aisйe, mais essayer tout de mкme. [/COLOR][/CENTER]
Йtape 1 :
Pour commencer il va falloir dйclarer plusieurs variables :
Code:
new PlayerText:Heure[MAX_PLAYERS]; [COLOR="Red"]// Dйclaration de la variable de type PlayerText.[/COLOR]
new jour, mois, ans; [COLOR="red"]// Dйclaration des 3 variables pour afficher la date[/COLOR].
Йtape 2 :
Une fois les variables dйclarйes, il faut afficher notre textdraw statique а l'йcran.
Placer donc ce code dans la callback OnPlayerConnect :
Code:
Heure[playerid] = CreatePlayerTextDraw(playerid, 300.0000, 300.5000, "Tutoriel par Scozor (Scol-Ben)"); [COLOR="Red"]// Assigne la crйation du textdraw а la variable.[/COLOR]
PlayerTextDrawAlignment(playerid, Heure[playerid], 0); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawFont(playerid, Heure[playerid], 2); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawLetterSize(playerid, Heure[playerid], 0.2999,1.4000); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawColor(playerid, Heure[playerid], -1); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawSetOutline(playerid, Heure[playerid], 0); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawSetProportional(playerid, Heure[playerid], 1); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawSetShadow(playerid, Heure[playerid], 1); [COLOR="red"]// Gиre la mise en forme du textdraw.[/COLOR]
PlayerTextDrawSetSelectable(playerid, Heure[playerid], true); [COLOR="red"]// Permets de rendre le textdraw sйlectionnable.[/COLOR]
PlayerTextDrawShow(playerid, PlayerText:Heure[playerid]); [COLOR="red"]// Affiche le textdraw а l'йcran du joueur.[/COLOR]
N'oubliez pas de dйtruire le textdraw а la dйconnexion du joueur dans OnPlayerDisconnect :
Code:
PlayerTextDrawDestroy(playerid, Heure[playerid]); [COLOR="Red"]// Dйtruit le textdraw heure.[/COLOR]
Йtape 3 :
Voici la derniиre йtape.
А ce stade, nous avons nos variables dйclarйes ainsi qu'un textdraw statique а l'йcran. Il nous reste plus qu'а rendre l’aperзu du curseur de notre souris а l'йcran et de cliquer sur le textdraw.
Sans plus attendre dans OnPlayerKeyStateChange :
Code:
if(newkeys == KEY_YES) [COLOR="Red"]// Lorsque le joueur presse la touche Y de son clavier.[/COLOR]
{
SendClientMessage(playerid, 0xFFCC99FF, "Vous pouvez dйsormer cliquer sur un texte а l'йcran pour l'utiliser.");
SelectTextDraw(playerid, 0xD70000FF);
return 1;
}
Et enfin la partie la plus importante du tutoriel :
Code:
public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
{
if(_:playertextid != 65535) [COLOR="Red"]// La condition vйrifie si l'id du textdraw est diffйrent de 65535.[/COLOR]
{
if(playertextid == Heure[playerid]) [COLOR="red"]// Lorsque le joueur sйlectionne le textdraw heure.[/COLOR]
{
new string[64]; [COLOR="red"]// Variable pour afficher le texte.[/COLOR]
new mtext[20]; [COLOR="red"]// Dйclaration d'une nouvelle variable permettant d'afficher un texte selon le mois.[/COLOR]
getdate(ans, mois, jour); [COLOR="red"]// On stock la date de l'ordinateur dans nos 3 variables.[/COLOR]
if(mois == 1) { mtext = "Janvier"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 2) { mtext = "Fevrier"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 3) { mtext = "Mars"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 4) { mtext = "Avril"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 5) { mtext = "Mai"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 6) { mtext = "Juin"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 7) { mtext = "Juillet"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 8) { mtext = "Aout"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 9) { mtext = "Septembre"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 10) { mtext = "Octobre"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 11) { mtext = "Novembre"; } [COLOR="red"]// Condition et attribution.[/COLOR]
else if(mois == 12) { mtext = "Decembre"; } [COLOR="red"]// Condition et attribution.[/COLOR]
format(string, sizeof(string), "~w~%02d %s %d", jour, mtext, ans);
GameTextForPlayer(playerid, string, 5000, 1); [COLOR="red"]// Texte а l'йcran pendant 5 secondes.[/COLOR]
}
CancelSelectTextDraw(playerid); [COLOR="red"]// Annule la sйlection du textdraw avec la souris.[/COLOR]
}
return 1;
}
Le tutoriel est terminй, maintenant vous avez tout sous la main pour crйer plein de textdraw cliquable.
Les explications sous toutes expliquйes en commentaire dans le CODE SOURCE.
Re : Textdraw sйlectionnable. -
StreetRP - 19.09.2015
Bon tuto !
Re : Textdraw sйlectionnable. -
Sus-Pets - 19.09.2015
Merci copain !
Re : Textdraw sйlectionnable. -
Scol-Ben - 19.09.2015
Merci, j'en ai pas trouvй en franзais je me suis dit pourquoi pas :)
Re: Textdraw sйlectionnable. -
Jabern - 19.09.2015
Rajoutons a ce super tuto le post de dutheil
https://sampforum.blast.hk/showthread.php?pid=3257984#pid3257984
Dutheil;3257984 Wrote:Tiens, tu devrais comprendre :
![[Image: 813371qsdsqdqsd.jpg]](http://img15.hostingpics.net/pics/813371qsdsqdqsd.jpg)
Code:
new textdraw;
textdraw = TextDrawCreate([B][COLOR="Red"]100.0[/COLOR][/B], [B][COLOR="DarkRed"]115.0[/COLOR][/B], "Textdraw");
TextDrawTextSize(textdraw, [B][COLOR="DarkOrange"]210.0[/COLOR][/B], [B][COLOR="SeaGreen"]15.0[/COLOR][/B]);
Donc ta zone de sйlection se dйfinie comme зa, j'ai mis 2 semaines pour comprendre en touchant а tout :'))))
Dans le cas oщ tu verrais que ta selection est trop а droite tu diminues la valeur de [COLOR="Red"]x[/COLOR] а [COLOR="RoyalBlue"]TextDrawTextSize[/COLOR]
Code:
[B][COLOR="RoyalBlue"]TextDrawTextSize[/COLOR][/B](textdraw, [B][COLOR="Red"]x[/COLOR][/B], y);
Dans le cas oщ tu verrais que ta sйlection est trop basse, tu diminues la valeur de [COLOR="Red"]y[/COLOR] а [COLOR="RoyalBlue"]TextDrawTextSize[/COLOR]
Code:
[B][COLOR="RoyalBlue"]TextDrawTextSize[/COLOR][/B](textdraw, x, [B][COLOR="Red"]y[/COLOR][/B]);
Re : Textdraw sйlectionnable. -
Scol-Ben - 19.09.2015
Merci, maintenant vous savez cordonner vos textdraws ! xD
Ah ne faite pas attention, celui du tutoriel est placй n'importe comment car je suis fainйant.
Re : Textdraw sйlectionnable. -
Chipardeur - 19.09.2015
Juste un petit truc, quand tu peux le faire: utiliser switch au lieu de faire 11 else if, зa fait beaucoup plus propre.
Et aussi, tu n'es pas obligй de mettre les accolades dans ton code:
PHP Code:
if(mois == 1) { mtext = ".."; }
revient exactement а faire:
PHP Code:
if(mois == 1) mtext = "..";
En tout cas, bon tuto ;)
Re : Textdraw sйlectionnable. -
Scol-Ben - 19.09.2015
Merci du conseil, je mettrais а jour le tutoriel plus tard.