Player with highest score wins
#1

I had a function, which worked out who has most score - making them win.

I noticed a bug, that when more than 1 player have the same score, it gets confused.

How can I make a function that does the score automatically?
Reply
#2

"simplify" is the magic word. how would you estimate the best player out of 10? each one with a score, ranging from 0 to 1000 (random values):
Код:
PlayerID:	0	1	2	3	4	5	6	7	8	9
Score:		43	872	108	150	134	10	48	644	872	123
there are 2 players with the (highest) score of 872. i can think of 4 ways to solve it now:
a) both share the win (good for money, but a bad idea with a house)? possible maybe.
b) both players gets ignored, since there is no "better" of them both, so the 3rd player with the second high score, wins? hillarious.
c) the player who scored in first place, wins (older score, without dying?) acceptable.
d) the player who recently scored the highest amount (like grabbing the trophy)? acceptable.
c and d seem to be the best way to solve it. one reason for your function getting confused, could be a simple linear search like
pawn Код:
new BestScore,BestID,Score;
for(new id=0;id<MAX_PLAYERS;id++)
{
Score=GetPlayerScore(id)
if(Score>BestScore)
{
BestScore=Score;
BestID=id;
}
}
this linear search compares the (yet) best score reachd with the actual id in the loop. once its higher, it will be the next value to be compared with, and the playerid gets put into BestID. the player (8) with the same score as player (1) gets ignored, coz 872 is not bigger than 872. its a hybrid of c) and d), coz if player (8) would achieve 872 as first, then the loop would ignore him due to the fact that his id is 8, and the player who recently achieved 872 too, is player id 1. (due to the fact that the loop goes from 0 to 9 upwards). unfair.
you need another solution to make sure how your script reacts.
do you want the first player to "hold" his trophy? or do you want a player who reaches 872 too (bot later), wins?
in both cases, you will need another variable, which stores the TickCount of his scoring.
if you are playerid (8) from the example above, and iam player (1), but you claimed 872 score first, then you should win, since you were faster, thats my opinion. if you gain a score, simply
pawn Код:
TimeScore[playerid]=GetTickCount();
so you can compare the players score TIME aswell later: the player with the oldest time (if the same score), wins :)
Reply
#3

I currently use d, but would love to be able to use a. If you could point me in the right direction of how I would do this, I'd appreciate it a lot!
Reply
#4

hm. heres a 2-pass solution:
pawn Код:
//top of the script
new MaxPlayers;
//...
//OnGameModeInit()
MaxPlayers=GetMaxPlayers();


new BestScore=-999999,Score,HighScoredPlayers;
for(new id=0;id<MaxPlayers;id++)//estimate the highest score...
{
    Score=GetPlayerScore(id);
    if(Score>BestScore)
    {
        BestScore=Score;
    }
}
for(new id=0;id<MaxPlayers;id++)//...to "collect" the players...
{
    Score=GetPlayerScore(id);//...according to that amount
    if(Score==BestScore)//if that (highest) score matches, then...
    {
        HighScoredPlayers++;//...add 1, and...
    }
}

//now the amount of players with the highscor are known, you can use it dor dividing the reward:
new Reward=1000000;//use your scripts variable for Reward

new Part=Reward/HighScoredPlayers;//...reward all (either 1 or more) players, like in the next loop, which is basically the same

for(new id=0;id<MaxPlayers;id++)
{
    Score=GetPlayerScore(id);
    if(Score==BestScore)
    {
        GivePlayerMoney(id,Part);//replace this by your method (serversided money)
    }
}
dont try to combine those loops please
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)