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.

Skript value going into minus

Discussion in 'Skript' started by gamie, Jul 6, 2021.

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

    gamie New Member

    Joined:
    Mar 8, 2019
    Messages:
    5
    Likes Received:
    0
    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 (Text):
    1. function setItemTag(item: item, tag: string, value: object) :: item:
    2.     set {_nbt} to nbt compound of {_item}
    3.     set tag "tag;custom;%{_tag}%" of {_nbt} to {_value}
    4.     return item from nbt {_nbt}
    5.  
    6. function getItemTag(item: item, tag: string) :: object:
    7.     set {_tag} to tag "custom;%{_tag}%" of nbt of {_item}
    8.     return {_tag}
    9.  
    10. function removeItemTag(item: item, tag: string) :: item:
    11.     set {_nbt} to nbt compound of {_item}
    12.     delete tag "tag;custom;%{_tag}%" of {_nbt}
    13.     return item from nbt {_nbt}
    14.  
    15. on break:
    16.     if event-block is stone:
    17.         if player is holding a diamond pickaxe:
    18.             set {_level} to getItemTag(player's tool, "level")
    19.             set {_xp} to getItemTag(player's tool, "xp")
    20.             set {_xpneeded} to getItemTag(player's tool, "xpneeded")
    21.             if {_xp} is less than {_xpneeded}:
    22.                 set player's tool to setItemTag(player's tool, "xp", {_xp}+1)
    23.                 set {_xp} to getItemTag(player's tool, "xp")
    24.                 set 2st line of player's held item's lore to "&aExperience: &2%{_xp}%&a/&2%{_xpneeded}%"
    25.                 stop
    26.             if {_xp} is {_xpneeded}:
    27.                 set player's tool to setItemTag(player's tool, "xp", 0)
    28.                 set player's tool to setItemTag(player's tool, "xpneeded", {_xpneeded}*1.25)
    29.                 set player's tool to setItemTag(player's tool, "level", {_level}+1)
    30.                 set {_level} to getItemTag(player's tool, "level")
    31.                 set {_xp} to getItemTag(player's tool, "xp")
    32.                 set {_xpneeded} to getItemTag(player's tool, "xpneeded")
    33.                 set 1st line of player's held item's lore to "&9Level: &b%{_level}%"
    34.                 set 2st line of player's held item's lore to "&aExperience: &2%{_xp}%&a/&2%{_xpneeded}%"
    35.                 message "&aYou leveled up! (%{_level}%&a)"
    36.                 stop
    --- Double Post Merged, Jul 7, 2021, Original Post Date: Jul 6, 2021 ---
    Hello? Anyone? If its not clear please tell me.
    --- Double Post Merged, Jul 8, 2021 ---
    bump
    --- Double Post Merged, Jul 9, 2021 ---
    bump
    --- Double Post Merged, Jul 11, 2021 ---
    Okay very helpfull..............
     
    #1 gamie, Jul 11, 2021
    Last edited: Jul 13, 2021
  2. AHappyLittleSloth

    Joined:
    Apr 22, 2020
    Messages:
    48
    Likes Received:
    4
    Please post your code in a code block
    Capture.PNG
     
  3. gamie

    gamie New Member

    Joined:
    Mar 8, 2019
    Messages:
    5
    Likes Received:
    0
    Hello! I think i've done it! Like this?
    --- Double Post Merged, Jul 14, 2021, Original Post Date: Jul 13, 2021 ---
    bump
     
  4. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    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.
    --- Double Post Merged, Jul 14, 2021, Original Post Date: Jul 14, 2021 ---
    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 (Text):
    1. on break of stone:
    2.     if tool of player is a diamond pickaxe:
    3.         set {_lore} to uncolored "%2st line of player's held item's lore%"
    4.         replace all "Experience: " with "" in {_lore}
    5.         set {_lore::*} to split {_lore} at "/"
    6.         set {_xp} to {_lore::1} parsed as an integer
    7.         set 2st line of player's held item's lore to "&aExperience: &2%{_xp}+1%&a/&2--"
     
  5. gamie

    gamie New Member

    Joined:
    Mar 8, 2019
    Messages:
    5
    Likes Received:
    0
    bump
    --- Double Post Merged, Jul 25, 2021, Original Post Date: Jul 24, 2021 ---
    bump
    --- Double Post Merged, Jul 26, 2021 ---
    bump
    --- Double Post Merged, Jul 31, 2021 ---
    bump
     
Thread Status:
Not open for further replies.

Share This Page

Loading...