Jump to content

Need help with sorting a list... within a list


FlapKakker
 Share

Recommended Posts

Hello there!

Glad you stumbled upon this post hehe! I'm currently trying to make a leaderboard for my players. It should sort the players based on their prestige and within that list, sorted based on their level. I'm already able to sort based on one list, but I can't figure out how to sort the levels inside the sorted prestige list! You can find my code snippet to sort based on levels down below. Thanks in advance if you can help me out!


Example of what i need: (i know it should be uuid, but havent had time to change all my files yet 😞 ) (dont mind the layout)

- Prestige top:

#1 Verwarmingman: P:15 Lvl:54
#2 ezezez: P:10 Lvl:89
#3 Notch: P:3 Lvl:11
#4 ElPepe: P:1 Lvl:30
#5 ggfds: P:0 Lvl:5

Example of what I currently have:

- Level top:

#1 ezezez:  Lvl:89
#2 Verwarmingman: Lvl:54
#3 ElPepe: Lvl:30
#4 Notch: Lvl:11
#5 ggfds: Lvl:5

 

#levels
	loop {level::*}:
		add 1 to {_size2}
		if {_low.to.high.list.levels::%loop-value%} is not set:
			set {_low.to.high.list.levels::%loop-value%} to loop-index
		else:
			set {_n2} to 0
			loop {_size2} times:
				set {_n2} to {_n2}+1
				{_low.to.high.list.levels::%loop-value-1%.%{_n2}%} is not set
				set {_low.to.high.list.levels::%loop-value-1%.%{_n2}%} to loop-index
				stop loop
	wait 1 tick
	set {_n2} to size of {_low.to.high.list.levels::*}
	loop {_low.to.high.list.levels::*}:
		set {_high.to.low.list.levels::%{_n2}%} to loop-value
		set {_n2} to {_n2}-1
	wait 1 tick

 

Link to comment
Share on other sites

https://skripthub.net/docs/?id=3542
https://skripthub.net/docs/?id=3544
https://skripthub.net/docs/?id=2158

function sort(indices: strings, values: numbers, descending: boolean = true) :: strings:
    loop {_indices::*}:
        set {_sort::%{_values::%loop-index%}%.%loop-index%} to loop-value
    return (reversed {_sort::*}) if {_descending} is true, else {_sort::*}

Hi! You can use what I have linked above to accomplish this. This requires skript-holo and thats all (pretty sure, its late and im not thinking.)

Developer

 

Joined Minecraft in 2014 on PC

Joined Minehut in August 2016

12 months Skript experience

1 month Java experience

5 months Javascript experience

 

Link to comment
Share on other sites

On 8/31/2021 at 10:55 PM, itsKimo said:

u should probably count the persons levels in a total variable like {totallevel.%player's uuid%} because if ur making a leaderboard for levels ppl lose levels on rebirth im assuming

indeed ieuw nested vars haha, and thanks for the reply! They indeed reset upon prestiging, but still counting the total doesnt enable me to sort within the sorted prestige list :s

 

Link to comment
Share on other sites

For anyone still looking for the solution, I dont know if anyone even is lol, you can find it down below 🙂

#levels
	loop {prestige::*}:
		add 1 to {_size2}
		if {_low.to.high.list.levels::%loop-value%} is not set:
			set {_low.to.high.list.levels::%loop-value%} to loop-index
		else:
			set {_n2} to 0
			loop {_size2} times:
				set {_n2} to {_n2}+1
				{_low.to.high.list.levels::%loop-value-1%.%{_n2}%} is not set
				set {_low.to.high.list.levels::%loop-value-1%.%{_n2}%} to loop-index
				stop loop
	wait 1 tick
	set {_n2} to size of {_low.to.high.list.levels::*}
	loop {_low.to.high.list.levels::*}:
		set {_high.to.low.list.levels::%{_n2}%} to loop-value
		set {_n2} to {_n2}-1
	wait 1 tick

	#loop second time
	loop {_high.to.low.list.levels::*}:
		add 1 to {_size4}
		set {_player} to "%loop-value%" parsed as offline player
		set {_level} to {level::%{_player}%}
		set {_prestige} to {prestige::%{_player}%}
		if {_low.to.high.list.levels2::%{_prestige}%.%{_level}%} is not set:
			set {_low.to.high.list.levels2::%{_prestige}%.%{_level}%} to loop-value
			#broadcast "no %{_low.to.high.list.levels2::%{_prestige}%.%{_level}%}%"
			#broadcast "%{_level}%"
		else:
			set {_n4} to 0
			loop {_size4} times:
				set {_n4} to {_n4}+1
				{_low.to.high.list.levels2::%{_prestige}%.%{_level}%.%{_n4}%} is not set
				set {_low.to.high.list.levels2::%{_prestige}%.%{_level}%.%{_n4}%} to loop-value-1
				#broadcast "yes %{_low.to.high.list.levels2.%{_prestige}%.%{_level}%.%{_n4}%}%"
				#broadcast "%{_level}%"
				stop loop
	wait 1 tick
	set {_n5} to size of {_low.to.high.list.levels2::*}
	loop {_low.to.high.list.levels2::*}:
		set {high.to.low.list.levels2::%{_n5}%} to loop-value
		set {_n5} to {_n5}-1
	wait 1 tick
	#message
	set {_topnumber} to 0
	set {_ind2} to 0
	loop {high.to.low.list.levels2::*}:
		#broadcast "%{_high.to.low.list.levels2::%loop-index%}% eeee"
		add 1 to {_ind2}
		if {_ind2} < 6:
			add 1 to {_topnumber}
			set {_player} to "%loop-value%" parsed as offlineplayer
			#broadcast "%{_player}% player"
			make console execute command "/holo setline leveltop %{_ind2} + 2% &d##%{_topnumber}% &f%{_player}% &f- &fP:%{prestige::%loop-value%}%&f Lvl. %{level::%loop-value%}%"
			#broadcast "%{_ind2}% %{_ind2} + 2%"
		else:
			make console execute command "/holo reload leveltop"
			stop loop

+ keep in mind that you CANNOT/SHOULDNT run this every second or on a command! When many people join your server, the list variables will be huge and looping over them will take considerable resources. You should make a timed event (e.g.: 30 minutes) and announce in chat that lagg may occur whilst loading the new leaderboards

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share



×
×
  • Create New...