Item only works if not stacked or named.

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

banduriku

New Member
Apr 15, 2024
5
0
1
26
Hello! I'm trying to create a script for a spice that you hold on your offhand that gets consumed when eating an item. I use lore to detect these custom items. It only seems to work if there is only one of the item in my offhand. If it's stacked or renamed to anything else the script doesn't work. Please help!

Code:
on consume rotten flesh:
    if player's offhand tool is cocoa beans with lore "Coriander":
        remove 1 cocoa beans with lore "Coriander" from player's inventory
        feed the player by 4 beefs
        wait a tick
        remove potion effect of hunger from player's active potion effects
 
To fix the first issue, check the stats of 1 of player's offhand item. If you just check if player's offhand tool is oak log (for example), it'll automatically default to checking if player's tool is exactly 1 oak log.

To get around the second issue, only check the lore of the item, not the exact itemtype. Checking if it's cocoa beans with lore "Coriander": means it won't work if it's cocoa beans with lore "Coriander" named "Beans":, but just checking for any item with the lore "Coriander" should make it work.

Hope this helped!

Code:
on consume of rotten flesh:
    lore of 1 of player's offhand tool contains "Coriander":
        remove 1 of player's offhand tool from player
        feed the player by 4 beefs
        wait 1 tick
        remove potion effect of hunger from player's active potion effects
 
  • Like
Reactions: banduriku
To fix the first issue, check the stats of 1 of player's offhand item. If you just check if player's offhand tool is oak log (for example), it'll automatically default to checking if player's tool is exactly 1 oak log.

To get around the second issue, only check the lore of the item, not the exact itemtype. Checking if it's cocoa beans with lore "Coriander": means it won't work if it's cocoa beans with lore "Coriander" named "Beans":, but just checking for any item with the lore "Coriander" should make it work.

Hope this helped!

Code:
on consume of rotten flesh:
    lore of 1 of player's offhand tool contains "Coriander":
        remove 1 of player's offhand tool from player
        feed the player by 4 beefs
        wait 1 tick
        remove potion effect of hunger from player's active potion effects
Thank you, this is very helpful!

I actually have one more question, is there a way to detect for a player holding an item on either hand? Or will I have to use an if else?