How can I figure out what slot number a custom item is in? (trying to remove a custom item)

Discussion in 'CommandHelper' started by malon, Apr 25, 2017.

  1. malon

    malon Member

    I'm really struggling to figure out how to decrement a custom item from a players inventory.

    Essentially, I'm trying to give a redeemable voucher.

    voucher give code (this works fine). It basically gives the player a piece of paper with a custom name and lore.
    Code (Text):

    voucher:/voucher $plr = >>>

        @plr = $plr
        @plr = player(@plr)

        @date = simple_date('EEE, MMM d yyyy')
        @date1 = simple_date('hh:mm aaa z',time(),'CST')

        @name = color(gold).'Voucher'
        @lore = array(
                    color(red).'Voucher created on ',
                    color(yellow)[email protected](red).' at '.color(yellow)[email protected],
                    color(red).' for '.color(yellow)[email protected]

        @meta = associative_array()
        @meta['display'] = @name
        @meta['lore'] = @lore

        tmsg(@plr,color(red).'Please redeem this voucher with the secretary!')
    How can I test if a player has that item in their inventory and then subtract 1 from the total qty, regardless of what slot it's in?
  2. PseudoKnight

    PseudoKnight Well-Known Member Developer

    foreach(@slot: @item in pinv(@plr)) {
      if(@item && @item['meta'] && @item['meta']['display'] == color('GOLD').'Voucher') {
        // here you can optionally parse and verify any lore information
        @inv = array();
        if([email protected]item['qty'] > 0) {
          @inv[@slot] = @item;
        } else {
          @inv[@slot] = null;
        set_pinv(@plr, @inv);
  3. malon

    malon Member

    Thank you! the trick was "foreach(@slot: @item in pinv(@plr))"

    I had no idea you could do the @slot part thank you