Create an item with charge attribute.
Example:

See the description, it'll show only 1 charge.

Show all charges declared in items.xml.
I made a test in Item::getDescription(const ItemType& it, int32_t lookDistance, const Item* item /*= nullptr*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) too see why it's returning 1, because when we set the charge by item:setAttribute(ITEM_ATTRIBUTE_CHARGES), it works fine (you can test it now using enchating.lua in data/actions).

How did you create the item? You may have created it like /i bonfire amulet, 1, which would yield only 1 charge. Try putting it in a monster's loot list and see if it drops with the proper amount of charges.
How did you create the item? You may have created it like
/i bonfire amulet, 1, which would yield only 1 charge. Try putting it in a monster's loot list and see if it drops with the proper amount of charges.
Hey, I tested with monster's loot and it's working fine, thank you. But I think it's very strange, because if we use in some script functions like player:addItem() or Game.createItem(), the charges in items.xml doesn't have any functionality here? Ok... we can use ItemType(id):getCharges() to get these values, but... like I said, I think it's very strange. I'll keep this issue open until someone can explain a little more about this functionality. Again, thank you.
I think it's not a problem, because when the item have charges, count is = charge. See this example:
/i might ring, 94
02:04 You see a might ring (protection physical +20%, energy +20%, earth +20%, fire +20%, ice +20%, holy +20%, death +20%) that has 94 charges left.
in constructor of the file item.cpp you can find this code:
} else if (it.charges != 0) {
if (count != 0) {
setCharges(count);
} else {
setCharges(it.charges);
}
}
EDIT:
I created a function to use as you suggested, please test and tell me what you think.
function Player.addChargeItem(self, itemid, count)
local type = ItemType(itemid)
if type:getCharges() == 0 then
return nil
end
local items = {}
for i = 1, math.max(1, count or 0) do
local item = self:addItem(itemid, type:getCharges())
table.insert(items, item)
end
return #items == 1 and items[1] or items
end
Example
-- add 1 might ring with 20 charges
player:addChargeItem('might ring')
-- add 3 might rings with 20 charges
player:addChargeItem('might ring', 3)
I forgot to check the constructor, thank you. Yeah, maybe I create a custom function to use addItem with charges in multiple quantity. Ty, guys, closing issue.
Most helpful comment
I think it's not a problem, because when the item have charges, count is = charge. See this example:
/i might ring, 94in constructor of the file
item.cppyou can find this code:EDIT:
I created a function to use as you suggested, please test and tell me what you think.
Example