[Tutorial] Textdraws Clicбveis
#1

Textdraws Clicбveis


Neste tutorial, vocк irб aprender a fazer textdraws clicбveis com as mais diversas aplicaзхes, sendo somente limitado pela sua imaginaзгo!

Para realizar o serviзo, vocк necessitarб de algumas ferramentas. Elas sгo opcionais, porйm fica bem mais fбcil de fazer Textdraws com as ferramentas.

https://sampforum.blast.hk/showthread.php?tid=376758 - iPLEOMAX's Textdraw Editor
https://sampforum.blast.hk/showthread.php?tid=291722 - Lorenc's Sprite Browser
Criando as textdraws


No exemplo deste tutorial, eu irei fazer um pequeno sistema de registro por textdraws clicбveis, que vocк pode conferir (e testб-lo em aзгo) no seguinte servidor: 208.115.224.233:7777. Caso vocк nгo sabia como desenhar textdraws no iPLEOMAX's Textdraw Editor, entre no link providenciado acima e veja o vнdeo com o tutorial.


O textdraw deste tutorial (apуs finalizado) terб o seguinte aspecto:


As setas e o нcone de balгo sгo SPRITES, imagens de textura do GTA original. O Sprite Browser permite vocк procurar algumas (se nгo todas) sprites disponнveis para uso.



Para comeзar, devemos definir o cуdigo das Textdraws e criб-las.
pawn Код:
//Preferencialmente no comeзo de seu GM, iremos definir as variбveis que guardarгo as textdraws...
new Text:RegisterOption[7];
new Text:RegisterClick[MAX_PLAYERS];
new Text:RegisterText[MAX_PLAYERS][5];
new Text:RegisterLeft[MAX_PLAYERS][5];
new Text:RegisterRight[MAX_PLAYERS][5];
Agora que suas variбveis foram inicializadas, vamos criar as textdraws em OnGameModeInit...
pawn Код:
RegisterOption[0] = TextDrawCreate(608.000000, 173.648147, "usebox"); // Textdraw da caixa preta de fundo;
    TextDrawLetterSize(RegisterOption[0], 0.000000, 24.295679);
    TextDrawTextSize(RegisterOption[0], 443.000000, 0.000000);
    TextDrawAlignment(RegisterOption[0], 1);
    TextDrawColor(RegisterOption[0], 0);
    TextDrawUseBox(RegisterOption[0], true);
    TextDrawBoxColor(RegisterOption[0], 102);
    TextDrawSetShadow(RegisterOption[0], 0);
    TextDrawSetOutline(RegisterOption[0], 0);
    TextDrawFont(RegisterOption[0], 0);

    RegisterOption[1] = TextDrawCreate(434.666687, 156.385192, "Registro"); //Textdraw Azul escrita Registro...
    TextDrawLetterSize(RegisterOption[1], 0.736666, 2.325926);
    TextDrawAlignment(RegisterOption[1], 1);
    TextDrawColor(RegisterOption[1], 257552383);
    TextDrawSetShadow(RegisterOption[1], 0);
    TextDrawSetOutline(RegisterOption[1], 1);
    TextDrawBackgroundColor(RegisterOption[1], 51);
    TextDrawFont(RegisterOption[1], 0);
    TextDrawSetProportional(RegisterOption[1], 1);

    RegisterOption[2] = TextDrawCreate(452.666595, 194.548156, "Idade:"); //Resto das textdraws...
    TextDrawLetterSize(RegisterOption[2], 0.301665, 1.255702);
    TextDrawAlignment(RegisterOption[2], 1);
    TextDrawColor(RegisterOption[2], -1);
    TextDrawSetShadow(RegisterOption[2], 0);
    TextDrawSetOutline(RegisterOption[2], -1);
    TextDrawBackgroundColor(RegisterOption[2], 255);
    TextDrawFont(RegisterOption[2], 2);
    TextDrawSetProportional(RegisterOption[2], 1);

    RegisterOption[3] = TextDrawCreate(452.666595, 217.777755, "Altura:");
    TextDrawLetterSize(RegisterOption[3], 0.300998, 1.254999);
    TextDrawAlignment(RegisterOption[3], 1);
    TextDrawColor(RegisterOption[3], -1);
    TextDrawSetShadow(RegisterOption[3], 0);
    TextDrawSetOutline(RegisterOption[3], -1);
    TextDrawBackgroundColor(RegisterOption[3], 255);
    TextDrawFont(RegisterOption[3], 2);
    TextDrawSetProportional(RegisterOption[3], 1);

    RegisterOption[4] = TextDrawCreate(452.666595, 241.007354, "Peso:");
    TextDrawLetterSize(RegisterOption[4], 0.300998, 1.254999);
    TextDrawAlignment(RegisterOption[4], 1);
    TextDrawColor(RegisterOption[4], -1);
    TextDrawSetShadow(RegisterOption[4], 0);
    TextDrawSetOutline(RegisterOption[4], 1);
    TextDrawBackgroundColor(RegisterOption[4], 255);
    TextDrawFont(RegisterOption[4], 2);
    TextDrawSetProportional(RegisterOption[4], 1);

    RegisterOption[5] = TextDrawCreate(452.666595, 264.236953, "Skin:");
    TextDrawLetterSize(RegisterOption[5], 0.300998, 1.254999);
    TextDrawAlignment(RegisterOption[5], 1);
    TextDrawColor(RegisterOption[5], -1);
    TextDrawSetShadow(RegisterOption[5], 0);
    TextDrawSetOutline(RegisterOption[5], 1);
    TextDrawBackgroundColor(RegisterOption[5], 255);
    TextDrawFont(RegisterOption[5], 2);
    TextDrawSetProportional(RegisterOption[5], 1);

    RegisterOption[6] = TextDrawCreate(452.666595, 287.466552, "Spawn:");
    TextDrawLetterSize(RegisterOption[6], 0.300998, 1.254999);
    TextDrawAlignment(RegisterOption[6], 1);
    TextDrawColor(RegisterOption[6], -1);
    TextDrawSetShadow(RegisterOption[6], 0);
    TextDrawSetOutline(RegisterOption[6], 1);
    TextDrawBackgroundColor(RegisterOption[6], 255);
    TextDrawFont(RegisterOption[6], 2);
    TextDrawSetProportional(RegisterOption[6], 1);
Essas sгo as textdraws que NГO sгo clicбveis. As textdraws acima sгo globais (nгo sгo criadas uma por jogador) pois sгo textos imutбveis e bбsicos. Agora, iremos proceder a colocar as textdraws por player, que sгo os textos que o jogador clicarб e/ou modificarб.

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        RegisterClick[i] = TextDrawCreate(509.137298, 342.131469, "ld_chat:thumbup"); //Textura do balгozinho.
        TextDrawLetterSize(RegisterClick[i], 0.000000, 0.000000);
        TextDrawTextSize(RegisterClick[i], 29.019626, 31.487031);
        TextDrawAlignment(RegisterClick[i], 1);
        TextDrawColor(RegisterClick[i], -1);
        TextDrawSetShadow(RegisterClick[i], 0);
        TextDrawSetOutline(RegisterClick[i], 0);
        TextDrawFont(RegisterClick[i], 4);
        TextDrawSetSelectable(RegisterClick[i], true);
       
        RegisterText[i][0] = TextDrawCreate(556.331970, 194.548156, "18");
        TextDrawLetterSize(RegisterText[i][0], 0.300998, 1.254999);
        TextDrawAlignment(RegisterText[i][0], 2);
        TextDrawColor(RegisterText[i][0], 257552383);
        TextDrawSetShadow(RegisterText[i][0], 0);
        TextDrawSetOutline(RegisterText[i][0], 1);
        TextDrawBackgroundColor(RegisterText[i][0], 255);
        TextDrawFont(RegisterText[i][0], 2);
        TextDrawSetProportional(RegisterText[i][0], 1);

        RegisterLeft[i][0] = TextDrawCreate(509.000274, 192.888931, "ld_beat:left"); //Textura da seta esquerda.
        TextDrawLetterSize(RegisterLeft[i][0], 0.002000, 0.037333);
        TextDrawTextSize(RegisterLeft[i][0], 17.006999, 17.007396);
        TextDrawAlignment(RegisterLeft[i][0], 1);
        TextDrawColor(RegisterLeft[i][0], -1);
        TextDrawSetShadow(RegisterLeft[i][0], 0);
        TextDrawSetOutline(RegisterLeft[i][0], 0);
        TextDrawFont(RegisterLeft[i][0], 4);
        TextDrawSetSelectable(RegisterLeft[i][0], true);

        RegisterRight[i][0] = TextDrawCreate(586.666137, 192.888931, "ld_beat:right"); //Textura da seta direita.
        TextDrawLetterSize(RegisterRight[i][0], 0.000000, 0.000000);
        TextDrawTextSize(RegisterRight[i][0], 17.006999, 18.666671);
        TextDrawAlignment(RegisterRight[i][0], 1);
        TextDrawColor(RegisterRight[i][0], -1);
        TextDrawSetShadow(RegisterRight[i][0], 0);
        TextDrawSetOutline(RegisterRight[i][0], 0);
        TextDrawFont(RegisterRight[i][0], 4);
        TextDrawSetSelectable(RegisterRight[i][0], true);
       
        RegisterText[i][1] = TextDrawCreate(556.331970, 217.777755, "130cm");
        TextDrawLetterSize(RegisterText[i][1], 0.300998, 1.254999);
        TextDrawAlignment(RegisterText[i][1], 2);
        TextDrawColor(RegisterText[i][1], 257552383);
        TextDrawSetShadow(RegisterText[i][1], 0);
        TextDrawSetOutline(RegisterText[i][1], 1);
        TextDrawBackgroundColor(RegisterText[i][1], 255);
        TextDrawFont(RegisterText[i][1], 2);
        TextDrawSetProportional(RegisterText[i][1], 1);

        RegisterLeft[i][1] = TextDrawCreate(509.000274, 216.11853, "ld_beat:left");
        TextDrawLetterSize(RegisterLeft[i][1], 0.002000, 0.037333);
        TextDrawTextSize(RegisterLeft[i][1], 17.006999, 17.007396);
        TextDrawAlignment(RegisterLeft[i][1], 1);
        TextDrawColor(RegisterLeft[i][1], -1);
        TextDrawSetShadow(RegisterLeft[i][1], 0);
        TextDrawSetOutline(RegisterLeft[i][1], 0);
        TextDrawFont(RegisterLeft[i][1], 4);
        TextDrawSetSelectable(RegisterLeft[i][1], true);

        RegisterRight[i][1] = TextDrawCreate(586.666137, 216.11853, "ld_beat:right");
        TextDrawLetterSize(RegisterRight[i][1], 0.000000, 0.000000);
        TextDrawTextSize(RegisterRight[i][1], 17.006999, 18.666671);
        TextDrawAlignment(RegisterRight[i][1], 1);
        TextDrawColor(RegisterRight[i][1], -1);
        TextDrawSetShadow(RegisterRight[i][1], 0);
        TextDrawSetOutline(RegisterRight[i][1], 0);
        TextDrawFont(RegisterRight[i][1], 4);
        TextDrawSetSelectable(RegisterRight[i][1], true);  
       
        RegisterText[i][2] = TextDrawCreate(556.331970, 241.007354, "45kg");
        TextDrawLetterSize(RegisterText[i][2], 0.300998, 1.254999);
        TextDrawAlignment(RegisterText[i][2], 2);
        TextDrawColor(RegisterText[i][2], 257552383);
        TextDrawSetShadow(RegisterText[i][2], 0);
        TextDrawSetOutline(RegisterText[i][2], 1);
        TextDrawBackgroundColor(RegisterText[i][2], 255);
        TextDrawFont(RegisterText[i][2], 2);
        TextDrawSetProportional(RegisterText[i][2], 1);

        RegisterLeft[i][2] = TextDrawCreate(509.000274, 239.348129, "ld_beat:left");
        TextDrawLetterSize(RegisterLeft[i][2], 0.002000, 0.037333);
        TextDrawTextSize(RegisterLeft[i][2], 17.006999, 17.007396);
        TextDrawAlignment(RegisterLeft[i][2], 1);
        TextDrawColor(RegisterLeft[i][2], -1);
        TextDrawSetShadow(RegisterLeft[i][2], 0);
        TextDrawSetOutline(RegisterLeft[i][2], 0);
        TextDrawFont(RegisterLeft[i][2], 4);
        TextDrawSetSelectable(RegisterLeft[i][2], true);

        RegisterRight[i][2] = TextDrawCreate(586.666137, 239.348129, "ld_beat:right");
        TextDrawLetterSize(RegisterRight[i][2], 0.000000, 0.000000);
        TextDrawTextSize(RegisterRight[i][2], 17.006999, 18.666671);
        TextDrawAlignment(RegisterRight[i][2], 1);
        TextDrawColor(RegisterRight[i][2], -1);
        TextDrawSetShadow(RegisterRight[i][2], 0);
        TextDrawSetOutline(RegisterRight[i][2], 0);
        TextDrawFont(RegisterRight[i][2], 4);
        TextDrawSetSelectable(RegisterRight[i][2], true);  
       
        RegisterText[i][3] = TextDrawCreate(556.331970, 264.236953, "1");
        TextDrawLetterSize(RegisterText[i][3], 0.300998, 1.254999);
        TextDrawAlignment(RegisterText[i][3], 2);
        TextDrawColor(RegisterText[i][3], 257552383);
        TextDrawSetShadow(RegisterText[i][3], 0);
        TextDrawSetOutline(RegisterText[i][3], 1);
        TextDrawBackgroundColor(RegisterText[i][3], 255);
        TextDrawFont(RegisterText[i][3], 2);
        TextDrawSetProportional(RegisterText[i][3], 1);

        RegisterLeft[i][3] = TextDrawCreate(509.000274, 262.577728, "ld_beat:left");
        TextDrawLetterSize(RegisterLeft[i][3], 0.002000, 0.037333);
        TextDrawTextSize(RegisterLeft[i][3], 17.006999, 17.007396);
        TextDrawAlignment(RegisterLeft[i][3], 1);
        TextDrawColor(RegisterLeft[i][3], -1);
        TextDrawSetShadow(RegisterLeft[i][3], 0);
        TextDrawSetOutline(RegisterLeft[i][3], 0);
        TextDrawFont(RegisterLeft[i][3], 4);
        TextDrawSetSelectable(RegisterLeft[i][3], true);

        RegisterRight[i][3] = TextDrawCreate(586.666137, 262.577728, "ld_beat:right");
        TextDrawLetterSize(RegisterRight[i][3], 0.000000, 0.000000);
        TextDrawTextSize(RegisterRight[i][3], 17.006999, 18.666671);
        TextDrawAlignment(RegisterRight[i][3], 1);
        TextDrawColor(RegisterRight[i][3], -1);
        TextDrawSetShadow(RegisterRight[i][3], 0);
        TextDrawSetOutline(RegisterRight[i][3], 0);
        TextDrawFont(RegisterRight[i][3], 4);
        TextDrawSetSelectable(RegisterRight[i][3], true);  

        RegisterText[i][4] = TextDrawCreate(556.331970, 287.466552, "Posto");
        TextDrawLetterSize(RegisterText[i][4], 0.300998, 1.254999);
        TextDrawAlignment(RegisterText[i][4], 2);
        TextDrawColor(RegisterText[i][4], 257552383);
        TextDrawSetShadow(RegisterText[i][4], 0);
        TextDrawSetOutline(RegisterText[i][4], 1);
        TextDrawBackgroundColor(RegisterText[i][4], 255);
        TextDrawFont(RegisterText[i][4], 2);
        TextDrawSetProportional(RegisterText[i][4], 1);

        RegisterLeft[i][4] = TextDrawCreate(509.000274, 285.807327, "ld_beat:left");
        TextDrawLetterSize(RegisterLeft[i][4], 0.002000, 0.037333);
        TextDrawTextSize(RegisterLeft[i][4], 17.006999, 17.007396);
        TextDrawAlignment(RegisterLeft[i][4], 1);
        TextDrawColor(RegisterLeft[i][4], -1);
        TextDrawSetShadow(RegisterLeft[i][4], 0);
        TextDrawSetOutline(RegisterLeft[i][4], 0);
        TextDrawFont(RegisterLeft[i][4], 4);
        TextDrawSetSelectable(RegisterLeft[i][4], true);

        RegisterRight[i][4] = TextDrawCreate(586.666137, 285.807327, "ld_beat:right");
        TextDrawLetterSize(RegisterRight[i][4], 0.000000, 0.000000);
        TextDrawTextSize(RegisterRight[i][4], 17.006999, 18.666671);
        TextDrawAlignment(RegisterRight[i][4], 1);
        TextDrawColor(RegisterRight[i][4], -1);
        TextDrawSetShadow(RegisterRight[i][4], 0);
        TextDrawSetOutline(RegisterRight[i][4], 0);
        TextDrawFont(RegisterRight[i][4], 4);
        TextDrawSetSelectable(RegisterRight[i][4], true);  
    }
Para quem nгo conhece sobre essas funзхes do textdraw (e por isso estб lendo este tutorial), eis a clarificaзгo de alguns termos:

pawn Код:
RegisterRight[i][4] = TextDrawCreate(586.666137, 285.807327, "ld_beat:right");
A linha acima contйm um nome estranho (ld_beat:right). Este nome й justamente a identificaзгo da textura. Utilizando a fonte 4 (vide abaixo), vocк coloca texturas ao invйs de textos. A sintaxe й: LIVRARIA:NOMEDATEXTURA.
No caso, fica a livraria de texutras ld_beat, textura right.txd. Ao entrar no Sprite Browser, vocк poderб identificar facilmente a livraria e textura no canto inferior esquerdo do programa.

pawn Код:
TextDrawFont(RegisterRight[i][4], 4); //Fonte tipo 4, para texturas.
pawn Код:
TextDrawSetSelectable(RegisterRight[i][4], true);
A linha acima torna a textdraw RegisterRight[i][4] selecionбvel, ou seja, vocк pode clicar nela.

A razгo pela qual existem textdraws nгo clicбveis, porйm separadas por jogador e com texto, como a textdraw abaixo, tem a ver com o sistema de registro implementado, que serб explicado no decorrer deste tutorial.

pawn Код:
RegisterText[i][2] = TextDrawCreate(556.331970, 241.007354, "45kg"); //Linha de texto.
Essas linhas de texto existem pois a cada vez que o jogador clica numa seta esquerda ou direita, o valor deste texto й alterado para mais ou para menos. Como fazer isso? Utilizando a callback OnPlayerClickTextDraw.

pawn Код:
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
    if(_:clickedid != INVALID_TEXT_DRAW)
    {
        if(clickedid == RegisterLeft[playerid][0])
        {
            new x = GetPVarInt(playerid, "RegisterSelection0");
            x--;
            SetPVarInt(playerid, "RegisterSelection0", x);
            if(GetPVarInt(playerid, "RegisterSelection0") < 18) SetPVarInt(playerid, "RegisterSelection0", 100);
            new string[128];
            format(string, 128, "%i", GetPVarInt(playerid, "RegisterSelection0"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][0]);
            TextDrawSetString(RegisterText[playerid][0], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][0]);
        }
        else if(clickedid == RegisterRight[playerid][0])
        {
            new x = GetPVarInt(playerid, "RegisterSelection0");
            x++;
            SetPVarInt(playerid, "RegisterSelection0", x);
            if(GetPVarInt(playerid, "RegisterSelection0") > 100) SetPVarInt(playerid, "RegisterSelection0", 18);
            new string[128];
            format(string, 128, "%i", GetPVarInt(playerid, "RegisterSelection0"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][0]);
            TextDrawSetString(RegisterText[playerid][0], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][0]);
        }
        else if(clickedid == RegisterLeft[playerid][1])
        {
            new x = GetPVarInt(playerid, "RegisterSelection1");
            x--;
            SetPVarInt(playerid, "RegisterSelection1", x);
            if(GetPVarInt(playerid, "RegisterSelection1") < 130) SetPVarInt(playerid, "RegisterSelection1", 220);
            new string[128];
            format(string, 128, "%icm", GetPVarInt(playerid, "RegisterSelection1"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][1]);
            TextDrawSetString(RegisterText[playerid][1], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][1]);
        }
        else if(clickedid == RegisterRight[playerid][1])
        {
            new x = GetPVarInt(playerid, "RegisterSelection1");
            x++;
            SetPVarInt(playerid, "RegisterSelection1", x);
            if(GetPVarInt(playerid, "RegisterSelection1") > 220) SetPVarInt(playerid, "RegisterSelection1", 130);
            new string[128];
            format(string, 128, "%icm", GetPVarInt(playerid, "RegisterSelection1"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][1]);
            TextDrawSetString(RegisterText[playerid][1], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][1]);
        }
        else if(clickedid == RegisterLeft[playerid][2])
        {
            new x = GetPVarInt(playerid, "RegisterSelection2");
            x--;
            SetPVarInt(playerid, "RegisterSelection2", x);
            if(GetPVarInt(playerid, "RegisterSelection2") < 45) SetPVarInt(playerid, "RegisterSelection2", 220);
            new string[128];
            format(string, 128, "%ikg", GetPVarInt(playerid, "RegisterSelection2"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][2]);
            TextDrawSetString(RegisterText[playerid][2], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][2]);
        }
        else if(clickedid == RegisterRight[playerid][2])
        {
            new x = GetPVarInt(playerid, "RegisterSelection2");
            x++;
            SetPVarInt(playerid, "RegisterSelection2", x);
            if(GetPVarInt(playerid, "RegisterSelection2") > 220) SetPVarInt(playerid, "RegisterSelection2", 45);
            new string[128];
            format(string, 128, "%ikg", GetPVarInt(playerid, "RegisterSelection2"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][2]);
            TextDrawSetString(RegisterText[playerid][2], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][2]);
        }
        else if(clickedid == RegisterLeft[playerid][3])
        {
            new x = GetPVarInt(playerid, "RegisterSelection3");
            x--;
            SetPVarInt(playerid, "RegisterSelection3", x);
            if(GetPVarInt(playerid, "RegisterSelection3") < 1) SetPVarInt(playerid, "RegisterSelection3", 299);
            new string[128];
            format(string, 128, "%i", GetPVarInt(playerid, "RegisterSelection3"));
            SetPlayerSkin(playerid, GetPVarInt(playerid, "RegisterSelection3"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][3]);
            TextDrawSetString(RegisterText[playerid][3], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][3]);
        }
        else if(clickedid == RegisterRight[playerid][3])
        {
            new x = GetPVarInt(playerid, "RegisterSelection3");
            x++;
            SetPVarInt(playerid, "RegisterSelection3", x);
            if(GetPVarInt(playerid, "RegisterSelection3") > 299) SetPVarInt(playerid, "RegisterSelection3", 1);
            new string[128];
            format(string, 128, "%i", GetPVarInt(playerid, "RegisterSelection3"));
            SetPlayerSkin(playerid, GetPVarInt(playerid, "RegisterSelection3"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][3]);
            TextDrawSetString(RegisterText[playerid][3], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][3]);
        }
        else if(clickedid == RegisterLeft[playerid][4])
        {
            new x = GetPVarInt(playerid, "RegisterSelection4");
            x--;
            SetPVarInt(playerid, "RegisterSelection4", x);
            if(GetPVarInt(playerid, "RegisterSelection4") < 1) SetPVarInt(playerid, "RegisterSelection4", 3);
            new string[128];
            switch (GetPVarInt(playerid, "RegisterSelection4"))
            {
                case 1: format(string, 128, "Posto", GetPVarInt(playerid, "RegisterSelection4"));
                case 2: format(string, 128, "Praзa", GetPVarInt(playerid, "RegisterSelection4"));
                case 3: format(string, 128, "Pier", GetPVarInt(playerid, "RegisterSelection4"));
            }
            TextDrawHideForPlayer(playerid, RegisterText[playerid][4]);
            TextDrawSetString(RegisterText[playerid][4], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][4]);
        }
        else if(clickedid == RegisterRight[playerid][4])
        {
            new x = GetPVarInt(playerid, "RegisterSelection4");
            x++;
            SetPVarInt(playerid, "RegisterSelection4", x);
            if(GetPVarInt(playerid, "RegisterSelection4") > 3) SetPVarInt(playerid, "RegisterSelection4", 1);
            new string[128];
            switch (GetPVarInt(playerid, "RegisterSelection4"))
            {
                case 1: format(string, 128, "Posto", GetPVarInt(playerid, "RegisterSelection4"));
                case 2: format(string, 128, "Praзa", GetPVarInt(playerid, "RegisterSelection4"));
                case 3: format(string, 128, "Pier", GetPVarInt(playerid, "RegisterSelection4"));
            }
            TextDrawHideForPlayer(playerid, RegisterText[playerid][4]);
            TextDrawSetString(RegisterText[playerid][4], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][4]);
        }
        else if(clickedid == RegisterClick[playerid])
        {
            SetPVarInt(playerid, "Age", GetPVarInt(playerid, "RegisterSelection0"));
            SetPVarInt(playerid, "Height", GetPVarInt(playerid, "RegisterSelection1"));
            SetPVarInt(playerid, "Weight", GetPVarInt(playerid, "RegisterSelection2"));
            SetPVarInt(playerid, "Skin", GetPVarInt(playerid, "RegisterSelection3"));
            SetPVarInt(playerid, "Spawn", GetPVarInt(playerid, "RegisterSelection4"));
            SendSystemMessage(playerid, "Registro completo com sucesso!");
            switch(GetPVarInt(playerid, "Spawn"))
            {
                case 1:
                {
                    SetPVarFloat(playerid, "PosX", 116.7447);
                    SetPVarFloat(playerid, "PosY", 1094.8406);
                    SetPVarFloat(playerid, "PosZ", 13.6126);
                    SetPVarInt(playerid, "Int", 0);
                    SetPVarInt(playerid, "VW", 0);
                }
                case 2:
                {
                    SetPVarFloat(playerid, "PosX", -146.1487);
                    SetPVarFloat(playerid, "PosY", 1124.4265);
                    SetPVarFloat(playerid, "PosZ", 19.7422);
                    SetPVarInt(playerid, "Int", 0);
                    SetPVarInt(playerid, "VW", 0);
                }
                case 3:
                {
                    SetPVarFloat(playerid, "PosX", -396.9557);
                    SetPVarFloat(playerid, "PosY", 911.6937);
                    SetPVarFloat(playerid, "PosZ", 10.9430);
                    SetPVarInt(playerid, "Int", 0);
                    SetPVarInt(playerid, "VW", 0);
                }
            }
            SetPlayerPos(playerid, GetPVarFloat(playerid, "PosX"), GetPVarFloat(playerid, "PosY"), GetPVarFloat(playerid, "PosZ"));
            SetPlayerInterior(playerid, 0);
            SetPlayerVirtualWorld(playerid, 0);
            SetCameraBehindPlayer(playerid);
            TextDrawHideForPlayer(playerid, RegisterOption[0]);
            TextDrawHideForPlayer(playerid, RegisterOption[1]);
            TextDrawHideForPlayer(playerid, RegisterOption[2]);
            TextDrawHideForPlayer(playerid, RegisterOption[3]);
            TextDrawHideForPlayer(playerid, RegisterOption[4]);
            TextDrawHideForPlayer(playerid, RegisterOption[5]);
            TextDrawHideForPlayer(playerid, RegisterOption[6]);
            TextDrawHideForPlayer(playerid, RegisterClick[playerid]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][0]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][0]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][0]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][1]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][1]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][1]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][2]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][2]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][2]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][3]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][3]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][3]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][4]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][4]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][4]);
            SetPVarInt(playerid, "Registered", 1);
            SavePlayerData(playerid);
            CancelSelectTextDraw(playerid);
            TogglePlayerControllable(playerid, true);
            return 1;
        }
    }
    return 1;
}

Dissecando todo o cуdigo acima...



pawn Код:
if(_:clickedid != INVALID_TEXT_DRAW)
    {
        if(clickedid == RegisterLeft[playerid][0])
Devido a um bug no sistema de Textdraws, caso vocк use a funзгo CancelSelectTextDraw(playerid), ela irб chamar a callback de novo, com a id INVALID_TEXT_DRAW, causando um loop. O primeiro IF acima ( if(_:clickedid != INVALID_TEXT_DRAW) ) previne este bug.

A seguir, vem uma sйrie de IF's, separando cada textdraw em um caso diferente. A funзгo de todas as textdraws de setas (RegisterLeft e RegisterRight) serve, como dito anteriormente, para adicionar ou subtrair um valor que serб mostrado em texto, e, portanto, tem funcionalidade semelhante. Mostrarei duas abaixo e explicarei-as detalhadamente.

pawn Код:
else if(clickedid == RegisterLeft[playerid][3])
        {
            new x = GetPVarInt(playerid, "RegisterSelection3"); //Variбvel para guardar o valor atual da seleзгo;
            x--; //Ao clicar na seta esquerda, ele diminui o valor...
            SetPVarInt(playerid, "RegisterSelection3", x); //... e o coloca novamente na variбvel.
            if(GetPVarInt(playerid, "RegisterSelection3") < 1) SetPVarInt(playerid, "RegisterSelection3", 299);
//Na linha acima, caso o valor seja menor que 1, ao clicar na seta esquerda, ele se torna 299. (SKINS);
            new string[128];
            format(string, 128, "%i", GetPVarInt(playerid, "RegisterSelection3"));
//formata o texto com a ID da skin;
            SetPlayerSkin(playerid, GetPVarInt(playerid, "RegisterSelection3"));
//Seta no jogador a skin na qual o valor que й mostrado no texto (e alterado pelas setas);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][3]);
//Esconde o texto para atualizaзгo;
            TextDrawSetString(RegisterText[playerid][3], string);
//Altera a textdraw que mostra o valor da skin;
            TextDrawShowForPlayer(playerid, RegisterText[playerid][3]);
//Mostra novamente o texto;
        }
Abaixo, a mesma situaзгo й descrita, porйm com o acrйscimo da variбvel que guarda a skin.

pawn Код:
else if(clickedid == RegisterRight[playerid][3])
        {
            new x = GetPVarInt(playerid, "RegisterSelection3"); //Variбvel que guarda a skin;
            x++; //Adiзгo ao clicar na seta direita;
            SetPVarInt(playerid, "RegisterSelection3", x); // Atualizaзгo no valor;
            if(GetPVarInt(playerid, "RegisterSelection3") > 299) SetPVarInt(playerid, "RegisterSelection3", 1);
//Caso a variбvel seja 299 e o jogador clicar na seta direita, ela retornarб a 1;
            new string[128];
//Abaixo a atualizaзгo do valor na textdraw;
            format(string, 128, "%i", GetPVarInt(playerid, "RegisterSelection3"));
            SetPlayerSkin(playerid, GetPVarInt(playerid, "RegisterSelection3"));
            TextDrawHideForPlayer(playerid, RegisterText[playerid][3]);
            TextDrawSetString(RegisterText[playerid][3], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][3]);
        }
Abaixo, temos um texto que й modificado da mesma maneira, porйm mostrado com valores diferentes.

pawn Код:
else if(clickedid == RegisterLeft[playerid][4])
        {
            //Mesmo esquema de antes: Para seta esquerda subtraзгo, para seta direita, adiзгo do valor.
                        new x = GetPVarInt(playerid, "RegisterSelection4");
            x--;
            SetPVarInt(playerid, "RegisterSelection4", x);
//Ao chegar em 1 (valor mнnimo), ele volta para 3;
            if(GetPVarInt(playerid, "RegisterSelection4") < 1) SetPVarInt(playerid, "RegisterSelection4", 3);
            new string[128];
            //Aqui, eu coloquei um switch para os valores. Cada valor corresponde a um texto diferente, como formatado abaixo;
                        switch (GetPVarInt(playerid, "RegisterSelection4"))
            {
                case 1: format(string, 128, "Posto", GetPVarInt(playerid, "RegisterSelection4"));
                case 2: format(string, 128, "Praca", GetPVarInt(playerid, "RegisterSelection4"));
                case 3: format(string, 128, "Pier", GetPVarInt(playerid, "RegisterSelection4"));
            }
            TextDrawHideForPlayer(playerid, RegisterText[playerid][4]);
            TextDrawSetString(RegisterText[playerid][4], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][4]);
        }
A mesma coisa acontece abaixo, porйm, adicionado os valores;

pawn Код:
else if(clickedid == RegisterRight[playerid][4])
        {
            new x = GetPVarInt(playerid, "RegisterSelection4");
            x++;
            SetPVarInt(playerid, "RegisterSelection4", x);
//Ao chegar no valor mбximo (3), ele retorna para o inнcio;
            if(GetPVarInt(playerid, "RegisterSelection4") > 3) SetPVarInt(playerid, "RegisterSelection4", 1);
            new string[128];
            switch (GetPVarInt(playerid, "RegisterSelection4"))
            {
                case 1: format(string, 128, "Posto", GetPVarInt(playerid, "RegisterSelection4"));
                case 2: format(string, 128, "Praca", GetPVarInt(playerid, "RegisterSelection4"));
                case 3: format(string, 128, "Pier", GetPVarInt(playerid, "RegisterSelection4"));
            }
            TextDrawHideForPlayer(playerid, RegisterText[playerid][4]);
            TextDrawSetString(RegisterText[playerid][4], string);
            TextDrawShowForPlayer(playerid, RegisterText[playerid][4]);
        }

Agora, para o ъltimo botгo, o que confirma suas mudanзas.

pawn Код:
else if(clickedid == RegisterClick[playerid])
        {
            //Abaixo sгo somente variбveis que correspondem a meu sistema de informaзхes;
                        SetPVarInt(playerid, "Age", GetPVarInt(playerid, "RegisterSelection0"));
            SetPVarInt(playerid, "Height", GetPVarInt(playerid, "RegisterSelection1"));
            SetPVarInt(playerid, "Weight", GetPVarInt(playerid, "RegisterSelection2"));
            SetPVarInt(playerid, "Skin", GetPVarInt(playerid, "RegisterSelection3"));
            SetPVarInt(playerid, "Spawn", GetPVarInt(playerid, "RegisterSelection4"));
            SendSystemMessage(playerid, "Registro completo com sucesso!");
            //Como visto acima, cada spawn tem um nome diferente, portanto este coleta o spawn selecionado pelo jogador, e o coloca lб;
                        switch(GetPVarInt(playerid, "Spawn"))
            {
                case 1:
                {
                    SetPVarFloat(playerid, "PosX", 116.7447);
                    SetPVarFloat(playerid, "PosY", 1094.8406);
                    SetPVarFloat(playerid, "PosZ", 13.6126);
                    SetPVarInt(playerid, "Int", 0);
                    SetPVarInt(playerid, "VW", 0);
                }
                case 2:
                {
                    SetPVarFloat(playerid, "PosX", -146.1487);
                    SetPVarFloat(playerid, "PosY", 1124.4265);
                    SetPVarFloat(playerid, "PosZ", 19.7422);
                    SetPVarInt(playerid, "Int", 0);
                    SetPVarInt(playerid, "VW", 0);
                }
                case 3:
                {
                    SetPVarFloat(playerid, "PosX", -396.9557);
                    SetPVarFloat(playerid, "PosY", 911.6937);
                    SetPVarFloat(playerid, "PosZ", 10.9430);
                    SetPVarInt(playerid, "Int", 0);
                    SetPVarInt(playerid, "VW", 0);
                }
            }
                        //Abaixo, a posiзгo e cвmera do jogador й setada, e as textdraws sгo escondidas da tela do jogador;
            SetPlayerPos(playerid, GetPVarFloat(playerid, "PosX"), GetPVarFloat(playerid, "PosY"), GetPVarFloat(playerid, "PosZ"));
            SetPlayerInterior(playerid, 0);
            SetPlayerVirtualWorld(playerid, 0);
            SetCameraBehindPlayer(playerid);
            TextDrawHideForPlayer(playerid, RegisterOption[0]);
            TextDrawHideForPlayer(playerid, RegisterOption[1]);
            TextDrawHideForPlayer(playerid, RegisterOption[2]);
            TextDrawHideForPlayer(playerid, RegisterOption[3]);
            TextDrawHideForPlayer(playerid, RegisterOption[4]);
            TextDrawHideForPlayer(playerid, RegisterOption[5]);
            TextDrawHideForPlayer(playerid, RegisterOption[6]);
            TextDrawHideForPlayer(playerid, RegisterClick[playerid]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][0]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][0]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][0]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][1]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][1]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][1]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][2]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][2]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][2]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][3]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][3]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][3]);
            TextDrawHideForPlayer(playerid, RegisterText[playerid][4]);
            TextDrawHideForPlayer(playerid, RegisterLeft[playerid][4]);
            TextDrawHideForPlayer(playerid, RegisterRight[playerid][4]);
            SetPVarInt(playerid, "Registered", 1);
            SavePlayerData(playerid);
//Em CancelSelectTextDraw, o jogador nгo poderб mais selecionar textdraws;
            CancelSelectTextDraw(playerid);
            TogglePlayerControllable(playerid, true);
            return 1;
        }

Pronto. A estrutura bбsica deste sistema foi criada e explicada acima. Portanto, como passo final, necessitamos mostrar ela em algum ponto do gamemode. Isto foi feito com a stock abaixo:

pawn Код:
stock StartRegister(playerid)
{
    //Abaixo, o jogador й colocado em uma sala e travado, para poder editar seu personagem;
        SetPVarFloat(playerid, "Health", 100);
    SpawnPlayer(playerid);
    SetPlayerInterior(playerid, 14);
    SetPlayerPos(playerid, 258.3504,-41.5838,1002.0234);
    TogglePlayerControllable(playerid, false);
    SetPlayerCameraPos(playerid, 254.1672,-41.8898,1003.2319);
    SetPlayerCameraLookAt(playerid, 258.3504,-41.5838,1002.0234);
        //Abaixo, os valores padrгo de cada um dos textos e variбveis que serгo editados pelos textdraws clicбveis sгo setados;
    SetPVarInt(playerid, "RegisterSelection0", 18);
    SetPVarInt(playerid, "RegisterSelection1", 130);
    SetPVarInt(playerid, "RegisterSelection2", 45);
    SetPVarInt(playerid, "RegisterSelection3", 1);
    SetPVarInt(playerid, "RegisterSelection4", 1);
//Abaixo, todas as textdraws sгo mostradas para o jogador;
    TextDrawShowForPlayer(playerid, RegisterOption[0]);
    TextDrawShowForPlayer(playerid, RegisterOption[1]);
    TextDrawShowForPlayer(playerid, RegisterOption[2]);
    TextDrawShowForPlayer(playerid, RegisterOption[3]);
    TextDrawShowForPlayer(playerid, RegisterOption[4]);
    TextDrawShowForPlayer(playerid, RegisterOption[5]);
    TextDrawShowForPlayer(playerid, RegisterOption[6]);
    TextDrawShowForPlayer(playerid, RegisterClick[playerid]);
    TextDrawShowForPlayer(playerid, RegisterText[playerid][0]);
    TextDrawShowForPlayer(playerid, RegisterLeft[playerid][0]);
    TextDrawShowForPlayer(playerid, RegisterRight[playerid][0]);
    TextDrawShowForPlayer(playerid, RegisterText[playerid][1]);
    TextDrawShowForPlayer(playerid, RegisterLeft[playerid][1]);
    TextDrawShowForPlayer(playerid, RegisterRight[playerid][1]);
    TextDrawShowForPlayer(playerid, RegisterText[playerid][2]);
    TextDrawShowForPlayer(playerid, RegisterLeft[playerid][2]);
    TextDrawShowForPlayer(playerid, RegisterRight[playerid][2]);
    TextDrawShowForPlayer(playerid, RegisterText[playerid][3]);
    TextDrawShowForPlayer(playerid, RegisterLeft[playerid][3]);
    TextDrawShowForPlayer(playerid, RegisterRight[playerid][3]);
    TextDrawShowForPlayer(playerid, RegisterText[playerid][4]);
    TextDrawShowForPlayer(playerid, RegisterLeft[playerid][4]);
    TextDrawShowForPlayer(playerid, RegisterRight[playerid][4]);
//A linha abaixo faz com que as textdraws que sгo selecionбveis possam ser selecionadas, mostrando o mouse. A funзгo permite tambйm mudar a cor da textdraw selecionada para qualquer uma que vocк quiser, com os mesmos parвmetros de cor da funзгo SendClientMessage;
    SelectTextDraw(playerid, COLOR_SYSBLUE);
    return 1;
}

E fim!



Qualquer dъvida e/ou comentбrio, incluindo crнticas, sгo bem vindos.
Reply
#2

Bom tutorial estava faltando mesmo algo relacionado a isso aqui na board.
Poderia utilizar tambйm o switch no OnPlayerClickTextDraw, mesmo assim good job.
Reply
#3

Уtimo tutorial ! Tudo muito bem explicado. Parabйns +REP
Reply
#4

Otimo Tutorial, bem organizado e bem explicado, +rep
Reply
#5

Bom tutorial, mas faltou explicares o OnPlayerClickPlayerTextdraw em conjunto com o CreatePlayerTextdraw
Reply
#6

Nada mal , mais poderia melhorar , como o BlueX disse , deveria explicar o PlayerTextdraw , tambйm deveria falar sobre cada funзгo utilizada para criar uma textdraw , por mais que este tutorial seja destinada apenas a parte clicбvel e nгo a criaзгo de textdraws .

Enfim , parabйns pelo esforзo .
Reply
#7

Valeu, galera.

@darkxdll e @BlueX talvez, mas o tutorial й sobre Textdraws Clickбveis, nгo sobre PlayerTextdraws e/ou criaзгo de textdraws.
Reply
#8

Уtimo tutorial ! Tudo muito bem explicado. Parabйns
Reply
#9

Quote:
Originally Posted by LeLeTe
Посмотреть сообщение
Valeu, galera.

@darkxdll e @BlueX talvez, mas o tutorial й sobre Textdraws Clickбveis, nгo sobre PlayerTextdraws e/ou criaзгo de textdraws.
Sim, mas tambйm existem PlayerTextdraws clicбveis coisa que tu nгo referiste neste tutorial.
Por isso que referi o OnPlayerClickPlayerTextdraw
Reply
#10

Parabйns, bom tutorial, apenas achei um possнvel erro:

Ao player clicar ESC segundo a checagem em OnPlayerClickTextDraw, serб ignorado, igual ao CancelSelectTextDraw, assim deixando a textdraw na tela e cancelando a seleзгo do cursor...
pawn Код:
if(_:clickedid != INVALID_TEXT_DRAW)
E creio que o certo seria retirar as textdraws da tela ao ser chamado INVALID_TEXT_DRAW, mas claro como disse, ao cancelar a seleзгo da mesma, faria com que sumisse a textdraw atual, por isso seria ecencial o uso de uma variбvel para checar se nгo foi chamada a funзгo CancelSelectTextDraw. Assim previniria bugs ao ser cancelado com a tecla ESC.

OBS IMPORTANTE: Tambйm vi que nгo citou que se nгo me engano, apenas as textdraws que forem Textos, й obrigatуrio o uso de box e textsize que serб o tamanho da regiгo selecionбvel.


@OFF Tambйm estava pensando em criar um tutorial do mesmo, parabйns! Tomara que agora criem e explorem mais textdraws, pois nгo й muito vista em aзгo nessa broad.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)