Tutoriel sur les TextDraw
Déjà, pour ceux qui ne le savent pas... qu'est ce que c'est ?
Un Textdraw, c'est un texte affiché sur son écran quand on joue à GTA SA-MP, le plus souvent en gros.
Voici un exemple de textdraw :
(http://metra-concept.fr/imagetuto/extext.PNG)
Maintenant que vous savez ce que c'est, passons au scripting de la bette :
Définir une variable (en haut du FS ou GM) :
new Text:loading; // vous devez changer que le mot "loading" par le nom d'une variable de votre choix!
Choisir à quel moment l'afficher (dans mon exemple je l'affiche quand un joueur se connecte au serveur) :
public OnPlayerConnect(playerid)
{
loading=TextDrawCreate(350.0, 400.0,"Chargement en cours"); // choix de la position et du texte
TextDrawUseBox(loading, 0); // n'ajoute pas de boxe derrière le texte
TextDrawFont(loading, 2); // choix d'une police d'écriture
TextDrawSetShadow(loading,0); // Affiche aucune ombre au texte
TextDrawSetOutline(loading,1); // un petit contour noir du texte
TextDrawColor(loading,0xFFFFFFFF); // couleur du textdraw
TextDrawShowForPlayer(playerid, loading); // montrer le textdraw à UN joueur
return 1;
}
Explication détaillée du script ci-dessous :
* loading=TextDrawCreate(350.0, 400.0,"Chargement en cours");
- loading : On défini à la variable qu'elle vaut la création d'un TextDraw
- TextDrawCreate : Fonction pour créer un TextDraw
- 350.0, 400.0 : Position X et Y du TextDraw sur l'écran
- Chargement en cours : Texte que va afficher le Textdraw
* TextDrawUseBox(loading, 0);
- TextDrawUseBox : Fonction pour choisir si on veut ajouter une box au TextDraw
- 0 : 0 = sans et 1 = avec
* TextDrawFont(loading, 2);
- TextDrawFont : Fonction pour choisir le type d'écriture
- 2 : ID de l'écriture, les voici :
(http://img115.imageshack.us/img115/5092/clipboard01vu9.png)
* TextDrawSetShadow(loading, 0);
- TextDrawSetShadow : Fonction pour afficher une ombre
- 0 : Choix de l'épaisseur de l'ombre
* TextDrawSetOutline(loading, 1);
- TextDrawSetOutline : Fonction pour afficher un contour autour des lettres
- 1 : Choix de l'épaisseur des contours
* TextDrawColor(loading, 0xFFFFFFFF);
- TextDrawColor : Fonction pour choisir la couleur du texte
- 0xFFFFFFFF : Choix de la couleur
* TextDrawShowForPlayer(playerid, loading);
- TextDrawShowForPlayer : Fonction pour afficher le TextDraw à un joueur. Vous pouvez aussi utiliser : TextDrawShowForAll(loading); pour afficher le TextDraw à tout le monde
Et voici d'autres fonctions pour les textdraws :
* TextDrawTextSize (loading, 200.0, 200.0) ;
- TextDrawTextSize : Fonction pour définir la taille du texte du TextDraw
- 200.0, 200.0 : Tailles X et Y du Texte
* TextDrawBoxColor(loading, 0x00000066);
- TextDrawBoxColor : Fonction pour définir la couleur d'une box (si vous en avez mis une)
- 0x00000066 : Couleur de la Box
* TextDrawBackgroundColor(loading, 0x000000FF) ;
- TextDrawBackgroundColor : Fonction qui ajoute un fond au TextDraw[/color]
- 0x000000FF : Couleur du fond
Et pour finir si vous voulez enlever le TextDraw à un certain moment il faut faire comme ceci (je vais reprendre l'exemple de ci-dessus et choisir d'enlever le textdraw quand un joueur arrive à la selection de personnage (la callback : OnPlayerRequestClass) :
public OnPlayerRequestClass(playerid, classid)
{
TextDrawHideForPlayer(playerid,loading);
return 1;
}
Explication du script ci-dessous :
* TextDrawHideForPlayer(playerid,loading); : fonction qui sert à effacer le TextDraw sur l'écran d'un joueur, si vosu avez choisir de montrer un TextDraw à tout les joueurs vous pouvez aussi utiliser : TextDrawHideForAll(loading);, cela servira à effacer le TextDraw pour tout le monde !
Vous voici arrivez à la fin du tutoriel, en espérant qu'il vous aura apporté des connaissances supplémentaires ;).
Bon scripting !
Metrakit, du groupe E-sky.fr (http://e-sky.fr).