How can i check if an player inventory contains an item from a 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!

Status
Not open for further replies.

JohniClark

Member
Feb 19, 2017
31
2
0
25
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.
 
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.
 
Last edited by a moderator:
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
[doublepost=1493229177,1493229143][/doublepost]but it doesnt work
 
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_language.skript:
on pickup:
    loop {banneditems::*}:
        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::*}
        cancel event
        delete event-entity
        stop

Remember to store items in {banneditems::*} as items, not as strings. What i mean is:
code_language.skript:
add player's tool to {banneditems::*} #Good.
add "%player's tool%" to {banneditems::*} #Bad.
 
Last edited by a moderator:
Remember to store items in {banneditems::*} as items, not as strings. What i mean is:
code_language.skript:
add player's tool to {banneditems::*} #Good.
add "%player's tool%" to {banneditems::*} #Bad.


it says "player`s tool is not an entity type" my code:
[SPOILER="CODE"]
command /cyberitems [<Text>]:
    trigger:
        if arg 1 is "add":
            add player`s tool to {banneditems::*}
            message "&bDas Item &c%player`s tool% &bWurde auf die item Banliste Hintugefügt!"
            stop
[/SPOILER]
 
Couldn't something like this also work?

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.

player`s tool

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

Copy and paste this:

player's tool
 
Last edited by a moderator:
Couldn't something like this also work?
code_language.skript:
on pickup:
    if {banneditems::*} contains event-item:
        remove event-item from event-player's inventory

Not sure if I wrote that correctly since I'm RDP'd through my phone.
It should, but it's known that the contains condition doesn't work well.

I know this is a typo but I died.
It was the auto correct haha.
 
  • Like
Reactions: BrettPlayMC
Status
Not open for further replies.