Save variable in item

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

Laserlp

New Member
Aug 4, 2024
7
0
1
15
Hello everyone! I need help by saving Variables per item. This is my code:

Code:
#ARMOR
command /armor <number>:
    trigger:
        clear {armor}
        set {armor} to unbreakable leather chestplate with name "&eLeather Set" with lore "&eLevel: &c%arg-1% %newline%%newline%&a&lCOMMON"
        set slot 1 of player's inventory to {armor}
        set {_item} to item in slot 1 of player's inventory
        set {level.%{_item}%} to arg-1

command /checklevel:
    trigger:
        set {_item} to player's tool
        broadcast "Level: %{level.%{_item}%}%"
What happens is that when I have two or more armor sets, the level of the first set gets replaced by the second. In other words, the variable only holds one value for all items.

How can I fix this? I don’t think using a list will help, but I’m open to suggestions if I’m wrong!
 
A list could definitely help if you want to make each item unique, but I honestly think it makes way more sense to just use Minecraft NBT to store variables in items. I think SkBee supports NBT tags and other stuff too.

I hope that helped. ^^
 
Yeah I know that, but I just can't get it to work. I tried this:

Code:
command /armor <integer>:
    trigger:
        clear {armor}
        set {armor} to unbreakable leather chestplate with name "&eLeather Set" with lore "&eLevel: &c%arg-1% %newline%%newline%&a&lCOMMON"
        set int tag "custom;ArmorLevel" of nbt of {armor} to arg-1
        give {armor} to player
     
command /checklevel:
    trigger:
        set {_level} to int tag "custom;ArmorLevel" of nbt of player's tool
        broadcast "Level: %{_level}%"

I mean like there is no error but it just doesn't work. Idk I have some problem with nbts... Maybe someone finds whats wrong...