Get the variable with the highest value?

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

SpLayzDK

Member
Jun 15, 2019
14
0
1
30
Hi, so i got 10 players, each with a variable named {votes.%player%}, and i want to find the name of the player with most votes. I've been trying for around 6 hours, and havent found a solution for this, so hope someone would help. Thanks in advance!
 
I would recommend you to use arrays: {votes::%player%}
Code:
loop {votes::*}:
    if {_best} is not set:
        set {_best} to {votes::%loop-index%}
        set {_bestplayer} to "%loop-index%"
        continue
    if {votes::%loop-index%} > {_best}:
        set {_best} to {votes::%loop-index%}
        set {_bestplayer} to "%loop-index%"
send "%{_bestplayer}% has the most votes."
Should work.
 
  • Like
Reactions: RoosSkywalker
If you do not want to use list variables, you can loop all players, then check if each player's votes are over eachothers. This would be extremely complicated of course, so I'd rather you use arrays instead.

I'm extremely confused by this as well, but I hope this works.

Another alternative is setting a variable to the last looped player's variable, but you still must loop all players.

Code:
loop all players:
  if {last} > {highestvotes}:
    set {highestvotes} to loop-player
    set {last} to {votes.%loop-player%}
  else:
    if {last} < {highestvotes}:

Make of this what you want, I did not intend for this to be spoonfeed.
 
Last edited:
If you do not want to use list variables, you can loop all players, then check if each player's votes are over eachothers. This would be extremely complicated of course, so I'd rather you use arrays instead.

I'm extremely confused by this as well, but I hope this works.

Another alternative is setting a variable to the last looped player's variable, but you still must loop all players.

Code:
loop all players:
  if {last} > {highestvotes}:
    set {highestvotes} to loop-player
    set {last} to {votes.%loop-player%}
  else:
    if {last} < {highestvotes}:

Make of this what you want, I did not intend for this to be spoonfeed.
The problem is: if you loop players all the players must be online; if you loop variables there is no such problem. I would just recommend to skip to using arrays.
 
Status
Not open for further replies.