Solved Limit the Number of Custom Crafting Recipe Uses?

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

Selvati

Active Member
Jun 26, 2017
190
10
18
21
I would like to know if anyone is aware of any methods to limit each player to only be able to use custom crafting recipes registered with skript a certain number of times, example, you make a custom recipe for bedrock, each player can craft it 3 times. Any suggestions?
 
code_language.skript:
on inventory click:
    if clicked slot type is RESULT:
        if name of clicked item contain "Awesome Bedrock":
            if {bedrock.%player%} = 3:
                cancel event
                send "You cannot craft any more bedrock!"
                stop
            add 1 to {bedrock.%player%}

Dunno if that works, but you get the point...

using Skellett addons
 
code_language.skript:
on inventory click:
    if clicked slot type is RESULT:
        if name of clicked item contain "Awesome Bedrock":
            if {bedrock.%player%} = 3:
                cancel event
                send "You cannot craft any more bedrock!"
                stop
            add 1 to {bedrock.%player%}

Dunno if that works, but you get the point...

using Skellett addons
WOW! This is so simple yet very effective, thank you so much!
[doublepost=1513747201,1513721744][/doublepost]I get the error that RESULT cannot be compared to a slot type?
WOW! This is so simple yet very effective, thank you so much!
 
I get the error that RESULT cannot be compared to a slot type?

Huh, thats wierd...

https://docs.skunity.com/syntax/search/slot type

The docs explained, that RESULT is for result slot in a furnace or crafting inventory.
[doublepost=1513748388,1513747580][/doublepost]So i tested it out by myself with these codes...

code_language.skript:
on inventory click:
    if clicked slot type is RESULT:
        if clicked item is iron axe:
            if {axe.%player%} = 3:
                cancel event
                send "You cannot craft any more axes!"
                stop
            add 1 to {axe.%player%}
            send "successfully crafted axe"

And it worked for me
2017_12_20_12_34_06_1.png


Are you sure you have the latest version of skellet?
 
code_language.skript:
on inventory click:
    if clicked slot type is RESULT:
        if name of clicked item contain "Awesome Bedrock":
            if {bedrock.%player%} = 3:
                cancel event
                send "You cannot craft any more bedrock!"
                stop
            add 1 to {bedrock.%player%}

Dunno if that works, but you get the point...

using Skellett addons
Please use list variables and uuids, especially when providing code for other people.
upload_2017-12-20_3-36-21.png
 
Well, if you made the recipe using TuSKe's Recipe Manager then it'd be as easy as:
code_language.skript:
on prepare item craft:

  if result item of event-recipe is stone named "tes"An on item craft event cannot be cancelled"t": #for example

    cancel event
It'd work if you made it with skQuery and you have TuSKe, too.
[doublepost=1513811488,1513811428][/doublepost]Here is what I have, only the error I posted above.


code_language.skript:
#Iron Pack Craft
on script load:
    register new shaped recipe for 10 iron ingot using iron ore, iron ore, iron ore, iron ore, coal, iron ore, iron ore, iron ore, iron ore
    
#Craft Limit Check
on prepare item craft:
    if result item of event-recipe is 10 iron ingot:
        if {craft.ironpack.%player%} = 3:
            cancel event
            send "You cannot craft any more Rion Packs!"
            stop
        add 1 to {craft.ironpack.%player%}
[doublepost=1513812078][/doublepost]Whoops, I forgot to say this is the only error, "An on item craft event cannot be cancelled"
 
[doublepost=1513811488,1513811428][/doublepost]Here is what I have, only the error I posted above.


code_language.skript:
#Iron Pack Craft
on script load:
    register new shaped recipe for 10 iron ingot using iron ore, iron ore, iron ore, iron ore, coal, iron ore, iron ore, iron ore, iron ore
   
#Craft Limit Check
on prepare item craft:
    if result item of event-recipe is 10 iron ingot:
        if {craft.ironpack.%player%} = 3:
            cancel event
            send "You cannot craft any more Rion Packs!"
            stop
        add 1 to {craft.ironpack.%player%}
[doublepost=1513812078][/doublepost]Whoops, I forgot to say this is the only error, "An on item craft event cannot be cancelled"
Welp, setting the event-item (or maybe event-slot, you'll have to try it) to air should achieve the same effect.
 
After a lot of time trying out several things from the docs, which half seem to be broken, I am proud to present the finished product, which only prevents the player from taking the crafting table's result slot item, in these examples below, I had to work around the fact that I couldn't compare a clicked slot type to RESULT, but at the same time not preventing the player from moving an iron axe in his/her inventory while in a workbench.

Here is an example for any viewers looking to use this system :emoji_slight_smile:), thank you too everyone for your input <3.


code_language.skript:
# -
# In this example each player will only be able to craft 3 iron axes unless their variable is reset to 0.
# -
# Craft Limit Check
on inventory click:
    if inventory type of player's current inventory is "WORKBENCH":
        if clicked item is iron axe:
            if clicked inventory is not player's inventory:
                if clicked slot is 0:
                    if {craft.axe.%player%} = 3:
                        cancel event
                        send "You cannot craft any more axes!"
                        stop
                    add 1 to {craft.axe.%player%}
                    send "successfully crafted axe"
It took me a while but I'm happy that I could solve this issue with a simple work around, now I just can't wait for an addon developer to revive json!
[doublepost=1513819185,1513819034][/doublepost]
After a lot of time trying out several things from the docs, which half seem to be broken, I am proud to present the finished product, which only prevents the player from taking the crafting table's result slot item, in these examples below, I had to work around the fact that I couldn't compare a clicked slot type to RESULT, but at the same time not preventing the player from moving an iron axe in his/her inventory while in a workbench.

Here is an example for any viewers looking to use this system :emoji_slight_smile:), thank you too everyone for your input <3.


code_language.skript:
# -
# In this example each player will only be able to craft 3 iron axes unless their variable is reset to 0.
# -
# Craft Limit Check
on inventory click:
    if inventory type of player's current inventory is "WORKBENCH":
        if clicked item is iron axe:
            if clicked inventory is not player's inventory:
                if clicked slot is 0:
                    if {craft.axe.%player%} = 3:
                        cancel event
                        send "You cannot craft any more axes!"
                        stop
                    add 1 to {craft.axe.%player%}
                    send "successfully crafted axe"
It took me a while but I'm happy that I could solve this issue with a simple work around, now I just can't wait for an addon developer to revive json!
Just sliding onto this post once more, this is also useful if anyone would like to make special crafts that are permission specific, allowing donors/certain ranks to craft special things, the possibilities are endless! Happy Holidays! ♥
~Selvati
 
After a lot of time trying out several things from the docs, which half seem to be broken, I am proud to present the finished product, which only prevents the player from taking the crafting table's result slot item, in these examples below, I had to work around the fact that I couldn't compare a clicked slot type to RESULT, but at the same time not preventing the player from moving an iron axe in his/her inventory while in a workbench.

Here is an example for any viewers looking to use this system :emoji_slight_smile:), thank you too everyone for your input <3.


code_language.skript:
# -
# In this example each player will only be able to craft 3 iron axes unless their variable is reset to 0.
# -
# Craft Limit Check
on inventory click:
    if inventory type of player's current inventory is "WORKBENCH":
        if clicked item is iron axe:
            if clicked inventory is not player's inventory:
                if clicked slot is 0:
                    if {craft.axe.%player%} = 3:
                        cancel event
                        send "You cannot craft any more axes!"
                        stop
                    add 1 to {craft.axe.%player%}
                    send "successfully crafted axe"
It took me a while but I'm happy that I could solve this issue with a simple work around, now I just can't wait for an addon developer to revive json!
[doublepost=1513819185,1513819034][/doublepost]
Just sliding onto this post once more, this is also useful if anyone would like to make special crafts that are permission specific, allowing donors/certain ranks to craft special things, the possibilities are endless! Happy Holidays! ♥
~Selvati
I relaly don't get why you aren't just using on craft. Also, json is already a thing in multiple addons.
 
I relaly don't get why you aren't just using on craft. Also, json is already a thing in multiple addons.
I use spigot 1.8.9 please do tell which json addons are working? & also I know this is in a way over complicated but it helps me grow in skript knowledge so I'm happy :]
 
I use spigot 1.8.9 please do tell which json addons are working? & also I know this is in a way over complicated but it helps me grow in skript knowledge so I'm happy :]
What kind of json are we talking? Parsing json? Chat component?
 
What kind of json are we talking? Parsing json? Chat component?
Chat components, the example that comes to mind is vanilla achievements, you can hover over green text to reveal details.
[doublepost=1513837950,1513837731][/doublepost]I’m aware of skjson, but it doesn’t work for my server oddly enough.
 
Chat components, the example that comes to mind is vanilla achievements, you can hover over green text to reveal details.
[doublepost=1513837950,1513837731][/doublepost]I’m aware of skjson, but it doesn’t work for my server oddly enough.
skript-json is not for that. You can use json.sk or vanilla skript on dev29+.
 
Status
Not open for further replies.