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

How do I use functions instead of "else if"

Discussion in 'Skript' started by cooldma, May 14, 2022.

Thread Status:
Not open for further replies.
  1. cooldma

    cooldma Member

    Joined:
    May 14, 2022
    Messages:
    2
    Likes Received:
    0
    I am trying to make a system of rewards for killing wither skeletons and it makes the server lag due to the "else if"s, I want to use functions and someone told me to use:
    Code (Text):
    1. function checkChance(chance: number, number: number) :: boolean:
    2.   return true if {_chance} <= {_number} else false
    My code:
    Code (Text):
    1. on script load:
    2.     set {-coin} to sunflower of unbreaking 10 named "&6&lCoin"
    3.    
    4. on death:
    5.     if attacker is a player:
    6.         if victim is a wither skeleton:
    7.             clear drops
    8.             set {-chance} to a random integer between 1 and 100
    9.             if {-chance} is less than or equal to 60:
    10.                 drop 1 netherite block at victim
    11.                 send "&7You got 1 netherite block" to attacker
    12.             else if {-chance} <= 89:
    13.                 drop 3 of {-coin} at victim
    14.                 send "&6You got 3 coins" to attacker
    15.             else if {-chance} <= 95:
    16.                 drop 8 of {-coin} at victim
    17.                 send "&6You got 8 coins" to attacker
    18.             else if {-chance} <= 99:
    19.                 drop 10 of {-coin} at victim
    20.                 send "&6You got 10 coins" to attacker
    21.             else if {-chance} <= 100:
    22.                 drop 32 of {-coin} at victim
    23.                 send "&6&lJackPot! (32 coins)" to attacker
    If anyone could help it would be greatly appreciated.
     
  2. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    I'm 100% sure that this isn't making your server lagging. And use local variables
     
  3. cooldma

    cooldma Member

    Joined:
    May 14, 2022
    Messages:
    2
    Likes Received:
    0
    Would it work on a non minehut server that would get 50+ player?
     
Thread Status:
Not open for further replies.

Share This Page

Loading...