1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Top Biggest Fish

Discussion in 'Skript' started by Mattllama987, Dec 4, 2019.

  1. Mattllama987

    Mattllama987 Well-Known Member

    Joined:
    Aug 5, 2018
    Messages:
    61
    Likes Received:
    0
    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 (Text):
    1. command /mf [<text>] [<int>]:
    2.     trigger:
    3.         if player has permission "fishing.help":
    4.             if arg-1 is "help":
    5.                 send "&aMore Fish commands."
    6.                 send ""
    7.                 send "&aUse /mf start <time> to start a contest"
    8.                 send "&aUse /mf stop to stop all the contests"
    9.         if player has permission "fishing.stop":
    10.             if arg-1 is "stop":
    11.                 set {contest::started} to 0
    12.                 send "&8[&bFishing&8] &7You stopped the contest"
    13.                 broadcast "&8[&bFishing&8] &7The fishing contest has been stopped!"
    14.                 set {contest::started} to false
    15.         if player has permission "fishing.start":
    16.             if arg-1 is "start":
    17.                 if arg-2 is set:
    18.                     set {size::fish::*} to 0
    19.                     send "&8[&bFishing&8] &7Starting a contest for %arg-2% seconds"
    20.                     set {contest::counter} to arg-2
    21.                     broadcast "&8[&bFishing&8] &7A fishing contest will be starting in 3..."
    22.                     wait 1 seconds
    23.                     broadcast "&8[&bFishing&8] &7A fishing contest will be starting in 2.."
    24.                     wait 1 seconds
    25.                     broadcast "&8[&bFishing&8] &7A fishing contest will be starting in 1."
    26.                     wait 1 seconds
    27.                     set {contest::started} to true
    28.                     broadcast "&8[&bFishing&8] &7A fishing contest has started. Come to /spawn to participate"
    29.                     wait "%{contest::counter}% seconds" parsed as time span
    30.                     broadcast "&8[&bFishing&8] &7The contest has ended!"
    31.                     set {contest::counter} to 0
    32.                     set {contest::started} to false
    33.                     make player execute command "/contestcaughtfishtop"
    34.                     wait 1 seconds
    35.                     set {contest::cought::*} to 0
    36.                     set {size::fish::*} to 0
    37.                 else:
    38.                     send "&7You must have a time set also. Use /mf start <time>"
    39. on fishing:
    40.     if player is in world "spawn":
    41.         if fish state is CAUGHT_FISH:
    42.             if {contest::started} is true:
    43.                 clear caught item
    44.                 add 1 to {contest::cought::%player%}
    45.                 set {fish::ran} to random integer between 1 and 1
    46.                 set {_var} to random number between 1 and 32.99
    47.                 if {_var} > ({size::fish::%player%} ? 0):
    48.                     set {size::fish::%player%} to {_var}
    49.                     set {size::fish::%player%} to random number between 1 and 32.99
    50.                     if {fish::ran} = 1:
    51.                         set {cod::%player%} to 1
    52.                         if {size::fish::%player%} is less than 30:
    53.                             give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{size::fish::%player%}%cm" and "&b* &7Common"
    54.                             send "&8[&bFishing&8] &7You cought a &7Common &asnapper"
    55.                     if {size::fish1} is more than 29:
    56.                         send "&8[&bFishing&8] &7You cought a &dRare &asnapper"
    57.                         give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{size::fish::%player%}%" and "&b* &dRare"
    58.                         broadcast "&8[&bFishing&8] &7%player% cought a &dRare &aSnapper thats %{size::fish::%player%}%cm!"
    59.  
    60. function pigeonhole(indices: objects, values: numbers, ascending: boolean = false) :: objects:
    61.  
    62.   loop {_indices::*}:
    63.     set {_v} to "%(loop-index parsed as integer)th element out of {_values::*}%"
    64.     set {_split::*} to {_v} split at "."
    65.     add length of {_split::2} ? 0 to {_p::*}
    66.     add loop-value to {_temp::%{_v}%::*}
    67.    
    68.   set {_prec} to 10^(max({_p::*})+1)
    69.  
    70.   loop all integers from min({_values::*})*{_prec} to (max({_values::*})+1)*{_prec}:
    71.     set {_v} to loop-value / {_prec}
    72.     if {_temp::%{_v}%::*} is set:
    73.       loop {_temp::%{_v}%::*}:
    74.         add loop-value-2 to {_sorted::*}
    75.  
    76.    
    77.   return ({_sorted::*}) if {_ascending} is true, otherwise (reversed {_sorted::*})
    78. command /contestcaughtfishtop:
    79.   trigger:
    80.     set {_indices::*} to indices of {size::fish::*}
    81.     set {_sorted-fish::*} to pigeonhole({_indices::*}, {size::fish::*})
    82.     set {_topfisher} to first element out of {_sorted-fish::*}
    83.     send "top fish man: %{_topfisher}% with %{size::fish::%{_topfisher}%}%cm"
     
  2. Policiu

    Policiu Member

    Joined:
    Jan 28, 2017
    Messages:
    10
    Likes Received:
    0
    What isn't working? Is it that the player's max fish keeps getting updated?

    Code (Text):
    1.  
    2. set {_var} to random number between 1 and 32.99
    3. if {_var} > ({size::fish::%player%} ? 0):
    4.                     set {size::fish::%player%} to {_var}
    5.                     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}?
     
  3. Mattllama987

    Mattllama987 Well-Known Member

    Joined:
    Aug 5, 2018
    Messages:
    61
    Likes Received:
    0
    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.
     
  4. Policiu

    Policiu Member

    Joined:
    Jan 28, 2017
    Messages:
    10
    Likes Received:
    0
    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.
     
  5. Mattllama987

    Mattllama987 Well-Known Member

    Joined:
    Aug 5, 2018
    Messages:
    61
    Likes Received:
    0
    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:
     
  6. Policiu

    Policiu Member

    Joined:
    Jan 28, 2017
    Messages:
    10
    Likes Received:
    0
    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
     
  7. Mattllama987

    Mattllama987 Well-Known Member

    Joined:
    Aug 5, 2018
    Messages:
    61
    Likes Received:
    0
    I think i did it correctly, but its still giving a higher fish than a random one.

    Code (Text):
    1. on fishing:
    2.     if player is in world "spawn":
    3.         if fish state is CAUGHT_FISH:
    4.             if {contest::started} is true:
    5.                 clear caught item
    6.                 add 1 to {contest::cought::%player%}
    7.                 set {fish::ran} to random integer between 1 and 1
    8.                 set {_var} to random number between 1 and 32.99
    9.                 if {_var} > ({size::fish::%player%} ? 0):
    10.                     set {size::fish::%player%} to {_var}
    11.                     if {fish::ran} = 1:
    12.                         set {cod::%player%} to 1
    13.                         if {_var} is less than 30:
    14.                             give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Common"
    15.                             send "&8[&bFishing&8] &7You cought a &7Common &asnapper"
    16.                     if {size::fish1} is more than 29:
    17.                         send "&8[&bFishing&8] &7You cought a &dRare &asnapper"
    18.                         give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%" and "&b* &dRare"
    19.                         broadcast "&8[&bFishing&8] &7%player% cought a &dRare &aSnapper thats %{_var}%cm!"
     
  8. Policiu

    Policiu Member

    Joined:
    Jan 28, 2017
    Messages:
    10
    Likes Received:
    0
    Very close! The is bigger check needs to be on a different indentation level
    Code (Text):
    1.  
    2. on fishing:
    3.     if player is in world "spawn":
    4.         if fish state is CAUGHT_FISH:
    5.             # Constest is on going
    6.             if {contest::started} is true:
    7.                 clear caught item
    8.                 add 1 to {contest::cought::%player%}
    9.                 set {fish::ran} to random integer between 1 and 1
    10.                 set {_var} to random number between 1 and 32.99
    11.                 # fish run away?
    12.                 if {fish::ran} is 1:
    13.                     set {cod::%player%} to 1 # init player?
    14.                     if {_var} is less than 30:
    15.                         give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Common"
    16.                         send "&8[&bFishing&8] &7You cought a &7Common &asnapper"
    17.                     # I changed this statement, note this will trigger even if the player has a bigger fish
    18.                     else:
    19.                         send "&8[&bFishing&8] &7You cought a &dRare &asnapper"
    20.                         give player a cod named "&b%player%'s fish" with lore "&8* &aSize: %{_var}%" and "&b* &dRare"
    21.                         broadcast "&8[&bFishing&8] &7%player% cought a &dRare &aSnapper thats %{_var}%cm!"
    22.                     # Update after giving a player a fish
    23.                     if {_var} > ({size::fish::%player%} ? 0):
    24.                         set {size::fish::%player%} to {_var}
    25.  
    EDIT: I didn't mean to send that yet! It is untested
     
  9. Mattllama987

    Mattllama987 Well-Known Member

    Joined:
    Aug 5, 2018
    Messages:
    61
    Likes Received:
    0
    Works like a charm! Thank you very much for your time and help! Have a wonderful day! :emoji_smile:
     
Loading...