Solved BalTop re-write

  • 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,248
241
73
Vancouver, Canada
Category:
Economy
Suggested name: none

What I want:
I have my SkEco skript, and in it, I have a /baltop command, which runs the top balances of players. (The baltop function was written by someone else) Now my problem is, there is ONE line in the function that requires TuSke.... and I do not want to have to depend on TuSke for ONE line. If someone could please help me re-write that part that would NOT require Tuske I would greatly appreciate it. Currently the skript depends on SkQuery (For checking skript version info from pastebin - Will be changing to reqn in my next update) as well as Vault/SkVault. I would prefer to not have to add anymore addons. I want to keep this simple, with the least amount of add-ons as possible. Thanks

Ideas for commands:
none required
Ideas for permissions:
none required
When I'd like it by: Soon would be nice

Here is the function (and the command, just so you can see how the function is run)
Line 16 is the one I want re-written
code_language.skript:
function baltop(p: sender, page: Number):
  loop {eco::balance::*}:
    set {_loop::%loop-index%} to loop-index
  set {_playersSorted::*} to sortHighestToLowest({_loop::*}, {eco::balance::*})
  set {_maxPage} to rounded up (size of {_playersSorted::*}/10)
  if {_maxPage} is less than 1:
    set {_maxPag} to 1
  if {_page} is greater than {_maxPage}:
    send "{@prefix} &cThat is not a valid page!" to {_p}
    stop
  if {_page} is less than 1:
    send "{@prefix} &cThat is not a valid page!" to {_p}
    stop
  set {_pos} to 1
  add (({_page}-1) * 10) to {_pos}
  set {_objects::*} to page {_page} of {_playersSorted::*} with 10 lines #<----- THIS LINE
  if {_objects::*} is set:
    send "" to {_p}
    send "{@prefix} - &l&nTop Balances" to {_p}
    send "" to {_p}
    loop {_objects::*}:
      set {_name} to loop-value parsed as offlineplayer
      set {_bal} to regex({eco::balance::%loop-value%})
      send "&b##%{_pos}% &b%{_name}% &8&l» &f$%{_bal}%" to {_p}
      add 1 to {_pos}
    send "" to {_p}
    send "&7&o(( You are on page %{_page}% / %{_maxPage}% ))" to {_p}
 
  else:
    send "{@prefix} &cThat is not a valid page!" to {_p}

command /baltop [<number=1>]:
    aliases: /balancetop
    trigger:
        if sender has permission "eco.baltop":     
            baltop(sender, arg-1)
 
code_language.skript:
function baltop(p: sender, page: Number):
    loop {eco::balance::*}:
        set {_loop::%loop-index%} to loop-index
    set {_playersSorted::*} to sortHighestToLowest({_loop::*}, {eco::balance::*})

    set {_maxPage} to 1 if size of {_playersSorted::*} is 0 else rounded up (size of {_playersSorted::*}/10)
    if {_page} is greater than {_maxPage}:
        send "{@prefix} &cThat is not a valid page!" to {_p}
    else if {_page} is less than 1:
        send "{@prefix} &cThat is not a valid page!" to {_p}
    else:
        send "" to {_p}
        send "{@prefix} - &l&nTop Balances" to {_p}
        send "" to {_p}

        set {_calcPage} to {_page} - 1
        set {_i} to 0
        set {_pos} to 1
        loop {_playersSorted::*}:
            if {_i} is between {_calcPage} * 10 and (({_calcPage} + 1) * 10) - 1:
                set {_name} to loop-index
                set {_bal} to regex(loop-value)
                send "&b##%{_pos}% &b%{_name}% &8&l» &f$%{_bal}%" to {_p}
                add 1 to {_pos}
            add 1 to {_i}
        send "&7&o(( You are on page %{_page}% / %{_maxPage}% ))" to {_p}
 
code_language.skript:
function baltop(p: sender, page: Number):
    loop {eco::balance::*}:
        set {_loop::%loop-index%} to loop-index
    set {_playersSorted::*} to sortHighestToLowest({_loop::*}, {eco::balance::*})

    set {_maxPage} to 1 if size of {_playersSorted::*} is 0 else rounded up (size of {_playersSorted::*}/10)
    if {_page} is greater than {_maxPage}:
        send "{@prefix} &cThat is not a valid page!" to {_p}
    else if {_page} is less than 1:
        send "{@prefix} &cThat is not a valid page!" to {_p}
    else:
        send "" to {_p}
        send "{@prefix} - &l&nTop Balances" to {_p}
        send "" to {_p}

        set {_calcPage} to {_page} - 1
        set {_i} to 0
        set {_pos} to 1
        loop {_playersSorted::*}:
            if {_i} is between {_calcPage} * 10 and (({_calcPage} + 1) * 10) - 1:
                set {_name} to loop-index
                set {_bal} to regex(loop-value)
                send "&b##%{_pos}% &b%{_name}% &8&l» &f$%{_bal}%" to {_p}
                add 1 to {_pos}
            add 1 to {_i}
        send "&7&o(( You are on page %{_page}% / %{_maxPage}% ))" to {_p}
This is what happens when I threw that into my skript
v67Crld.png

[doublepost=1532548985,1532548836][/doublepost]oh CRAP... im not sure if this is needed... i guess I should have posted this, but anyways these are the other functions that go along with the skript, sorry
code_language.skript:
function regex(n: object) :: text:
    if "%{_n}%" contains ".":
        set {_s::*} to split "%{_n}%" at "."
        set {_n} to "%a({_s::1})%.%{_s::2}%"
        return "%{_n}%"
    else:
        set {_n} to a("%{_n}%")
        return "%{_n} ? 0%"
function a(b: text) :: text:
    if length of {_b} > 3:
        return "%a(first length of {_b} - 3 characters of {_b})%,%last 3 characters of {_b}%"
    return {_b}

function sortHighestToLowest(indexes: strings, values: objects) :: strings:
    if {eco::indexes::*} is not set:
        set {_size} to size of {_values::*}
        loop {_size} times:
            loop {_size} - 1 times:
                set {_value1} to {_values::%loop-number-2%}
                set {_value2} to {_values::%loop-number-2 + 1%}
                {_value1} is less than {_value2}
                set {_index1} to {_indexes::%loop-number-2%}
                set {_indexes::%loop-number-2%} to {_indexes::%loop-number-2 + 1%}
                set {_values::%loop-number-2%} to {_value2}
                set {_indexes::%loop-number-2 + 1%} to {_index1}
                set {_values::%loop-number-2 + 1%} to {_value1}
            remove 1 from {_size}
        set {eco::indexes::*} to {_indexes::*}
        return {eco::indexes::*}
        wait 5 minute
        delete {eco::indexes::*}
    else:
        return {eco::indexes::*}
 
I set it up assuming the sorted variable was like {_playersSorted::%player%} = 10

I can fix it later