Solved How to make level skript

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


Code:
variables:
    {number} = 1
    {blocks.%player%} = 0
    {level.%player%} = 0
    
        
every second in world "world":
    loop all players:
        if {blocks.%loop-player%} is 15:
            add 1 to {level.%loop-player%}
            send "&e&lLEVEL UP&f: Congratulations &c%loop-player%&f you are now level 1&c!" to loop-player
            play sound "entity.entity.player.levelup" with volume 1 to loop-player

on mine:
    if event-block is coal ore:
        if player's gamemode is creative:
            send "&fCoal ore broken successfully&c!"
            stop
        else:
            cancel event
            set {_int} to random integer between 1 and 5
            set {_item} to "%{_int}% coal" parsed as item
            give {_item} to player
            send "&a+%{_int}% &8Coal ore"
            add 1 to {blocks.%player%}
            play sound "entity.experience_orb.pickup" with volume 0.5 to the player
            stop
    if event-block is iron ore:
        if player's gamemode is creative:
            send "&fIron ore broken successfully&c!"
            stop
        else:
            cancel event
            set {_int} to random integer between 1 and 3
            set {_item} to "%{_int}% iron ingot" parsed as item
            give {_item} to player
            send "&a+%{_int}% &7Iron ingot"
            add 1 to {blocks.%player%}
            play sound "entity.experience_orb.pickup" with volume 0.5 to the player
            stop
    if event-block is Cobblestone:
        if player's gamemode is creative:
            send "&fCobblestone broken successfully&c!"
            stop
        else:
            cancel event
            set {_int} to random integer between 1 and 10
            set {_item} to "%{_int}% cobblestone" parsed as item
            give {_item} to player
            send "&a+%{_int}% &7Cobblestone"
            add 1 to {blocks.%player%}
            play sound "entity.experience_orb.pickup" with volume 0.5 to the player
            stop

This above worked for me :emoji_slight_smile:
Hope it works for you too.

It's because you need to loop all players to get a player, and then you need to change player to loop-player.
And also you don't need to make a on mine: for each block you can do it in one, like above. :emoji_slight_smile:
 
jSG1JJP.png


Code:
variables:
    {number} = 1
    {blocks.%player%} = 0
    {level.%player%} = 0
  
      
every second in world "world":
    loop all players:
        if {blocks.%loop-player%} is 15:
            add 1 to {level.%loop-player%}
            send "&e&lLEVEL UP&f: Congratulations &c%loop-player%&f you are now level 1&c!" to loop-player
            play sound "entity.entity.player.levelup" with volume 1 to loop-player

on mine:
    if event-block is coal ore:
        if player's gamemode is creative:
            send "&fCoal ore broken successfully&c!"
            stop
        else:
            cancel event
            set {_int} to random integer between 1 and 5
            set {_item} to "%{_int}% coal" parsed as item
            give {_item} to player
            send "&a+%{_int}% &8Coal ore"
            add 1 to {blocks.%player%}
            play sound "entity.experience_orb.pickup" with volume 0.5 to the player
            stop
    if event-block is iron ore:
        if player's gamemode is creative:
            send "&fIron ore broken successfully&c!"
            stop
        else:
            cancel event
            set {_int} to random integer between 1 and 3
            set {_item} to "%{_int}% iron ingot" parsed as item
            give {_item} to player
            send "&a+%{_int}% &7Iron ingot"
            add 1 to {blocks.%player%}
            play sound "entity.experience_orb.pickup" with volume 0.5 to the player
            stop
    if event-block is Cobblestone:
        if player's gamemode is creative:
            send "&fCobblestone broken successfully&c!"
            stop
        else:
            cancel event
            set {_int} to random integer between 1 and 10
            set {_item} to "%{_int}% cobblestone" parsed as item
            give {_item} to player
            send "&a+%{_int}% &7Cobblestone"
            add 1 to {blocks.%player%}
            play sound "entity.experience_orb.pickup" with volume 0.5 to the player
            stop

This above worked for me :emoji_slight_smile:
Hope it works for you too.

It's because you need to loop all players to get a player, and then you need to change player to loop-player.
And also you don't need to make a on mine: for each block you can do it in one, like above. :emoji_slight_smile:
Don't use a periodical for checking to see if a player leveled up. Just make a formula or write down vars for the amount each level and then use a function to check. This way is much more efficient. Untested code:
code_language.skript:
on join:
    set {exp::%uuid of player%} to 0
    set {level::%uuid of player%} to 1

# Example exponential formula (goes up 15% per level)
function checkForLevelUp(p: player):
    set {_uuid} to uuid of {_p}
    if {exp::%{_uuid}%} >= round(87(1.15)^{level::%{_uuid}%}):
        set {exp::%{_uuid}%} to {exp::%{_uuid}%} - round(87(1.15)^{level::%{_uuid}%}) # catches over xp
        add 1 to {level::%{_uuid}%}
        send "&aYou are now level %{level::%{_uuid}%}%!" to {_p}

on mine:
    if event-block is iron ore:
        add 5 to {exp::%uuid of player%}
        checkForLevelUp(player)


# OR YOU CAN DO SOMETHING LIKE:

on script load:
    set {level::1} to 150
    set {level::2} to 300

# Example exponential formula (goes up 15% per level)
function checkForLevelUp(p: player):
    set {_uuid} to uuid of player
    if {exp::%{_uuid}%} >= {level::%{level::%{_uuid}%}%}:
        set {exp::%{_uuid}%} to {exp::%{_uuid}%} - {level::%{level::%{_uuid}%}%} # catches over xp
        add 1 to {level::%{_uuid}%}
        send "&aYou are now level %{level::%{_uuid}%}%!" to {_p}
 
Don't use a periodical for checking to see if a player leveled up. Just make a formula or write down vars for the amount each level and then use a function to check. This way is much more efficient. Untested code:
code_language.skript:
on join:
    set {exp::%uuid of player%} to 0
    set {level::%uuid of player%} to 1

# Example exponential formula (goes up 15% per level)
function checkForLevelUp(p: player):
    set {_uuid} to uuid of {_p}
    if {exp::%{_uuid}%} >= round(87(1.15)^{level::%{_uuid}%}):
        set {exp::%{_uuid}%} to {exp::%{_uuid}%} - round(87(1.15)^{level::%{_uuid}%}) # catches over xp
        add 1 to {level::%{_uuid}%}
        send "&aYou are now level %{level::%{_uuid}%}%!" to {_p}

on mine:
    if event-block is iron ore:
        add 5 to {exp::%uuid of player%}
        checkForLevelUp(player)


# OR YOU CAN DO SOMETHING LIKE:

on script load:
    set {level::1} to 150
    set {level::2} to 300

# Example exponential formula (goes up 15% per level)
function checkForLevelUp(p: player):
    set {_uuid} to uuid of player
    if {exp::%{_uuid}%} >= {level::%{level::%{_uuid}%}%}:
        set {exp::%{_uuid}%} to {exp::%{_uuid}%} - {level::%{level::%{_uuid}%}%} # catches over xp
        add 1 to {level::%{_uuid}%}
        send "&aYou are now level %{level::%{_uuid}%}%!" to {_p}

Im sorry, but thats gonna be a bit advanced for me, therefore making it hard to for me to add more to the code
Anyhow i found that a solution like this works just fine:

https://hastebin.com/zaroxoyupu.cpp
 
Don't use a periodical for checking to see if a player leveled up. Just make a formula or write down vars for the amount each level and then use a function to check. This way is much more efficient. Untested code:
code_language.skript:
on join:
    set {exp::%uuid of player%} to 0
    set {level::%uuid of player%} to 1

# Example exponential formula (goes up 15% per level)
function checkForLevelUp(p: player):
    set {_uuid} to uuid of {_p}
    if {exp::%{_uuid}%} >= round(87(1.15)^{level::%{_uuid}%}):
        set {exp::%{_uuid}%} to {exp::%{_uuid}%} - round(87(1.15)^{level::%{_uuid}%}) # catches over xp
        add 1 to {level::%{_uuid}%}
        send "&aYou are now level %{level::%{_uuid}%}%!" to {_p}

on mine:
    if event-block is iron ore:
        add 5 to {exp::%uuid of player%}
        checkForLevelUp(player)


# OR YOU CAN DO SOMETHING LIKE:

on script load:
    set {level::1} to 150
    set {level::2} to 300

# Example exponential formula (goes up 15% per level)
function checkForLevelUp(p: player):
    set {_uuid} to uuid of player
    if {exp::%{_uuid}%} >= {level::%{level::%{_uuid}%}%}:
        set {exp::%{_uuid}%} to {exp::%{_uuid}%} - {level::%{level::%{_uuid}%}%} # catches over xp
        add 1 to {level::%{_uuid}%}
        send "&aYou are now level %{level::%{_uuid}%}%!" to {_p}

I'm trying to learn functions currebtly now that I know its possible
 
Status
Not open for further replies.