#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]);
}
}
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.
Have you even tested that BubbleSort function?
You have to be lucky to have an array which actually gets sorted by using that function. |
#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]);
}
}
This will get the player with the highest score:
pawn Код:
|
The function was tested and working.
#You can replace: pawn Код:
|
error 001: expected token: "-identifier-", but found ";" error 017: undefined symbol "i"
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]);
}
}
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
pawn Код:
Код:
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 |
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]);
}
}
[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