Solved Inventory list (Detect, Add to list, if the item is, give back)

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

Dabriel

Member
Aug 13, 2018
45
5
0
27
Alright, so I'm trying to create this really cool feature on my server. It's not happening tho.
I'm a beginner in Skript so I need help. Why not create this Skript together?
So what I have in mind, is making some kind of blacksmith.
hymLZWl.png


So it's a GUI, obv. The first row until slot 7, should be the list that players can place the items in.
The items that are placed in that list (slots) are gonna be added to the items list, like
code_language.skript:
{blacksmith.%player%::items::*} -- Just an example.

rUat2Wm.png


Now when the items are in the slots, the IF condition gonna take a place in the code.
So let's say, you need common keys to make 1 uncommon key.
if you place 3 keys in that GUI, the items are gonna get added to the items list, so if {blacksmith.%player%::items::*} has those 3 items, and the player clicks on the green dye
HYiCNhl.png

It's gonna clear the slots from 0 to 7, give the player the uncommon key, and delete the items list.

But if the player puts only 2 out of 3 items in, it's gonna clear the slots from 0 to 7, give all the items in the list back and delete the list.
36AMPYX.png




So what's the best way to do so? I mean, how to create a list and do the if condition?
This might sound like too much, if we make it, it might help a lot of people, and give some new ideas.


Thanks :emoji_slight_smile:
[doublepost=1535636632,1535551953][/doublepost]bump.
At least just help making the list for the slots :emoji_frowning:
 
Help is on the way, Dabriel.

I've coded your entire request, I only have one question: What would happen if players put more than 3 common keys on the slots?

EDIT: Nevermind, I'm in a hurry, take it, I wrote it so it would return all the common keys even if they're more than 3 (just like if they were less than 3).

Note: it includes a command to auto-give you a common key so you can test it, don't forget to delete that later, or else players will have free common keys at-their-service lol. Good script idea tho.

P.S. You actually don't need any array. It's all about slot looping.

code_language.skript:
options:
    readyButton: &a&lReady
    commonKeyItem: iron nugget
    uncommonKeyItem: gold nugget
    commonKey: &7&lCommon Key
    uncommonKey: &c&lUncommon Key

command /blacksmithgui:
    trigger:
        open chest with 3 rows named "&5&lBlacksmith" to player
        set slot 8 of player's current inventory to light green dye named "{@readyButton}"
        set {_count} to 9
        loop 18 times:
            set slot {_count} of player's current inventory to black stained glass named " "
            add 1 to {_count}
        
on inventory click:
    name of event-inventory is "&5&lBlacksmith"
    if event-slot is not air:
        cancel event
        if name of event-slot is "{@readyButton}":
            set {_count} and {_common} to 0
            loop 8 times:
                if name of slot {_count} of event-inventory is "{@commonKey}":
                    add 1 to {_common}
                add 1 to {_count}
            if {_common} is 3:
                set slot 0, 1, 2, 3, 4, 5, 6 and 7 of event-inventory to air
                give {@uncommonKeyItem} named "{@uncommonKey}" to player
            else:
                set {_count} to 0
                loop 8 times:
                    give slot {_count} of event-inventory to player
                    add 1 to {_count}
                set slot 0, 1, 2, 3, 4, 5, 6 and 7 of event-inventory to air

on inventory close:
    name of event-inventory is "&5&lBlacksmith"
    set {_count} to 0
    loop 8 times:
        give slot {_count} of event-inventory to player
        add 1 to {_count}

command /givecommonkey:
    trigger:
        give {@commonKeyItem} named "{@commonKey}" to player
 
Last edited:
Help is on the way, Dabriel.

I've coded your entire request, I only have one question: What would happen if players put more than 3 common keys on the slots?

EDIT: Nevermind, I'm in a hurry, take it, I wrote it so it would return all the common keys even if they're more than 3 (just like if they were less than 3).

Note: it includes a command to auto-give you a common key so you can test it, don't forget to delete that later, or else players will have free common keys at-their-service lol. Good script idea tho.

P.S. You actually don't need any array. It's all about slot looping.

code_language.skript:
options:
    readyButton: &a&lReady
    commonKeyItem: iron nugget
    uncommonKeyItem: gold nugget
    commonKey: &7&lCommon Key
    uncommonKey: &c&lUncommon Key

command /blacksmithgui:
    trigger:
        open chest with 3 rows named "&5&lBlacksmith" to player
        set slot 8 of player's current inventory to light green dye named "{@readyButton}"
        set {_count} to 9
        loop 18 times:
            set slot {_count} of player's current inventory to black stained glass named " "
            add 1 to {_count}
       
on inventory click:
    name of event-inventory is "&5&lBlacksmith"
    if event-slot is not air:
        cancel event
        if name of event-slot is "{@readyButton}":
            set {_count} and {_common} to 0
            loop 8 times:
                if name of slot {_count} of event-inventory is "{@commonKey}":
                    add 1 to {_common}
                add 1 to {_count}
            if {_common} is 3:
                set slot 0, 1, 2, 3, 4, 5, 6 and 7 of event-inventory to air
                give {@uncommonKeyItem} named "{@uncommonKey}" to player
            else:
                set {_count} to 0
                loop 8 times:
                    give slot {_count} of event-inventory to player
                    add 1 to {_count}
                set slot 0, 1, 2, 3, 4, 5, 6 and 7 of event-inventory to air

on inventory close:
    name of event-inventory is "&5&lBlacksmith"
    set {_count} to 0
    loop 8 times:
        give slot {_count} of event-inventory to player
        add 1 to {_count}

command /givecommonkey:
    trigger:
        give {@commonKeyItem} named "{@commonKey}" to player
You
are
a
god!



Thank you so very much for this masterpiece! It's perfect! I didn't think anyone would do it
Thank you so much
 
  • Like
Reactions: PatoFrango
Status
Not open for further replies.