Save items in variables

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

Status
Not open for further replies.

ChromeShape

Member
Feb 1, 2020
1
0
0
29
Hello there!
I need help for this skript problem.

when I break the one of wheat, I want to save the amount of items to array variables, but I can't do this.
How can I solve this problem?

Code:
command /crops:
    trigger:
        wait 1 ticks
        open chest with 3 row named "{@a} %player%" to player
        play sound "BLOCK_NOTE_PLING" to player with volume 1 and pitch 10
        loop 27 times:
            set slot (loop-number)-1 of current inventory of player to {crops.%player%::%loop-number%}

on inventory close:
    delete {cropsam.%{_a}%::*}
    if inventory name of current inventory of player contains "crops":
        set {_a} to inventory name of current inventory of player
        replace all "{@a} " with "" in {_a}
        delete {crops.%{_a}%::*}
        loop 27 times:
            add slot (loop-number)-1 of current inventory of player to {crops.%{_a}%::*}
        loop {crops.%{_a}%::*}:
            add item amount of wheat of {crops.%{_a}%::%loop-index%} to {cropsam.%{_a}%::%loop-index%}

on break of ripe wheat:
    wait 1 tick
    loop {crops.%player%::*}:
        add item amount of loop-value + 1 to item amount of {crops.%player%::%loop-index%}
        broadcast "%{crops.%player%::%loop-index%}%"
    send player title "" with subtitle "&fYou got &e&lWheat!" for 0.5 seconds
 
Last edited:
you save crops only on inventory close, which does not seem related to getting the crops amount from block breaking, I'd recommend loop dropped item entities around the broken block, check if their Spigot.ticksLived tag is like 0-1 and if it is wheat within the entity

and your variable format looks weird, I'd recommend {crops::%uuid of player%::*} instead of {crops.%player%::*}
 
Status
Not open for further replies.