Detect if a list contains another list

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

Cakerama1

New Member
Aug 21, 2022
6
0
1
18
Im trying to detect if a list of items has another list of items in it. I thought this would be easy but "if <list> contains <list>" does not work because if 1 list has "3 stone" and the other list has "2 stone", It will not trigger. Is there anyway to fix this?
 
Hey, hm, im wondering how you can do it, maybe you can try it like you loop those lists and then split both loop-values at integer or space or whatever will be easier, and check if those splits matches, if yes then the list contains required item.
It will probably have easier solution, but i cant think of something at the moment..
 
Java:
function contains(n: items, c: items) :: boolean :
    if {_n::*} is empty:
        return false
    loop {_n::*}:
        set {_item} to loop-item
        set {_amount} to amount of {_item} in {_n::*}
        if {_c::*} does not contain at least {_amount} of {_item}:
            return false
    return true

no tested
 
Last edited:
The contains() method checks if it contains the required elements. If it does, it returns true, otherwise it returns false.

Java:
if contains({items::*}, all items in player's inventory) is true: // contains(required items, available items)
      send "yes, it's includes"

Have you tried it?
 
thx everyone for the help. I have decided to give up on this for now since I couldnt find a solution. The only thing I made was an extremely scuffed check that didnt even cover everything I needed it to. What Im actually going for is a sort of shapeless recipe detection. If you have ideas on how to fix my problem I would appreicate it. I already tried adding it an inv, then checking it didnt really work, but mabye you can get it to.



Code:
function pricedetect(list: objects, check: object) :: boolean:
    loop {_list::*}:
        set {_forgelist::*} to "%loop-value%" split at " "
        set {_ingredlist::*} to "%{_check}%" split at " "
        if "%{_ingredlist::1}%" parsed as number >= "%{_forgelist::1}%" parsed as number:
            set {_ingredlist::2} to "%{_ingredlist::2}% %{_ingredlist::3}% %{_ingredlist::4}% %{_ingredlist::5}% %{_ingredlist::6}%"
            set {_forgelist::2} to "%{_forgelist::2}% %{_forgelist::3}% %{_forgelist::4}% %{_forgelist::5}% %{_forgelist::6}%"
            delete {_forgelist::3}, {_forgelist::4}, {_forgelist::5}, and {_forgelist::6}
            delete {_ingredlist::3}, {_ingredlist::4}, {_ingredlist::5}, and {_ingredlist::6}

            if {_ingredlist::2} = {_forgelist::2}:
                return true
        else:
            broadcast "incorrect item"
            return false