How do I use functions instead of "else if"

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

cooldma

Member
May 14, 2022
2
0
1
33
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:
function checkChance(chance: number, number: number) :: boolean:
  return true if {_chance} <= {_number} else false

My code:
Code:
on script load:
    set {-coin} to sunflower of unbreaking 10 named "&6&lCoin"
    
on death:
    if attacker is a player:
        if victim is a wither skeleton:
            clear drops
            set {-chance} to a random integer between 1 and 100
            if {-chance} is less than or equal to 60:
                drop 1 netherite block at victim
                send "&7You got 1 netherite block" to attacker
            else if {-chance} <= 89:
                drop 3 of {-coin} at victim
                send "&6You got 3 coins" to attacker
            else if {-chance} <= 95:
                drop 8 of {-coin} at victim
                send "&6You got 8 coins" to attacker
            else if {-chance} <= 99:
                drop 10 of {-coin} at victim
                send "&6You got 10 coins" to attacker
            else if {-chance} <= 100:
                drop 32 of {-coin} at victim
                send "&6&lJackPot! (32 coins)" to attacker

If anyone could help it would be greatly appreciated.
 
Status
Not open for further replies.