1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can i check if an player inventory contains an item from a list

Discussion in 'Skript' started by JohniClark, Apr 26, 2017.

Thread Status:
Not open for further replies.
  1. JohniClark

    JohniClark Member

    Joined:
    Feb 19, 2017
    Messages:
    31
    Likes Received:
    2
    hello, i have a list called {items} and i want to do a function that checks if the player has one of the items in his inventory if yes remove the items.
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    Just loop all items in the player's inventory, check if your list contains the looped item and then if so remove the looped item from the player's inventory.
     
    #2 ShaneBee, Apr 26, 2017
    Last edited by a moderator: Apr 26, 2017
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    I know this is a typo but I died.
     
    • Agree Agree x 1
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    Could you maybe give me a code?
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    Could you please send me the code i tried like this
    on pickup:
    loop inventory of player:
    if %loop-item% is one of {banneditems::*}:
    remove the loop-item
    --- Double Post Merged, Apr 26, 2017, Original Post Date: Apr 26, 2017 ---
    but it doesnt work
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    You can't use percent signs if you're not in a string. And using string removes item properties like custom name and lore. Use loop-value is event-item instead.
     
  8. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    i changed my post up there please check it again.
     
  9. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    Just realised you're messing it up. Why looping the inventory of the player who picked the item when you can just use event-item instead?
    In any case, what you need to loop is the variable that contains the items.

    Im also dumb for not realising earlier lul

    Also, I can't figure how to destroy an item that's in the ground, so I just set its Age NBT to 6000 to make it instantly despawn. If any of you guys can figure out a better way to approach this please let me know, as i'm also interested now.

    Edit: Nevermind, you can use delete event-entity. Changed the code.


    Code (Skript):
    1. on pickup:
    2.     loop {banneditems::*}:
    3.         1 of event-item is 1 of loop-value #Using 1 of because if for some reason you pickup 23 'banned steaks' it will let you unless you specifically added 23 steaks to {banneditems::*}
    4.         cancel event
    5.         delete event-entity
    6.         stop
    Remember to store items in {banneditems::*} as items, not as strings. What i mean is:
    Code (Skript):
    1. add player's tool to {banneditems::*} #Good.
    2. add "%player's tool%" to {banneditems::*} #Bad.
     
    #9 ShaneBee, Apr 26, 2017
    Last edited by a moderator: Apr 26, 2017
  10. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    Couldn't something like this also work?
    Code (Skript):
    1.  
    2. on pickup:
    3.     if {banneditems::*} contains event-item:
    4.         remove event-item from event-player's inventory
    5.  
    Not sure if I wrote that correctly since I'm RDP'd through my phone.
     
  11. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    Remember to store items in {banneditems::*} as items, not as strings. What i mean is:
    Code (Skript):
    1. add player's tool to {banneditems::*} #Good.
    2. add "%player's tool%" to {banneditems::*} #Bad.
    3.  
    4.  
    5. it says "player`s tool is not an entity type" my code:
    6. [SPOILER="CODE"]
    7. command /cyberitems [<Text>]:
    8.     trigger:
    9.         if arg 1 is "add":
    10.             add player`s tool to {banneditems::*}
    11.             message "&bDas Item &c%player`s tool% &bWurde auf die item Banliste Hintugefügt!"
    12.             stop
    13. [/SPOILER]
     
  12. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    contains only works on texts, if i remember correctly.
    that's not correct. Sorry.

    It also works on testing for an object (although i couldn't even figure out how to use it lol). Anyway, i guess it checks for the exact item (Same quantity), so if you store 1 steak on the variable and there are 32 on the ground, it won't work. I guess.

    You're using the character ` instead of the character ' .

    Copy and paste this:

    player's tool
     
    #12 ShaneBee, Apr 26, 2017
    Last edited by a moderator: Apr 26, 2017
  13. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,181
    Likes Received:
    217
    It should, but it's known that the contains condition doesn't work well.

    It was the auto correct haha.
     
    • Like Like x 1
Thread Status:
Not open for further replies.

Share This Page

Loading...