#Player's inventory contians a named item

1 messages · Page 1 of 1 (latest)

dreamy agate
#

How do i check if a player's inventory contains a named item like a diamond named "Test".
i want there to happen somthing if the player has the item and another if he doesn't
i search in google and found this but it didn't work when i added named "Test"
set {_inv} to player's inventory if {_inv} doesn't contains diamonds: message "&c» &7You do not have any &bDiamonds&7!" stop if {_inv} contains diamonds: set {_diamonds} to amount of diamonds in {_inv}

thin bridge
#
if player has diamond named "among us":```
dreamy agate
#

so instead i should just write
if player has diamond named "test":

how do i check if he doesn't have a diamond

thin bridge
#

if player does not have a diamond named "test"

dreamy agate
#

That doesn't work it always do the command as if i have the diamond even thought i don't

thin bridge
#
if player doesn't have 1 diamond:
    send "&c» &7You do not have any &bDiamonds&7!"
else:
    set {_diamonds} to amount of diamonds in player's inventory
    send "&a» &7You have %{_diamonds}% diamonds!"```
ionic flame
#

you could try setting the item you are looking for before checking for it

set {_diamondwithname} to diamond named "Test"
if player has 1 {_diamondwithname}:
dreamy agate
#

This does the same

#

it always thinks i dont have any

thin bridge
#

oh i see

#
if player has 1 diamond:
    set {_diamonds} to amount of diamonds in player's inventory
    send "&a» &7You have %{_diamonds}% diamonds!"
else:
    send "&c» &7You do not have any &bDiamonds&7!"```
dreamy agate
#

This works but not if i add a named

ionic flame
#

Uuuh I know what could cause the issue

#

I think when renaming items on the anvil or by using a rename plugin it adds &r before the name

#

so you'd have to check for diamonds first, then check all of these separately if the name contains the string you are looking for

dreamy agate
thin scarab
#

what seems to be the issue

ionic flame
#

What mc version are you on?

dreamy agate
dreamy agate
ionic flame
#

I've got something that works on 1.16, let me get it real quick, maybe it still works on later versions

thin scarab
#

And player has diamond named "&rtest" does not work?

dreamy agate
#

it doesnt say a mistake but nothing happends

ionic flame
#

I'm guessing it's because there's an invisible extra in the name. Like color codes etc.

thin scarab
dreamy agate
thin scarab
dreamy agate
#

ooh

thin scarab
#

it matches color codes exactly

ionic flame
#

Could you send a screenshot of the item's name?

thin scarab
#

You might have '&f' instead of '&r' accidentally

dreamy agate
ionic flame
#

yeah that might be a &r&n (I think it's n) in front

thin scarab
dreamy agate
thin scarab
#

That's probably diamond named "test"

dreamy agate
ionic flame
#

wait, did you try it with Test before?

#

or test

dreamy agate
thin scarab
thin scarab
dreamy agate
ionic flame
#

That shouldn't be the case tho... I just tried the same thing myself, and when renaming in an anvil, it would just not have color codes at all

#

Weird

dreamy agate
#

do you have a plugin for making colored names i anvils?

ionic flame
#

You can just make a command for renaming items with color. It's actually fairly easy

ionic flame
#

Simple Rename

#

Adds both commands AND anvil compatibility.