Solved Custom Farming Not Giving Item When Harvested

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

ItsMCB

Member
May 20, 2018
46
1
8
23
www.vexel.media
I'm trying to make a custom food skript for my server. I can't figure out why the player isn't being given the item when it's harvested.
code_language.skript:
on rightclick on soil:
    if name of player's tool is "&aCucumber Seed":
        if block above clicked block is air:
            remove 1 of player's tool from player
            add location above clicked block to {cucumbers::*}
            set block above clicked block to crops

every 20 ticks:
    loop {cucumbers::*}:
        if block at loop-value is crops:    # This checks to see if it has been harvested
            if data value of block at loop-value is greater than 6:
                set block at loop-value to fern
            else:
                add 1 to data value of block at loop-value    # The data value is the grow state in the case of crops
        else:
            remove loop-value from {cucumbers::*}
            # Deletes the cucumber location variable if harvested or full grown

on break of crops:0-6:
    if block below event-block is farmland:
        cancel event
on break of crops:7:
    if {farminglvl.%player%} is higher than or equal to 0:
        give 1 melon_slice named "&aCucumber" to player's inventory
        add 0.5 to {farminglvl.%player%}
Thanks for your help :emoji_slight_smile:
 
well based on what i see here, i may be wrong / reading it wrong, but your plant grows into a fern, and you want it to give a player a cucumber.... but you have nothing in here about harvesting the fern itself. You have harvesting the crop... but not the fern.
So the cucumber is only given when the player harvests a crop.
 
Ohhh.. I didnt know what he want too, because it works well.. I thought that last level of growing(fern) is that the plat is dead.. just that its out of limit :emoji_grinning:DD if you know what i mean xD

Then try:
code_language.skript:
on rightclick on soil:
    if name of player's tool is "&aCucumber Seed":
        if block above clicked block is air:
            remove 1 of player's tool from player
            add location above clicked block to {cucumbers::*}
            set block above clicked block to crops
 
every 20 ticks:
    loop {cucumbers::*}:
        if block at loop-value is crops:    # This checks to see if it has been harvested
            if data value of block at loop-value is greater than 6:
                set block at loop-value to fern
            else:
                add 1 to data value of block at loop-value    # The data value is the grow state in the case of crops
        else:
            remove loop-value from {cucumbers::*}
            # Deletes the cucumber location variable if harvested or full grown
 
on break of crops:0-7:
    if block below event-block is farmland:
        cancel event
on break of fern:
    if {farminglvl.%player%} is higher than or equal to 0:
        give 1 melon_slice named "&aCucumber" to player's inventory
        add 0.5 to {farminglvl.%player%}

And I would make it like this:
code_language.skript:
on break of crops:0-7:
    if block below event-block is farmland:
        loop {cucumbers::*}:
            if loop-value is location at event-block:
                cancel event
                set event-block to air
                drop 1 seeds named "&aCucumber Seed" at location of event-block

on break of fern:
    #cancel event                     #Not required if block has no drops
    #set event-block to air           #Not required if block has no drops
    drop 1 melon_slice named "&aCucumber"
    loop random integer between 1 and 2 times:
        drop 1 seeds named "&aCucumber Seed" at location of event-block
 
Last edited:
Ohhh.. I didnt know what he want too, because it works well.. I thought that last level of growing(fern) is that the plat is dead.. just that its out of limit :emoji_grinning:DD if you know what i mean xD

Then try:
code_language.skript:
on rightclick on soil:
    if name of player's tool is "&aCucumber Seed":
        if block above clicked block is air:
            remove 1 of player's tool from player
            add location above clicked block to {cucumbers::*}
            set block above clicked block to crops
 
every 20 ticks:
    loop {cucumbers::*}:
        if block at loop-value is crops:    # This checks to see if it has been harvested
            if data value of block at loop-value is greater than 6:
                set block at loop-value to fern
            else:
                add 1 to data value of block at loop-value    # The data value is the grow state in the case of crops
        else:
            remove loop-value from {cucumbers::*}
            # Deletes the cucumber location variable if harvested or full grown
 
on break of crops:0-7:
    if block below event-block is farmland:
        cancel event
on break of fern:
    if {farminglvl.%player%} is higher than or equal to 0:
        give 1 melon_slice named "&aCucumber" to player's inventory
        add 0.5 to {farminglvl.%player%}

And I would make it like this:
code_language.skript:
on break of crops:0-7:
    if block below event-block is farmland:
        loop {cucumbers::*}:
            if loop-value is location at event-block:
                cancel event
                set event-block to air
                drop 1 seeds named "&aCucumber Seed" at location of event-block

on break of fern:
    #cancel event                     #Not required if block has no drops
    #set event-block to air           #Not required if block has no drops
    drop 1 melon_slice named "&aCucumber"
    loop random integer between 1 and 2 times:
        drop 1 seeds named "&aCucumber Seed" at location of event-block
Thank you so much! :emoji_grinning:
 
I saw this post and started working on it before MusicMan replied and solved it.
But I wanted to post what I came up with anyways.

My way is a bit different. I noticed in your way, the plant is forced to grow within a few seconds.
I changed it up a bit, I did it so the plants grow naturally like other plants.
When a player plants the cucumber seed, it will grow like a regular wheat plant, but when it comes to full maturity the plant will then turn into a fern.
If a player breaks the crop before it comes to full maturity, it will drop a single cucumber seed
If the player waits till full maturity, and breaks the fern, it will drop a cucumber slice, as well as a random chance of 1-3 cucumber seeds

Give this a try

code_language.skript:
on right click on soil:
    if player's tool is seeds named "&aCucumber Seed":
        set {_loc} to location 1 above event-location
        set {crops::cucumber::%{_loc}%} to {_loc}

on crop growth:
    if event-location is {crops::cucumber::%event-location%}:
        if data value of event-block is 7:
            set event-block to fern

on break of fern:
    if event-location is {crops::cucumber::%event-location%}:
        drop 1 melon slice named "&aCucumber" at event-location
        set {_drop} to a random number between 1 and 3
        drop {_drop} of seeds named "&aCucumber Seed" at event-location
        clear {crops::cucumber::%event-location%}

on break of crops:
    if event-location is {crops::cucumber::%event-location%}:
        cancel event
        set event-block to air
        drop 1 of seeds named "&aCucumber Seed" at event-location
        clear {crops::cucumber::%event-location%}
 
@ShaneBee I made same thing for me xDD.. yes.. left it for growing like others and then make from it cucumber.. same.. but i posted it like he wanted.. :emoji_joy::emoji_joy:
 
Definitely want to note for @ItsMCB that the code @ShaneBee gave is way better (assuming it works, but if not it could be fixed). There's no reason to need the 'every 20 ticks' loop for this code.
 
Yes I know.. but he has issue with giving items.. so i helped him with it.. I know that there is mutch better way to do it but he wanted this way...
 
Definitely want to note for @ItsMCB that the code @ShaneBee gave is way better (assuming it works, but if not it could be fixed). There's no reason to need the 'every 20 ticks' loop for this code.
It does work, i made sure to test it before posting here. I did it that way because i thought it was very odd to plant seeds and have it come to full term in 3 seconds. Seems pointless.... might as well just have it when you hit the farmland with seeds it gives you melons. This way a player has to wait for the plant to fully grow or use bone meal on the plant (Which i also tested and works)
 
  • Like
Reactions: Mr_Simba
It does work, i made sure to test it before posting here. I did it that way because i thought it was very odd to plant seeds and have it come to full term in 3 seconds. Seems pointless.... might as well just have it when you hit the farmland with seeds it gives you melons. This way a player has to wait for the plant to fully grow or use bone meal on the plant (Which i also tested and works)
Sorry I have been inactive, thank you
I saw this post and started working on it before MusicMan replied and solved it.
But I wanted to post what I came up with anyways.

My way is a bit different. I noticed in your way, the plant is forced to grow within a few seconds.
I changed it up a bit, I did it so the plants grow naturally like other plants.
When a player plants the cucumber seed, it will grow like a regular wheat plant, but when it comes to full maturity the plant will then turn into a fern.
If a player breaks the crop before it comes to full maturity, it will drop a single cucumber seed
If the player waits till full maturity, and breaks the fern, it will drop a cucumber slice, as well as a random chance of 1-3 cucumber seeds

Give this a try

code_language.skript:
on right click on soil:
    if player's tool is seeds named "&aCucumber Seed":
        set {_loc} to location 1 above event-location
        set {crops::cucumber::%{_loc}%} to {_loc}

on crop growth:
    if event-location is {crops::cucumber::%event-location%}:
        if data value of event-block is 7:
            set event-block to fern

on break of fern:
    if event-location is {crops::cucumber::%event-location%}:
        drop 1 melon slice named "&aCucumber" at event-location
        set {_drop} to a random number between 1 and 3
        drop {_drop} of seeds named "&aCucumber Seed" at event-location
        clear {crops::cucumber::%event-location%}

on break of crops:
    if event-location is {crops::cucumber::%event-location%}:
        cancel event
        set event-block to air
        drop 1 of seeds named "&aCucumber Seed" at event-location
        clear {crops::cucumber::%event-location%}
Sorry I have been inactive, thank you :emoji_grinning:
 
Status
Not open for further replies.