Solved amount of item in inventory is not work

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

_PAPER_PLANE_

Member
Jan 21, 2022
41
0
6
When I use "set {_n} to amount of {_item} in inventory," it doesn't work, {_n} remains 0.
I have confirmed that {_item} contains cobblestone block, and I have them in my inventory. If I replace {_item} with cobblestone block, {_n} will display the quantity correctly. There are no error messages, and I don't know where I went wrong.

Here is my code:

Code:
on inventory click:
    event-inventory = (metadata tag "shop" of player):
        cancel event
        set {_item} to type of event-item
        set {_name} to name of event-item
        if event-slot = 14,21 or 30:
            set {price.%player%} to 0.5
        else if event-slot = 10,11,12,13,15,20 or 22:
            set {price.%player%} to 0.3
        else if event-slot = 19:
            set {price.%player%} to 0.2
        else if event-slot = 28,31 or 32:
            set {price.%player%} to 2
        else if event-slot = 29:
            set {price.%player%} to 1
        event-slot = 10,11,12,13,14,15,19,20,21,22,28,29,30,31 or 32
        click action is left mouse button with shift:
            set {_n} to amount of {_item} in inventory of player
            {_n} = 0:
                send "&cyou don't have &e%{_name}%" to player
            else:
                remove {_n} of {_item} from player
                add product({price.%player%}, {_n}) to money of player
 
Last edited:
if you just use event-item would that work?
set {_n} to amount of event-item in inventory of player
 
The reason I first use “set {_item} to type of event-item” is because if I only use event-item, it will display “event-item named … my custom name”. I just want to get the type of item, otherwise it will be different from the original name and cannot be detected.
 
This is all my code
I have translated some Traditional Chinese into English to make it easier for you to read.
Code:
function shop(p: player):
    set metadata tag "shop" of {_p} to chest inventory with 6 row named "&8sell shop"
    set slot 0,1,2,3,4,5,6,7,8,9,17,18,26,27,35,36,44,45,46,47,48,51 and 52 of metadata tag "shop" of {_p} to black stained glass pane named " "
# 1
    set slot 10 of metadata tag "shop" of {_p} to cobblestone named "&r鵝卵石" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 11 of metadata tag "shop" of {_p} to granite named "&r花崗岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 12 of metadata tag "shop" of {_p} to diorite named "&r閃長岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 13 of metadata tag "shop" of {_p} to andesite named "&r安山岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 14 of metadata tag "shop" of {_p} to cobbled deepslate named "&r深板岩碎石" with lore "&bprice: &60.5/個", "", "&eleft click: &fmore option" and "&eshift+left click:&fsell all"
    set slot 15 of metadata tag "shop" of {_p} to tuff named "&r凝灰岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
# 2
    set slot 19 of metadata tag "shop" of {_p} to netherrack named "&r地獄石" with lore "&bprice: &60.2/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 20 of metadata tag "shop" of {_p} to gravel named "&r礫石" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 21 of metadata tag "shop" of {_p} to blackstone named "&r黑石" with lore "&bprice: &60.5/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 22 of metadata tag "shop" of {_p} to basalt named "&r玄武岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
# 3
    set slot 28 of metadata tag "shop" of {_p} to iron ingot named "&r鐵碇" with lore "&bprice: &62/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 29 of metadata tag "shop" of {_p} to copper ingot named "&r銅碇" with lore "&bprice: &61/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 30 of metadata tag "shop" of {_p} to redstone named "&r紅石" with lore "&bprice: &60.5/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 31 of metadata tag "shop" of {_p} to gold ingot named "&r金碇" with lore "&bprice: &62/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 32 of metadata tag "shop" of {_p} to lapis lazuli named "&r青金石" with lore "&bprice: &62/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
# L
    set slot 49 of metadata tag "shop" of {_p} to {customhead::back} named "&cBACK"
    open (metadata tag "shop" of {_p}) to {_p}

function shopoption(p: player, item: item, stone: text, price: number):
    set {stone.%{_p}%} to {_stone}
    set metadata tag "shopoption" of {_p} to chest inventory with 1 row named "&2收購選項"
    set slot 0 of metadata tag "shopoption" of {_p} to {_item} named "&f%{_stone}%" with lore "&bprice: &6%{_price}%" and "&aclick to sell!"
    set slot 1 of metadata tag "shopoption" of {_p} to 16 of {_item} named "&f%{_stone}% ×16" with lore "&bprice: &6%{_price}*16%" and "&aclick to sell!"
    set slot 2 of metadata tag "shopoption" of {_p} to 32 of {_item} named "&f%{_stone}% ×32" with lore "&bprice: &6%{_price}*32%" and "&aclick to sell!"
    set slot 3 of metadata tag "shopoption" of {_p} to 64 of {_item} named "&f%{_stone}% ×64" with lore "&bprice: &6%{_price}*64%" and "&aclick to sell!"
    set slot 7 of metadata tag "shopoption" of {_p} to skull of {_p} named "&emoney: &6%money of {_p}%"
    set slot 8 of metadata tag "shopoption" of {_p} to {customhead::back} named "&cBACK"
    open (metadata tag "shopoption" of {_p}) to {_p}
    play sound "ui_button_click" with volume 0.5 to {_p}

function shopoptionclick(p: player, n: number, item: itemtype, name: text, price: number):
    {_p} has {_n} of {_item}:
        remove {_n} of {_item} from {_p}
        add product({_price}, {_n}) to money of {_p}
        play sound "block_note_block_pling" with volume 1 and pitch 2 to {_p}
        send "&ayou sell &6%{_n}% &6%{_name}% &aand get &6$%product({_price}, {_n})%" to {_p}
        shopoption({_p}, {_item}, {stone.%{_p}%}, {_price})
    else:
        send "&cYou don't have enough items" to {_p}
        play sound "block.note_block.pling" with volume 2 and pitch 0.5 to {_p}

on inventory click:
    event-inventory = (metadata tag "shop" of player):
        cancel event
        set {_item} to type of event-item
        set {_name} to name of event-item
        if event-slot = 14,21 or 30:
            set {price.%player%} to 0.5
        else if event-slot = 10,11,12,13,15,20 or 22:
            set {price.%player%} to 0.3
        else if event-slot = 19:
            set {price.%player%} to 0.2
        else if event-slot = 28,31 or 32:
            set {price.%player%} to 2
        else if event-slot = 29:
            set {price.%player%} to 1
        event-slot = 10,11,12,13,14,15,19,20,21,22,28,29,30,31,32 or 49
        click action is left mouse button with shift:
            set {_n} to amount of (type of event-item) in inventory of player
            {_n} = 0:
                send "&cyou don't have &e%{_name}%" to player
                play sound "block.note_block.pling" with volume 2 and pitch 0.5 to player
            else:
                remove {_n} of {_item} from player
                add product({price.%player%}, {_n}) to money of player
                play sound "block_note_block_pling" with volume 1 and pitch 2 to player
                send "&ayou sell &6%{_n}% &e%{_name}% &aand get &6$%product({price.%player%}, {_n})%" to player
                shop(player)
        else:
            shopoption(player, {_item}, {_name}, {price.%player%})
        event-slot = 49: #BACK
            menushop(player)
            play sound "ui_button_click" with volume 0.5 to player

on inventory click:
    event-inventory = (metadata tag "shopoption" of player):
        cancel event
        set {_item} to type of event-item
        set {_name} to name of event-item
        if event-slot = 8: #BACK
            shop(player)
            play sound "ui_button_click" with volume 0.5 to player
        else if event-slot = 0:
            shopoptionclick(player, 1, {_item}, {_name}, {price.%player%})
        else if event-slot = 1:
            shopoptionclick(player, 16, {_item}, {_name}, {price.%player%})
        else if event-slot = 2:
            shopoptionclick(player, 32, {_item}, {_name}, {price.%player%})
        else if event-slot = 3:
            shopoptionclick(player, 64, {_item}, {_name}, {price.%player%})
 
Last edited:
This is all my code
I have translated some Traditional Chinese into English to make it easier for you to read.
Code:
function shop(p: player):
    set metadata tag "shop" of {_p} to chest inventory with 6 row named "&8sell shop"
    set slot 0,1,2,3,4,5,6,7,8,9,17,18,26,27,35,36,44,45,46,47,48,51 and 52 of metadata tag "shop" of {_p} to black stained glass pane named " "
# 1
    set slot 10 of metadata tag "shop" of {_p} to cobblestone named "&r鵝卵石" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 11 of metadata tag "shop" of {_p} to granite named "&r花崗岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 12 of metadata tag "shop" of {_p} to diorite named "&r閃長岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 13 of metadata tag "shop" of {_p} to andesite named "&r安山岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 14 of metadata tag "shop" of {_p} to cobbled deepslate named "&r深板岩碎石" with lore "&bprice: &60.5/個", "", "&eleft click: &fmore option" and "&eshift+left click:&fsell all"
    set slot 15 of metadata tag "shop" of {_p} to tuff named "&r凝灰岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
# 2
    set slot 19 of metadata tag "shop" of {_p} to netherrack named "&r地獄石" with lore "&bprice: &60.2/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 20 of metadata tag "shop" of {_p} to gravel named "&r礫石" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 21 of metadata tag "shop" of {_p} to blackstone named "&r黑石" with lore "&bprice: &60.5/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 22 of metadata tag "shop" of {_p} to basalt named "&r玄武岩" with lore "&bprice: &60.3/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
# 3
    set slot 28 of metadata tag "shop" of {_p} to iron ingot named "&r鐵碇" with lore "&bprice: &62/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 29 of metadata tag "shop" of {_p} to copper ingot named "&r銅碇" with lore "&bprice: &61/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 30 of metadata tag "shop" of {_p} to redstone named "&r紅石" with lore "&bprice: &60.5/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 31 of metadata tag "shop" of {_p} to gold ingot named "&r金碇" with lore "&bprice: &62/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
    set slot 32 of metadata tag "shop" of {_p} to lapis lazuli named "&r青金石" with lore "&bprice: &62/個", "", "&eleft click: &fmore option" and "&eshift+left click: &fsell all"
# L
    set slot 49 of metadata tag "shop" of {_p} to {customhead::back} named "&cBACK"
    open (metadata tag "shop" of {_p}) to {_p}

function shopoption(p: player, item: item, stone: text, price: number):
    set {stone.%{_p}%} to {_stone}
    set metadata tag "shopoption" of {_p} to chest inventory with 1 row named "&2收購選項"
    set slot 0 of metadata tag "shopoption" of {_p} to {_item} named "&f%{_stone}%" with lore "&bprice: &6%{_price}%" and "&aclick to sell!"
    set slot 1 of metadata tag "shopoption" of {_p} to 16 of {_item} named "&f%{_stone}% ×16" with lore "&bprice: &6%{_price}*16%" and "&aclick to sell!"
    set slot 2 of metadata tag "shopoption" of {_p} to 32 of {_item} named "&f%{_stone}% ×32" with lore "&bprice: &6%{_price}*32%" and "&aclick to sell!"
    set slot 3 of metadata tag "shopoption" of {_p} to 64 of {_item} named "&f%{_stone}% ×64" with lore "&bprice: &6%{_price}*64%" and "&aclick to sell!"
    set slot 7 of metadata tag "shopoption" of {_p} to skull of {_p} named "&emoney: &6%money of {_p}%"
    set slot 8 of metadata tag "shopoption" of {_p} to {customhead::back} named "&cBACK"
    open (metadata tag "shopoption" of {_p}) to {_p}
    play sound "ui_button_click" with volume 0.5 to {_p}

function shopoptionclick(p: player, n: number, item: itemtype, name: text, price: number):
    {_p} has {_n} of {_item}:
        remove {_n} of {_item} from {_p}
        add product({_price}, {_n}) to money of {_p}
        play sound "block_note_block_pling" with volume 1 and pitch 2 to {_p}
        send "&ayou sell &6%{_n}% &6%{_name}% &aand get &6$%product({_price}, {_n})%" to {_p}
        shopoption({_p}, {_item}, {stone.%{_p}%}, {_price})
    else:
        send "&cYou don't have enough items" to {_p}
        play sound "block.note_block.pling" with volume 2 and pitch 0.5 to {_p}

on inventory click:
    event-inventory = (metadata tag "shop" of player):
        cancel event
        set {_item} to type of event-item
        set {_name} to name of event-item
        if event-slot = 14,21 or 30:
            set {price.%player%} to 0.5
        else if event-slot = 10,11,12,13,15,20 or 22:
            set {price.%player%} to 0.3
        else if event-slot = 19:
            set {price.%player%} to 0.2
        else if event-slot = 28,31 or 32:
            set {price.%player%} to 2
        else if event-slot = 29:
            set {price.%player%} to 1
        event-slot = 10,11,12,13,14,15,19,20,21,22,28,29,30,31,32 or 49
        click action is left mouse button with shift:
            set {_n} to amount of (type of event-item) in inventory of player
            {_n} = 0:
                send "&cyou don't have &e%{_name}%" to player
                play sound "block.note_block.pling" with volume 2 and pitch 0.5 to player
            else:
                remove {_n} of {_item} from player
                add product({price.%player%}, {_n}) to money of player
                play sound "block_note_block_pling" with volume 1 and pitch 2 to player
                send "&ayou sell &6%{_n}% &e%{_name}% &aand get &6$%product({price.%player%}, {_n})%" to player
                shop(player)
        else:
            shopoption(player, {_item}, {_name}, {price.%player%})
        event-slot = 49: #BACK
            menushop(player)
            play sound "ui_button_click" with volume 0.5 to player

on inventory click:
    event-inventory = (metadata tag "shopoption" of player):
        cancel event
        set {_item} to type of event-item
        set {_name} to name of event-item
        if event-slot = 8: #BACK
            shop(player)
            play sound "ui_button_click" with volume 0.5 to player
        else if event-slot = 0:
            shopoptionclick(player, 1, {_item}, {_name}, {price.%player%})
        else if event-slot = 1:
            shopoptionclick(player, 16, {_item}, {_name}, {price.%player%})
        else if event-slot = 2:
            shopoptionclick(player, 32, {_item}, {_name}, {price.%player%})
        else if event-slot = 3:
            shopoptionclick(player, 64, {_item}, {_name}, {price.%player%})
I don't think you're supposed to be using two on inventory click: events...