[Ayuda] Top players.
#1

їAlguien me da alguna ayuda sobre cуmo hacer algo parecido a йsto?:

Reply
#2

Usa esto
Reply
#3

Sн, ya habнa visto ese post, pero entre que estб en inglйs y que mis conocimientos de pawn no van mбs allб de los bбsico..

Si alguien me explica cуmo usarlo..
Reply
#4

Quote:
Originally Posted by Loox
Посмотреть сообщение
Sн, ya habнa visto ese post, pero entre que estб en inglйs y que mis conocimientos de pawn no van mбs allб de los bбsico..

Si alguien me explica cуmo usarlo..
Suponiendo que tienes definido esto:

pawn Код:
enum rankingEnum
{
    player_Score,
    player_ID
}

stock GetPlayerHighestScores(array[][rankingEnum], left, right)
{
    new
        tempLeft = left,
        tempRight = right,
        pivot = array[(left + right) / 2][player_Score],
        tempVar
    ;
    while(tempLeft <= tempRight)
    {
        while(array[tempLeft][player_Score] > pivot) tempLeft++;
        while(array[tempRight][player_Score] < pivot) tempRight--;
       
        if(tempLeft <= tempRight)
        {
            tempVar = array[tempLeft][player_Score], array[tempLeft][player_Score] = array[tempRight][player_Score], array[tempRight][player_Score] = tempVar;
            tempVar = array[tempLeft][player_ID], array[tempLeft][player_ID] = array[tempRight][player_ID], array[tempRight][player_ID] = tempVar;
            tempLeft++, tempRight--;
        }
    }
    if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
    if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
}
stock Nombre(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
entonces en un comando en lo que quieras que aparesca pones
pawn Код:
new playerScores[MAX_PLAYERS][rankingEnum], index;
for(new i; i != MAX_PLAYERS; ++i)
{
    if(IsPlayerConnected(i) && !IsPlayerNPC(i))
    {
        playerScores[index][player_Score] = GetPlayerScore(i);
        playerScores[index][player_ID] = i;
        ++index;
    }
}
GetPlayerHighestScores(playerScores, 0, index);

for(new i; i != 30; ++i)
{
    new string[512];
    format(string, sizeof(string), "Jugador: %s Score: %d", Nombre(playerScores[i][player_ID]), playerScores[i][player_Score], i);
    TextDrawSetString(Textdraw[i], string);
}

tienes que crear el "Textdraw" y definirlo de esta manera
new Text: Textdraw[31];

no se si funcione correctamente, porque no lo probй.
Reply
#5

A ver, ya conseguн hacer funcionar el cуdigo que me pasaste.

Asн:

Код:
#include <a_samp>

new Text:Textdraw;

enum rankingEnum
{
    player_Score,
    player_ID
}

public OnFilterScriptInit()
{
	Textdraw = TextDrawCreate(499.000000, 15.000000, "");
	TextDrawBackgroundColor(Textdraw, 255);
	TextDrawFont(Textdraw, 1);
	TextDrawLetterSize(Textdraw, 0.310000, 1.200000);
	TextDrawColor(Textdraw, -1);
	TextDrawSetOutline(Textdraw, 0);
	TextDrawSetProportional(Textdraw, 1);
	TextDrawSetShadow(Textdraw, 1);
	TextDrawUseBox(Textdraw, 1);
	TextDrawBoxColor(Textdraw, 255);
	TextDrawTextSize(Textdraw, 603.000000, 0.000000);
	return 1;
}

public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid, Textdraw);
return 1;
}


stock GetPlayerHighestScores(array[][rankingEnum], left, right)
{
    new
        tempLeft = left,
        tempRight = right,
        pivot = array[(left + right) / 2][player_Score],
        tempVar
    ;
    while(tempLeft <= tempRight)
    {
        while(array[tempLeft][player_Score] > pivot) tempLeft++;
        while(array[tempRight][player_Score] < pivot) tempRight--;

        if(tempLeft <= tempRight)
        {
            tempVar = array[tempLeft][player_Score], array[tempLeft][player_Score] = array[tempRight][player_Score], array[tempRight][player_Score] = tempVar;
            tempVar = array[tempLeft][player_ID], array[tempLeft][player_ID] = array[tempRight][player_ID], array[tempRight][player_ID] = tempVar;
            tempLeft++, tempRight--;
        }
    }
    if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
    if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
}

stock Nombre(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}

public OnPlayerCommandText(playerid, cmdtext[])
{

if(strcmp("/prueba", cmdtext, true) == 0)
{
new playerScores[MAX_PLAYERS][rankingEnum], index;
for(new i; i != MAX_PLAYERS; ++i)
{
    if(IsPlayerConnected(i) && !IsPlayerNPC(i))
    {
        playerScores[index][player_Score] = GetPlayerScore(i);
        playerScores[index][player_ID] = i;
        ++index;
    }
}
GetPlayerHighestScores(playerScores, 0, index);

for(new i; i != 30; ++i)
{
    new string[512];
    format(string, sizeof(string), "Jugador: %s Score: %d", Nombre(playerScores[i][player_ID]), playerScores[i][player_Score], i);
    TextDrawSetString(Textdraw, string);
}
return 1;
}

return 0;
}
Pero no sй cуmo hacer el ranking usando йso..
Reply
#6

pawn Код:
#include <a_samp>

new Text:Textdraw[31];

enum rankingEnum
{
    player_Score,
    player_ID
}

public OnFilterScriptInit()
{
    Textdraw[1] = TextDrawCreate(499.000000, 15.000000, ""); // pos 1

        Textdraw[2] = TextDrawCreate(499.000000, 15.000000, ""); // pos 2
        Textdraw[3] = TextDrawCreate(499.000000, 15.000000, ""); // pos 3
        Textdraw[4] = TextDrawCreate(499.000000, 15.000000, ""); // pos 4
        Textdraw[5] = TextDrawCreate(499.000000, 15.000000, ""); // pos 5
// has las posiciones puedes optimizarlas por lineas sumandole a Y y dejar igual X
        for(new i = 0; i < 30; i++)
        {
    TextDrawBackgroundColor(Textdraw[i], 255);
    TextDrawFont(Textdraw[i], 1);
    TextDrawLetterSize(Textdraw[i], 0.310000, 1.200000);
    TextDrawColor(Textdraw[i], -1);
    TextDrawSetOutline(Textdraw[i], 0);
    TextDrawSetProportional(Textdraw[i], 1);
    TextDrawSetShadow(Textdraw[i], 1);
    TextDrawUseBox(Textdraw[i], 1);
    TextDrawBoxColor(Textdraw[i], 255);
    TextDrawTextSize(Textdraw[i], 603.000000, 0.000000);
        }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{

if(strcmp("/prueba", cmdtext, true) == 0)
{
new playerScores[MAX_PLAYERS][rankingEnum], index;
for(new i; i != MAX_PLAYERS; ++i)
{
    if(IsPlayerConnected(i) && !IsPlayerNPC(i))
    {
        playerScores[index][player_Score] = GetPlayerScore(i);
        playerScores[index][player_ID] = i;
        ++index;
    }
}
GetPlayerHighestScores(playerScores, 0, index);

for(new i; i != 30; ++i)
{
    new string[512];
    format(string, sizeof(string), "Jugador: %s Score: %d", Nombre(playerScores[i][player_ID]), playerScores[i][player_Score], i);
    TextDrawSetString(Textdraw[i], string);
    TextDrawShowForPlayer(playerid, TextDraw[i]);
}
return 1;
}

return 0;
}

stock GetPlayerHighestScores(array[][rankingEnum], left, right)
{
    new
        tempLeft = left,
        tempRight = right,
        pivot = array[(left + right) / 2][player_Score],
        tempVar
    ;
    while(tempLeft <= tempRight)
    {
        while(array[tempLeft][player_Score] > pivot) tempLeft++;
        while(array[tempRight][player_Score] < pivot) tempRight--;

        if(tempLeft <= tempRight)
        {
            tempVar = array[tempLeft][player_Score], array[tempLeft][player_Score] = array[tempRight][player_Score], array[tempRight][player_Score] = tempVar;
            tempVar = array[tempLeft][player_ID], array[tempLeft][player_ID] = array[tempRight][player_ID], array[tempRight][player_ID] = tempVar;
            tempLeft++, tempRight--;
        }
    }
    if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
    if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
}

stock Nombre(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
PD: Tienes que crear 30 posiciones Textdraw[ 1 ] una posicion Textdraw[ 2 ] la segunda posiciуn y asн.
Reply
#7

Ya hice una pequeсa prueba del funcionamiento del cуdigo y funciona perfecto. Un millуn de gracias por tu ayuda GROVE22.
Reply
#8

їNo serнa mejor usar ~n~? Digo, en vez de crear 30 textdraw diferentes. Si lo combinas con tabulaciones el cуdigo te quedarб ordenado como en la imagen.
Reply
#9

A ver, me surgiу un pequeсo problema.

El format que actualiza el textdraw en el que aparece el score debe tener algъn error, porque, por ejemplo, me puse el score en 27 y en la tabla me lo marcaba como 77.



Los formats:

Код:
new string[512];
    format(string, sizeof(string), "%s", Nombre(playerScores[i][player_ID]), i);
    TextDrawSetString(Textdraw[i], string);
    format(string, sizeof(string), "%d", Nombre(playerScores[i][player_ID]), playerScores[i][player_Score], i);
    TextDrawSetString(Textdraw19[i], string);
Reply
#10

pawn Код:
new string[512];
    format(string, sizeof(string), "%s", Nombre(playerScores[i][player_ID]));
    TextDrawSetString(Textdraw[i], string);
    format(string, sizeof(string), "%d", playerScores[i][player_Score]);
    TextDrawSetString(Textdraw19[i], string);
Reemplazalo por eso que te va a funcionar
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)