SA-MP Forums Archive
[HELP]Team Scores - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP]Team Scores (/showthread.php?tid=276864)



[HELP]Team Scores - Tigerbeast11 - 15.08.2011

I have created 5 vars:
pawn Код:
new BallasScore;
new GroveScore;
new MafiaScore;
new VagosScore;
new AztecaScore;
But I want to find out which of the variables has the greatest value at the end of a round. And what if 2 teams both have the highest score... I think I would need to use loops, but I don't understand loops. I have tried Wiki but it's too confusing.


AW: [HELP]Team Scores - Nero_3D - 16.08.2011

We need to create a function which gets the highest variable

pawn Код:
stock GetHighestVar(...) {
    new
        highest = 0, // lets pretend that the first is the highest, it is also the fallback if all got the same value
        i = (numargs() - 1); // starts at the end of the list to loop
    for( ; i != 0; --i) { // loops through all input variables
        if(getarg(highest) < getarg(i)) { // check if the current variable is bigger than the highest
            highest = i; // sets the highest to the current
        }
    }
    return highest; // return the highest
}
How to use

pawn Код:
switch(GetHighestVar(BallasScore, GroveScore, MafiaScore, VagosScore, AztecaScore)) {
    case 0: {} // BallasScore
    case 1: {} // GroveScore
    case 2: {} // MafiaScore
    case 3: {} // VagosScore
    case 4: {} // AztecaScore
}
But this gets pretty messed up if you need to put for each team their own code

I would suggest arrays with enums


Re: [HELP]Team Scores - Tigerbeast11 - 16.08.2011

I have looked at the wiki, but I don't understand how I would use the enums and arrays together to return the team with the highest score...