#Help with Attributes

1 messages · Page 1 of 1 (latest)

rotund sand
#
# # Get Item Attribute
# gets the 'amount' of an attribute on an item, if the item doesn't have that attribute, it returns <none>.
function getItemAttribute(item: item, attribute: string) :: object: # number doesn't work
    set {_nbt} to (nbt compound of {_item})
    set {_attributes::*} to (compound list tag "AttributeModifiers" of {_nbt})
    loop {_attributes::*}:
        if (string tag "Name" of loop-value) is {_attribute}:
            set {_amount} to (int tag "Amount" of loop-value)
            return {_amount}

command /getItemAttribute:
    permission: op 
    trigger:
        set {_i} to player's held item
        set {_value} to getItemAttribute({_i}, "generic_max_health")
        send "%{_value}%"

Hey there, im working on a attributes skript, basically trying to find attributes per gear piece
But uh {_value} keeps returning "<none>"
I also double checked that the armor piece that im holding has 1 max health, but it does not seem to detect it

empty shell
#

broadcast (string tag "Name" of loop-value) in the function and see what its actually called

meager crescent
#

what happens if you broadcast the pretty nbt of the item

#

are you sure its an int tag and not a float or something

#

heck, you can broadcast the type to check

rotund sand
#

@meager crescent

#

not sure why int tag isnt working lol

meager crescent
#

Anyways, i cant see what’s supposed to be broadcasted. send_code

rotund sand
#

Anyways, that is fixed but

#

having another issue here

#
function addItemAttribute(item: item, attribute: string, amount: number, operation: integer, slot: string) :: item:
    set {_nbt} to (nbt compound of {_item})
    set {_attributes::*} to (compound list tag "AttributeModifiers" of {_nbt})
    set {_uuid} to uuid int array as string
    set {_new.attribute} to (nbt compound from "{Slot:%{_slot}%, AttributeName:%{_attribute}%, Name:%{_attribute}%, Amount:%{_amount}%, Operation:%{_operation}%, UUID:%{_uuid}%}")
    add {_new.attribute} to {_attributes::*}
    set (compound list tag "AttributeModifiers" of {_nbt}) to {_attributes::*}
    return {_item}

command /getItemAttribute:
    permission: op 
    trigger:
        set {_x} to addItemAttribute(player's held item, "generic_max_health", 2, 1, "chest")
        give player {_x}
#

I followed the function and it reloads fine

#

but it doesnt add the attribute to the player's held item