Highest score!
#1

hello. how can i make the highest score player will win the game?
i've already searched for it, but all of them shows the Top list, not picking up the player who got the highest score..
thanks.
Reply
#2

i made this for this tуpic: (http://forum.sa-mp.com/showthread.ph...23#post1708323),
bugs ? report for my on post xD

pawn Код:
#include <a_samp>

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/rankScore", true))
    {
        static
            Scores[MAX_PLAYERS],
            String[128],
            Nome[24],
            IntVar,
        ;
           
        for(IntVar = 0; IntVar != MAX_PLAYERS; ++IntVar) Scores[IntVar] = GetPlayerScore(IntVar);
       
        BubbleSort(Scores, sizeof(Scores));
       
        for(IntVar = 0; IntVar < 10; ++i)
        {  
            GetPlayerName(IntVar, Nome, 24);
            format(String, sizeof(String),"%i є  Name: %s Score: %s", IntVar+1, Nome, Scores[IntVar]);
            SendClientMessage(playerid, -1, String);
        }
        return 1;
    }
    return 0;
}


static stock BubbleSort(v[], size)
{
    #if !defined swap
        #define swap(%0,%1)  (%0 ^= %1, %1 ^= %0, %0 ^= %1)
    #endif
    for(new i = 1; i != size; ++i)
    {
        for(new q = 0; (q != size - i); ++q)if(v[i] > v[q]) s_swap(v[q],v[i]);
    }
}
Reply
#3

Have you even tested that BubbleSort function?

You have to be lucky to have an array which actually gets sorted by using that function.
Reply
#4

This will get the player with the highest score:
pawn Код:
new
    iHighest;

for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        if(GetPlayerScore(i) > GetPlayerScore(iHighest)) iHighest = i;
    }
}

// The variable: "iHighest" now contains the player id holding the highest score.
Reply
#5

im sorry, but what does it do?
Reply
#6

Quote:
Originally Posted by Finn
Посмотреть сообщение
Have you even tested that BubbleSort function?

You have to be lucky to have an array which actually gets sorted by using that function.
The function was tested and working.


#You can replace:
pawn Код:
#include <a_samp>

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/rankScore", true))
    {
        static
            Scores[MAX_PLAYERS],
            String[128],
            Nome[24],
            IntVar,
        ;
           
        for(IntVar = 0; IntVar != MAX_PLAYERS; ++IntVar) Scores[IntVar] = GetPlayerScore(IntVar);
       
        BubbleSort(Scores, sizeof(Scores));
       
        for(IntVar = 0; IntVar < 10; ++i)
        {  
            GetPlayerName(IntVar, Nome, 24);
            format(String, sizeof(String),"%i є  Name: %s Score: %s", IntVar+1, Nome, Scores[IntVar]);
            SendClientMessage(playerid, -1, String);
        }
        return 1;
    }
    return 0;
}


static stock BubbleSort(v[], size)
{
    #if !defined swap
        #define swap(%0,%1)  (%0 ^= %1, %1 ^= %0, %0 ^= %1)
    #endif
    for(new i = 1; i != size; ++i)
    {
        for(new q = 0; (q != size - i); ++q)if(v[i] > v[q]) swap(v[q],v[i]);
    }
}
Reply
#7

Quote:
Originally Posted by -Prodigy-
Посмотреть сообщение
This will get the player with the highest score:
pawn Код:
new
    iHighest;

for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        if(GetPlayerScore(i) > GetPlayerScore(iHighest)) iHighest = i;
    }
}

// The variable: "iHighest" now contains the player id holding the highest score.
tested, doesnt work.




Quote:
Originally Posted by DarkScripter
Посмотреть сообщение
The function was tested and working.


#You can replace:
pawn Код:
#include <a_samp>

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/rankScore", true))
    {
        static
            Scores[MAX_PLAYERS],
            String[128],
            Nome[24],
            IntVar,
        ;
           
        for(IntVar = 0; IntVar != MAX_PLAYERS; ++IntVar) Scores[IntVar] = GetPlayerScore(IntVar);
       
        BubbleSort(Scores, sizeof(Scores));
       
        for(IntVar = 0; IntVar < 10; ++i)
        {  
            GetPlayerName(IntVar, Nome, 24);
            format(String, sizeof(String),"%i є  Name: %s Score: %s", IntVar+1, Nome, Scores[IntVar]);
            SendClientMessage(playerid, -1, String);
        }
        return 1;
    }
    return 0;
}


static stock BubbleSort(v[], size)
{
    #if !defined swap
        #define swap(%0,%1)  (%0 ^= %1, %1 ^= %0, %0 ^= %1)
    #endif
    for(new i = 1; i != size; ++i)
    {
        for(new q = 0; (q != size - i); ++q)if(v[i] > v[q]) swap(v[q],v[i]);
    }
}
i got 2 errors:
Код:
error 001: expected token: "-identifier-", but found ";"
error 017: undefined symbol "i"

well can you make it become SetTimer and forward please.. it is easier for me to look up, thanks.
Reply
#8

pawn Код:
static stock BubbleSort(v[], size)
{
    #if !defined swap
        #define swap(%0,%1)  (%0 ^= %1, %1 ^= %0, %0 ^= %1)
    #endif
    for(new i = 1; i != size; ++i)
    {
        for(new q = 0; (q != size - i); ++q)if(v[i] > v[q]) swap(v[q],v[i]);
    }
}

main()
{
    new Scores[] = { 10, 9, 1, 1, 1, 1, 9, 1, 1, 7, 8, 9, 10, 1, 1, 5, 1, 1, 10, 12, 1};
    BubbleSort(Scores, sizeof(Scores));
    for(new i; i < sizeof(Scores); i++)
    {
        printf("%i. %d", i, Scores[i]);
    }
}
Prints:
Код:
0. 12
1. 10
2. 10
3. 9
4. 9
5. 8
6. 7
7. 1
8. 1
9. 1
10. 1
11. 1
12. 1
13. 1
14. 1
15. 5
16. 1
17. 1
18. 9
19. 10
20. 1
Reply
#9

Quote:
Originally Posted by Finn
Посмотреть сообщение
pawn Код:
static stock BubbleSort(v[], size)
{
    #if !defined swap
        #define swap(%0,%1)  (%0 ^= %1, %1 ^= %0, %0 ^= %1)
    #endif
    for(new i = 1; i != size; ++i)
    {
        for(new q = 0; (q != size - i); ++q)if(v[i] > v[q]) swap(v[q],v[i]);
    }
}

main()
{
    new Scores[] = { 10, 9, 1, 1, 1, 1, 9, 1, 1, 7, 8, 9, 10, 1, 1, 5, 1, 1, 10, 12, 1};
    BubbleSort(Scores, sizeof(Scores));
    for(new i; i < sizeof(Scores); i++)
    {
        printf("%i. %d", i, Scores[i]);
    }
}
Prints:
Код:
0. 12
1. 10
2. 10
3. 9
4. 9
5. 8
6. 7
7. 1
8. 1
9. 1
10. 1
11. 1
12. 1
13. 1
14. 1
15. 5
16. 1
17. 1
18. 9
19. 10
20. 1
oh yeah!
Fixed =).
pawn Код:
public OnFilterScriptInit()
{
    new Scores[] = { 10, 9, 1, 1, 1, 1, 9, 1, 1, 7, 8, 9, 10, 1, 1, 5, 1, 1, 10, 12, 1};
    BubbleSort(Scores, sizeof(Scores));
    for(new i; i < sizeof(Scores); i++)
    {
        printf("%i. %d", i, Scores[i]);
    }
    return true;
}

static stock BubbleSort(v[], size)
{
    #if !defined swap
        #define swap(%0,%1)   (%0 ^= %1, %1 ^= %0, %0 ^= %1)
    #endif
    for(new i = 1; i != size; ++i)
    {
        for(new q = 0; (q != size); ++q)if(v[i] > v[q]) swap(v[i],v[q]);
    }
}
Prints
Код:
[04:34:04] 0. 12
[04:34:04] 1. 10
[04:34:04] 2. 10
[04:34:04] 3. 10
[04:34:04] 4. 9
[04:34:04] 5. 9
[04:34:04] 6. 9
[04:34:04] 7. 8
[04:34:04] 8. 7
[04:34:04] 9. 5
[04:34:04] 10. 1
[04:34:04] 11. 1
[04:34:04] 12. 1
[04:34:04] 13. 1
[04:34:04] 14. 1
[04:34:04] 15. 1
[04:34:04] 16. 1
[04:34:04] 17. 1
[04:34:04] 18. 1
[04:34:04] 19. 1
[04:34:04] 20. 1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)