Solved Using NBT values in scripts

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


    You can always check out skUnity Downloads for downloads and any other information about Skript!

Not open for further replies.


New Member
Jun 7, 2017
Partial Code:
command /NBT <Item=bone> <Number=10>:
        give arg-1 with custom nbt "{hr:{valueHolder:%arg-2%}}" to player

Soo, if I wish to use valueHolder in parts of my script for example checking if its equal to 0 What would be the best way on doing so. -//- I wish to store data on items and use values I've saved for those items in scripts. Like checking if values is bigger than another one or saving the value in local variables

Ps. Is there a truly server side way to store item data that isn't hella complicated, I'm pretty sure NBT data is send to the client even tho you woudln't be able to see it without modified client.
Unless I'm misunderstanding what you're asking, you can just set a variable to "%arg-2%" because that's what you're setting valueHolder to.
I'm trying to use the set value at a later stage, for example after getting the item with lets say the value i want to store is elemental damage or something similar. I need to fetch that value to deal damage with OnHit, or some other trigger. The command itself wouldn't be good enough
There's probably a way to check it, but you could still just set %arg-2% to a variable then use it later. Ex)

command /NBT <Item=bone> <Number=10>:
        give arg-1 with custom nbt "{hr:{valueHolder:%arg-2%}}" to player
        set {variable.%player%} to arg-2

on damage:
    cancel event
    if lore of attacker's tool is "a lore you would add to the item in the above command": #i forget if thats the exact way to check an items lore but its something like that
        damage the victim by {variable.%attacker%}
But if I would set the value to hundreds or thousands of items, it would be a real mess to track.

to clarify what I meant, i want something like this:
On rightclick:
    broadcast "%[B]Value of valueHolder in nbt of attacker's tool[/B]%"
The bolded code doesn't work
Like I said there's probably a way to do that but I don't know how.

You're right, variables would get messy. You could do something like this:

command /NBT <Item=bone> <Number=10>: 
        give arg-1 with custom nbt "{hr:{valueHolder:%arg-2%}}" with lore "valueHolder: %arg-2%" to player
on rightclick:
    if lore of player's tool contains "valueHolder":
        set {_test::*} to lore of player's tool split at " "
        broadcast "%{_test::2}%"
I've got almost something that I wanted, it will suffice tho

    set {_value} to tag "valueHolder" of nbt of player's tool
    broadcast "%{_value}%"

Output is the nbt value of valueHolder in the weapon

But this doesnt seem to work with indets, that hr part at the start needs to be removed. So the nbt that is checked is at the tag level.

Post 1 NBT (havn't got it to work with tag "string" of nbt)
Current, Using the code above will broadcast 10 if nbt looks like this
Not open for further replies.