[Tutorial] Crear textdraws de estadisticas
#1

Hola, en este tutorial les enseсare a crear textdraws de estadisticas (O sea, los que son individuales para cada player. Por ejemplo: muestran su ping).



_________________________________________________



1) Crearemos el textdraw. їComo?
Usando Zamaroth's text draw editor!
Una vez que lo creamos lo exportaremos en modo CLASICO.



_________________________________________________



2) Ahora abrimos el archivo .txt que nos genero el TextDraw editor. Copiamos su contenido, ahora vamos a la parte de arriba de nuestro script donde alli agregaremos:
pawn Код:
new Text:nombredeltext[MAX_PLAYERS];


_________________________________________________



3) Bueno aqui empezaremos a crear los text draws de estadisticas. Hay 2 formas de hacerlo:

Antes de ver las formas primero con las lineas de nuestro textdraw haremos lo siguiente:
Remplazamos le nombre Textdraw0 por el nombre de nuestro textdraw y le agregaremos el [playerid] adelante.
Ejemplo:
pawn Код:
Ping[playerid] = TextDrawCreate(634.000000, 417.000000, "Ping: 0");
TextDrawAlignment(Ping[playerid], 3);
TextDrawBackgroundColor(Ping[playerid], 0x000000FF);
TextDrawFont(Ping[playerid], 2);
TextDrawLetterSize(Ping[playerid], 0.499999, 1.400000);
TextDrawSetOutline(Ping[playerid], 1);
  • 1:
    pawn Код:
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
    // Lineas de nuestro textdraw
    }
    Esta linea crea 500 textdraws (1 para cada player). Es la menos recomendada, dado a que segun el limite de textdraws de samp (204 solo podriamos crear 4 textdraws actualizables.
-------------------------------------------------------------------------------
  • 2:
    pawn Код:
    for(new playerid = 0; playerid < GetMaxPlayers(); playerid ++)
    {
    // Lineas de nuestro textdraw
    }
    Esta es la que recomiendo crea los textdraws suficientes para los slots de tu server, (si tu server tiene 500 slots es lo mismo que nada, recomendaria no mas de 200 slots).


_________________________________________________



4) Ahora crearemos un timer que actulize los textdraws cada sierto tiempo:

En la parte de arriba de nuestro script: forward ActualizarTextDraws();
En OnGameModeInit: SetTimer("ActualizarTextDraws", 200, true);
Bueno ahi definimos una nueva funcion y creamos un cronometro que se repite actualizando constantemente los textdraws.



_________________________________________________



5) El callback, aqui pondremos el codigo para que nuestro textdraw se actualize:

Si en el paso 3 usaste el modo 1 sigue esta:

pawn Код:
public ActualizarTextDraws()
{
    new String[100];

    for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            format(String, sizeof(String), "Ping: %d", GetPlayerPing(playerid));
            TextDrawSetString(Ping[playerid], String);
            TextDrawShowForPlayer(playerid, Ping[playerid]);
        }
    }
}
De lo contrario esta:

pawn Код:
public ActualizarTextDraws()
{
    new String[100];

    for(new playerid = 0; playerid < GetMaxPlayers(); playerid ++)
    {
        if(IsPlayerConnected(playerid))
        {
            format(String, sizeof(String), "Ping: %d", GetPlayerPing(playerid));
            TextDrawSetString(Ping[playerid], String);
            TextDrawShowForPlayer(playerid, Ping[playerid]);
        }
    }
}

Que hicimos ahi? Usamos el for para checkear todos los slots a la vez. Luego checkeamos si esta conectado el jugador. Y luego actualizamos su textdraw.

Yo he creado el tutorial usando el ejemplo de un textdraw de ping. Ustedes pueden hacerlo de otras cosas.
Cualquier duda pregunten
Reply
#2

MMM se podria hacer de niveles
Reply
#3

Buen Tuto
Reply
#4

Se agradece.
Reply
#5

Porque no se crea el TextDraw en OnPlayerConnect? Asн supuestamente el TextDraw se crea para cada jugador. No?
_________________
Saludos...
Reply
#6

Buen tutorial MrDeath
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)