Skript value going into minus

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

gamie

New Member
Mar 8, 2019
5
0
1
35
Hey! Im really bad at explaining but its supposed to when i mine it just adds 1 experience and when i mine it just works and updates the xp but when i go after 127 it goes into minus (-127) and then counting like -126 -125 -124 and this keeps happening. Can someone help? Heres my full code:



Code:
function setItemTag(item: item, tag: string, value: object) :: item:
    set {_nbt} to nbt compound of {_item}
    set tag "tag;custom;%{_tag}%" of {_nbt} to {_value}
    return item from nbt {_nbt}

function getItemTag(item: item, tag: string) :: object:
    set {_tag} to tag "custom;%{_tag}%" of nbt of {_item}
    return {_tag}

function removeItemTag(item: item, tag: string) :: item:
    set {_nbt} to nbt compound of {_item}
    delete tag "tag;custom;%{_tag}%" of {_nbt}
    return item from nbt {_nbt}

on break:
    if event-block is stone:
        if player is holding a diamond pickaxe:
            set {_level} to getItemTag(player's tool, "level")
            set {_xp} to getItemTag(player's tool, "xp")
            set {_xpneeded} to getItemTag(player's tool, "xpneeded")
            if {_xp} is less than {_xpneeded}:
                set player's tool to setItemTag(player's tool, "xp", {_xp}+1)
                set {_xp} to getItemTag(player's tool, "xp")
                set 2st line of player's held item's lore to "&aExperience: &2%{_xp}%&a/&2%{_xpneeded}%"
                stop
            if {_xp} is {_xpneeded}:
                set player's tool to setItemTag(player's tool, "xp", 0)
                set player's tool to setItemTag(player's tool, "xpneeded", {_xpneeded}*1.25)
                set player's tool to setItemTag(player's tool, "level", {_level}+1)
                set {_level} to getItemTag(player's tool, "level")
                set {_xp} to getItemTag(player's tool, "xp")
                set {_xpneeded} to getItemTag(player's tool, "xpneeded")
                set 1st line of player's held item's lore to "&9Level: &b%{_level}%"
                set 2st line of player's held item's lore to "&aExperience: &2%{_xp}%&a/&2%{_xpneeded}%"
                message "&aYou leveled up! (%{_level}%&a)"
                stop
[doublepost=1625674486,1625598718][/doublepost]Hello? Anyone? If its not clear please tell me.
[doublepost=1625760818][/doublepost]bump
[doublepost=1625837547][/doublepost]bump
[doublepost=1626016973][/doublepost]Okay very helpfull..............
 
Last edited:
Please post your code in a code block
Capture.PNG
 
Yes you have, but for your future topics, please do not spam your topic with comments like "Hello? Anyone? If its not clear please tell me." or "Okay very helpfull..............". If someone is going to help you, they will do so without these comments.
[doublepost=1626287599,1626284776][/doublepost]I could recreate your problem, but I was unable to solve it - sorry! But I provided the basic workaround, you just have to customize and copy & paste it.
Code:
on break of stone:
    if tool of player is a diamond pickaxe:
        set {_lore} to uncolored "%2st line of player's held item's lore%"
        replace all "Experience: " with "" in {_lore}
        set {_lore::*} to split {_lore} at "/"
        set {_xp} to {_lore::1} parsed as an integer
        set 2st line of player's held item's lore to "&aExperience: &2%{_xp}+1%&a/&2--"
 
bump
[doublepost=1627211951,1627157816][/doublepost]bump
[doublepost=1627298155][/doublepost]bump
[doublepost=1627735844][/doublepost]bump
 
Status
Not open for further replies.