BalTop (Part of Eco Skript)

  • 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!

ShaneBee

Supporter +
Addon Developer
Sep 7, 2017
2,247
241
73
Vancouver, Canada
Category: Skript

Suggested name: No name required, this will be pasted in my eco skript

What I want:
I am working on an economy Skript. I have gotten most of it done, I just need a /baltop command similar to Essentials. I would like it to sort the balances of the players from the HIGHEST to LOWEST... in groups of 10 per page. So if there's more than 10 players, it would show the highest 10 on the first page, and next highest 10 on the next page, and so on.
The variable I am using for economy is
{eco::balance::%uuid of player%}
Ideas for commands:
/baltop (I can change later if need be)
Ideas for permissions:
skeco.baltop
When I'd like it by: Soon would be nice :emoji_slight_smile:

Thank you
-ShaneBee
 
code_language.skript:
options:

  baltop-format: <light red>[position]<yellow>. [balance] <light grey> - <cmd:/baltop [player]>[player] # I suck at coloring so you may change this

  highlight-top: 3 # The position and their balance's color will be changed to them
  highlight-color: <light green>


on skript load:
 
  codeblock {eco::baltop::format}:

    set {_format} to {@baltop-format}
    loop {_top-board::*}:

      add 1 to {_position}
      set {_format} to {@baltop-format}
      set {_name} to "%loop-index parsed as offline player%"

      replace all "[player]" with {_name} in {_format}
      replace all "[position]" with "%{_position}%" in {_format}
      replace all "[balance]" with "%loop-value%" in {_format}
   
      if {_position} is less than or equal to {@highlight-top}:
        set {_format} to "{@highlight-color}%subtext of {_format} from 2 to length of {_format}%"
     
        if first character of format is "§":
          set {_format} to "{@highlight-color}%subtext of {_format} from 2 to length of {_format}%"
        else:
          set {_format} to "{@highlight-color}%{_format}%"
      set {eco-cache::baltop::%loop-index%} to {_format}

  async:
   
    set {_top-board::*} to {eco::balance::*}
    set {_indexes::*} to indexes of {eco::balance::*}
 
    loop size of {_top-board::*} times:
      set {_index} to 1
      loop {_top-board::*}:
        add 1 to {_index}
        set {_next} to {_top-board::%{_indexes::%{_index}%}%}
        loop-value-2 is less than {_next}
        {_index} is less or equal to size of {_top-board::*}
        set {_top-board::%{_indexes::%{_index}%}%} to loop-value-2
        set {_top-board::%loop-index%} to {_next}

        if mod(loop-number, 20) is 0: # it waits one tick per 20 values looped, I'd increase it the bigger the variable is.
          async wait 1 tick
 
    sync:
      run codeblock {eco::baltop::format} here
      set {eco::baltop::last-sort} to now


command /balancetop [<offline player>]:
  usage: /baltop [player]
  description: Shows the users with most balance in the server; the top-list of the given player if provided. The list is updated once a day.
  permission: skeco.baltop
  permission message: <light red>You do not have the permission to use this command.
  aliases: baltop
  trigger:
    if argument isn't set:

      loop {eco-cache::baltop::*}:
        send {_format} to sender

      if {eco::baltop::last-sort} was more than a day ago:
        async:
   
          set {_top-board::*} to {eco::balance::*}
          set {_indexes::*} to indexes of {eco::balance::*}
   
          loop size of {_top-board::*} times:
            set {_index} to 1
          loop {_top-board::*}:
            add 1 to {_index}
            set {_next} to {_top-board::%{_indexes::%{_index}%}%}
            loop-value-2 is less than {_next}
            {_index} is less or equal to size of {_top-board::*}
            set {_top-board::%{_indexes::%{_index}%}%} to loop-value-2
            set {_top-board::%loop-index%} to {_next}

            if mod(loop-number, 20) is 0: # it waits one tick per 20 values looped, I'd increase it the bigger the variable is.
              async wait 1 tick
       
        sync:
          run codeblock {eco::baltop::format} here
          set {eco::baltop::last-sort} to now

    else:
     
      if argument hasn't played before in the server:
        send "<yellow>Couldn't find the player in the database!"
        stop

      set {_uuid} to uuid of argument
      if {eco-cache::baltop::%{_uuid}%} isn't set:
        send "<yellow>Couldn't find the player in the database!"
        stop


      set {_format} to {@baltop-format}
      set {_position-index} to first index of "[position]" in {_format}
      set {_position} to subtext of {eco-cache::baltop::%{_uuid}%} from {_position-index} to {_position-index} + 1
      send "<light green>%argument% Top Info" and ""
      send "<yellow>Position<grey>: <light grey>%{_position}%"
      send "<light green>Balance<grey>: <light grey>%{eco::balance::%{_uuid}%}%"
Needs MundoSK, not sure if it works but it is worth a try.

EDIT: Forgot the argument logic, going to do it after work. Gotta go.

EDIT #2: There we go, not sure if it works.
 
Last edited:
sorry for the late reply,

I downloaded MundoSk.... threw this all into a test skript, and this was the error I got

code_language.skript:
[14:07:33 INFO]: [Skript] Reloading baltop.sk...
[14:07:33 ERROR]: ':/baltop [player]>[player]' is not a valid item data (baltop.sk, line 13: set {_format} to {@baltop-format}')
[14:07:33 ERROR]: ':/baltop [player]>[player]' is not a valid item data (baltop.sk, line 17: set {_format} to {@baltop-format}')
[14:07:33 ERROR]: Can't compare 'first character of format' with a text (baltop.sk, line 27: if first character of format is "§":')
[14:07:33 ERROR]: 'else' has to be placed just after an 'if' or 'else if' section (baltop.sk, line 29: else:')
[14:07:33 ERROR]: Functions cannot be used here (or there is a problem with your arguments). (baltop.sk, line 84: if mod(loop-number, 20) is 0:# it waits one tick per 20 values looped, I'd increase it the bigger the variable is.')
[14:07:33 ERROR]: can't understand this condition: 'argument hasn't played before in the server' (baltop.sk, line 93: if argument hasn't played before in the server:')
[14:07:33 ERROR]: ':/baltop [player]>[player]' is not a valid item data (baltop.sk, line 103: set {_format} to {@baltop-format}')
[14:07:33 INFO]: [Skript] Encountered 7 errors while reloading baltop.sk!