Leveling Up Skript undefined option

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

SnapRan

Member
Aug 9, 2022
3
0
1
43
variables:
lv1 = 5
lv2 = 10
lv3 = 20
lv4 = 35
lv5 = 50
lv6 = 100
lv7 = 150
lv8 = 200
lv9 = 230
lv10 = 250
lv11 = 300


on mine:
add 1 to {_xp}
if {1.level::%player%} is true:
if {_xp} = {@lv1}:
set {1.level::%player%} to false
set {level::%player%} to 1
set {_xp} to 0
if {2.level::%player%} is true:
if {_xp} = {@lv2}:
set {level::%player%} to 2
set {_xp} to 0
set {2.level::%player%} to false
 
If you use a variable it's not {@lv1} but {lv1}. If you want to make it so that it loads what you changed on skript you should do options
Example (also, please use code brackets)

Note: I don't know if I got the amount of spaces right.

Code:
options:
    lv1: 5
    lv2: 10
    lv3: 20
    lv4: 35
    lv5: 50
    lv6: 100
    lv7: 150
    lv8: 200
    lv9: 230
    lv10: 250
    lv11: 300

on mine:
    add 1 to {_xp}
    if {1.level::%player%} is true:
        if {_xp} = "{@lv1}":
            set {1.level::%player%} to false
            set {level::%player%} to 1
            set {_xp} to 0
    if {2.level::%player%} is true:
        if {_xp} = "{@lv2}":
            set {level::%player%} to 2
            set {_xp} to 0
            set {2.level::%player%} to false
 
There are some problems with your skript.
1. You should use "options:" instead of "variables:" if you are going to use {@lv1}.
2. Your skript doesn't work. After "on mine:" starts to run, since {_xp} is a local variable it will start as nothing so when you do "add 1 to {_xp}", {_xp} will just be 1.
3. It's really not a good idea to make the levels one by one (Unless there is a low level cap. Like for example, the level cap is just 10).
4. You are using "%player%" instead of "%player%'s uuid", since %player% just indicates the player's username and the player has the ability to change their username, if they change their username they are going to lose the data.

You should probably make some kind of formula to get how much experience the player needs to level up.

I made a better skript, hasn't been tested so reply to me if there was any errors:
Code:
function getXpAmount(block: block) :: number:

    #return 1 if {_block} is a coal ore
    #return 2 if {_block} is an iron ore
    #return 10 if {_block} is a diamond ore

    # -- Here you can code something that will return a different xp amount depending on the block that was mined

    return 1

function neededXp(lvl: number) :: number:
    return 10*{_lvl}-5 # Little formula that I made

function getXp(plr: player) :: number:
    set {xp::%{_plr}'s uuid%} to 0 if {xp::%{_plr}'s uuid%} does not exist # Sets the xp to 0 if the player is new just in case

    return {xp::%{_plr}'s uuid%}

function getLevel(plr: player) :: number:
    set {level::%{_plr}'s uuid%} to 1 if {level::%{_plr}'s uuid%} does not exist # Sets the level to 1 if the player is new just in case

    return {level::%{_plr}'s uuid%}

function giveXp(plr: player, a: number):
    add {_a} to {xp::%{_plr}'s uuid%}

function giveLevel(plr: player, a: number):
    add {_a} to {level::%{_plr}'s uuid%}

function setXp(plr: player, a: number):
    set {xp::%{_plr}'s uuid%} to {_a}

function setLevel(plr: player, a: number):
    set {level::%{_plr}'s uuid%} to {_a}

function checkForLevelUp(plr: player):
    set {_xp} to getXp({_plr})
    set {_level} to (getLevel({_plr}) + 1)

    if {_xp} >= neededXp({_level}):
        giveLevel({_plr}, 1)
        giveXp({_plr}, (neededXp({_level})) * -1)
        checkForLevelUp({_plr})

on mine:
    set {_x} to getXp(player) # Sets the xp to 0 if the player is new (inside the function)
    giveXp(player, getXpAmount(event-block)) # getXpAmount(event-block) returns how much xp it will give to the player

    checkForLevelUp(player)
 
Status
Not open for further replies.