Enchanting Item with multiple enchants

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

    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!

Quentin_GHG

Member
Mar 15, 2024
13
0
1
Hello! Ive recently Tried to Learn Skript YAML and it was going pretty well untill I hit a roadblock and I cant solve it, so I wanted to ask for some help :emoji_grinning:
So Im working on a GUI where players can upgrade their items etc etc, and each item is saved as an individual .yml file so I can edit the name lore etc, but here is my problem, I tried using a list or someway of adding enchants, but I couldnt parse the list nor could I enchant items with it, I tried Parse as enchantment type and level, but it just doesnt seem to work for me sadly, so here is what my basic yml file looks like:
Code:
name: "&6Wooden Axe &8[&7I&8]"
type: wooden axe
price: "64 oak log"
enchants: unbreaking 1 and efficiency 2
damage: 2

And this is my function to retrieve the information:

Code:
function createItem(player: player, id: number, type: text) :: item:
    if file "plugins/Items/%{_type}%/%{_id}%.yml" doesn't exist:
        send "&7[&bItems&7] &8» &cUnable to generate an item. This ID does not exist." to {_player}
    else:
        load "plugins/Items/%{_type}%/%{_id}%.yml" as "items-%{_type}%-%{_id}%"
        set {_name} to yaml value "name" from "items-%{_type}%-%{_id}%"
        set {_itemType} to yaml value "type" from "items-%{_type}%-%{_id}%"
        set {_price-shown} to yaml value "price" from "items-%{_type}%-%{_id}%"
        set {_enchants::*} to yaml value "enchants" from "items-%{_type}%-%{_id}%"
        loop {_enchants::*}:
            set {_enchant} to loop-value parsed as enchantment type
            broadcast "%{_enchant}%"
            enchant {_item} with {_enchant}
        set {_item} to {_itemType} parsed as item
        set name of {_item} to colored {_name}
        set lore of {_item} to colored "&a%{_price-shown}%"
        add hide attributes to item flags of {_item}
        add hide enchants to item flags of {_item}
        return {_item}

And there aren't any errors, just that it doesnt enchant it correctly, if the list only contains 1 enchant then it atleast outputs it correctly to the broadcast, but still the item doesnt get enchanted, and more then one enchant is just <none>
Anyways as always I very much appreciate help and this platform :emoji_grinning:
 
Why are you setting the variable {_item} after you enchant it? Maybe the issue is the order you clarified the variable. (I'm on mobile so sorry if this isn't helpful)
 
ye that was stupid off me true, I dont know how I didn't see that haha, but its still the problem with more then 1 enchant, I just cant find online how to use lists with yaml? I tried it with splitting the line but that juts didnt work for me, I just done understand how to use lists? Or any way to store and output a list,
Either way I thank you very much for showing me my silly mistake lol
 
Just found a solution finally and its actually way to simple, instead of using set {_enchants::*} to yaml value "enchants" from "items-%{_type}%-%{_id}%"
I just use set {_enchants::*} to yaml list "enchants" from "items-%{_type}%-%{_id}%" and that fixxed everything, so yeah I think Im just stupid anyways thanks for helping and uh I think this is done, tysm :emoji_grinning:
 
Just found a solution finally and its actually way to simple, instead of using set {_enchants::*} to yaml value "enchants" from "items-%{_type}%-%{_id}%"
I just use set {_enchants::*} to yaml list "enchants" from "items-%{_type}%-%{_id}%" and that fixxed everything, so yeah I think Im just stupid anyways thanks for helping and uh I think this is done, tysm :emoji_grinning:
Yeah, that makes sense, because you were only getting one value instead of the whole list. At least you did it!