Top Biggest Fish

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

Mattllama987

Active Member
Aug 5, 2018
225
7
18
24
Hello, im trying to make a contest that will show the top 10 biggest fish caught in the contest. I have this here and it works with no errors. But it will show the most recent caught fish size and not the biggest size. Im not sure how to fix the problem thats going on with it. If anyone knows how to fix it, please let me know ASAP.


Thanks!
~Matt

Code:

Code:
command /mf [<text>] [<int>]:
    trigger:
        if player has permission "fishing.help":
            if arg-1 is "help":
                send "&aMore Fish commands."
                send ""
                send "&aUse /mf start <time> to start a contest"
                send "&aUse /mf stop to stop all the contests"
        if player has permission "fishing.stop":
            if arg-1 is "stop":
                set {contest::started} to 0
                send "&8[&bFishing&8] &7You stopped the contest"
                broadcast "&8[&bFishing&8] &7The fishing contest has been stopped!"
                set {contest::started} to false
        if player has permission "fishing.start":
            if arg-1 is "start":
                if arg-2 is set:
                    set {size::fish::*} to 0
                    send "&8[&bFishing&8] &7Starting a contest for %arg-2% seconds"
                    set {contest::counter} to arg-2
                    broadcast "&8[&bFishing&8] &7A fishing contest will be starting in 3..."
                    wait 1 seconds
                    broadcast "&8[&bFishing&8] &7A fishing contest will be starting in 2.."
                    wait 1 seconds
                    broadcast "&8[&bFishing&8] &7A fishing contest will be starting in 1."
                    wait 1 seconds
                    set {contest::started} to true
                    broadcast "&8[&bFishing&8] &7A fishing contest has started. Come to /spawn to participate"
                    wait "%{contest::counter}% seconds" parsed as time span
                    broadcast "&8[&bFishing&8] &7The contest has ended!"
                    set {contest::counter} to 0
                    set {contest::started} to false
                    make player execute command "/contestcaughtfishtop"
                    wait 1 seconds
                    set {contest::cought::*} to 0
                    set {size::fish::*} to 0
                else:
                    send "&7You must have a time set also. Use /mf start <time>"
on fishing:
    if player is in world "spawn":
        if fish state is CAUGHT_FISH:
            if {contest::started} is true:
                clear caught item
                add 1 to {contest::cought::%player%}
                set {fish::ran} to random integer between 1 and 1
                set {_var} to random number between 1 and 32.99
                if {_var} > ({size::fish::%player%} ? 0):
                    set {size::fish::%player%} to {_var}
                    set {size::fish::%player%} to random number between 1 and 32.99
                    if {fish::ran} = 1:
                        set {cod::%player%} to 1
                        if {size::fish::%player%} is less than 30:
                            give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{size::fish::%player%}%cm" and "&b* &7Common"
                            send "&8[&bFishing&8] &7You cought a &7Common &asnapper"
                    if {size::fish1} is more than 29:
                        send "&8[&bFishing&8] &7You cought a &dRare &asnapper"
                        give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{size::fish::%player%}%" and "&b* &dRare"
                        broadcast "&8[&bFishing&8] &7%player% cought a &dRare &aSnapper thats %{size::fish::%player%}%cm!"

function pigeonhole(indices: objects, values: numbers, ascending: boolean = false) :: objects:

  loop {_indices::*}:
    set {_v} to "%(loop-index parsed as integer)th element out of {_values::*}%"
    set {_split::*} to {_v} split at "."
    add length of {_split::2} ? 0 to {_p::*}
    add loop-value to {_temp::%{_v}%::*}
    
  set {_prec} to 10^(max({_p::*})+1)

  loop all integers from min({_values::*})*{_prec} to (max({_values::*})+1)*{_prec}:
    set {_v} to loop-value / {_prec}
    if {_temp::%{_v}%::*} is set:
      loop {_temp::%{_v}%::*}:
        add loop-value-2 to {_sorted::*}

    
  return ({_sorted::*}) if {_ascending} is true, otherwise (reversed {_sorted::*})
command /contestcaughtfishtop:
  trigger:
    set {_indices::*} to indices of {size::fish::*}
    set {_sorted-fish::*} to pigeonhole({_indices::*}, {size::fish::*})
    set {_topfisher} to first element out of {_sorted-fish::*}
    send "top fish man: %{_topfisher}% with %{size::fish::%{_topfisher}%}%cm"
 
What isn't working? Is it that the player's max fish keeps getting updated?

Code:
set {_var} to random number between 1 and 32.99
if {_var} > ({size::fish::%player%} ? 0):
                    set {size::fish::%player%} to {_var}
                    set {size::fish::%player%} to random number between 1 and 32.99

Also, did you mean to set {size::fish::%player%} to a random number after setting it to {_var}?
 
What isn't working? Is it that the player's max fish keeps getting updated?

Code:
set {_var} to random number between 1 and 32.99
if {_var} > ({size::fish::%player%} ? 0):
                    set {size::fish::%player%} to {_var}
                    set {size::fish::%player%} to random number between 1 and 32.99

Also, did you mean to set {size::fish::%player%} to a random number after setting it to {_var}?
Thank you for replying. But the problem is, when a player catches a fish lets say 4.32cm, and after they catch another thats 7.93cm, and catch 1 more fish thats 3.64, it will show the 3.64 fish instead of the 7.93 fish. But for the {size::fish::%player%} to a random number after setting it to {_var} i will have to fix that.
 
Try to remove "set {size::fish::%player%} to random number between 1 and 32.99."

After I removed it, the script seems to work fine.

Explanation:

You are overwriting the variable with a new random which could be smaller that the original value.
 
That seamed to have fixed that part. But what im needing it to do, is when a player catches a fish thats 4.23cm, and another thats 3.56, it will send the 4.23cm one in the top biggest fish message. Right now its only catching the fish if its bigger than the last one. I need it to pick a random fish with a random cm and it send the biggest fish that the player caught :emoji_slight_smile:
 
That should be an easy fix. Currently, you are only giving a fish to the player if the fish is the largest seen.
Instead:
  1. Give the player a fish based on {_var} and not the max seen
  2. Update max if necessary
 
I think i did it correctly, but its still giving a higher fish than a random one.

Code:
on fishing:
    if player is in world "spawn":
        if fish state is CAUGHT_FISH:
            if {contest::started} is true:
                clear caught item
                add 1 to {contest::cought::%player%}
                set {fish::ran} to random integer between 1 and 1
                set {_var} to random number between 1 and 32.99
                if {_var} > ({size::fish::%player%} ? 0):
                    set {size::fish::%player%} to {_var}
                    if {fish::ran} = 1:
                        set {cod::%player%} to 1
                        if {_var} is less than 30:
                            give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Common"
                            send "&8[&bFishing&8] &7You cought a &7Common &asnapper"
                    if {size::fish1} is more than 29:
                        send "&8[&bFishing&8] &7You cought a &dRare &asnapper"
                        give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%" and "&b* &dRare"
                        broadcast "&8[&bFishing&8] &7%player% cought a &dRare &aSnapper thats %{_var}%cm!"
 
Very close! The is bigger check needs to be on a different indentation level
Code:
on fishing:
    if player is in world "spawn":
        if fish state is CAUGHT_FISH:
            # Constest is on going
            if {contest::started} is true:
                clear caught item
                add 1 to {contest::cought::%player%}
                set {fish::ran} to random integer between 1 and 1
                set {_var} to random number between 1 and 32.99
                # fish run away?
                if {fish::ran} is 1:
                    set {cod::%player%} to 1 # init player?
                    if {_var} is less than 30:
                        give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Common"
                        send "&8[&bFishing&8] &7You cought a &7Common &asnapper"
                    # I changed this statement, note this will trigger even if the player has a bigger fish
                    else:
                        send "&8[&bFishing&8] &7You cought a &dRare &asnapper"
                        give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%" and "&b* &dRare"
                        broadcast "&8[&bFishing&8] &7%player% cought a &dRare &aSnapper thats %{_var}%cm!"
                    # Update after giving a player a fish
                    if {_var} > ({size::fish::%player%} ? 0):
                        set {size::fish::%player%} to {_var}

EDIT: I didn't mean to send that yet! It is untested
 
Works like a charm! Thank you very much for your time and help! Have a wonderful day! :emoji_smile:
 
Status
Not open for further replies.