print("time to refill")
local weapons_in_backpack = getPlayerItemCount(cid,itemID)-1
if weapons_in_backpack >= 1 then
print("weapons_in_backpack: ".. weapons_in_backpack)
local slotItem = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
if isContainer(slotItem) then
print("container")
for containerSlot = 0, getContainerSize(slotItem) - 1 do
local itemFound = getContainerItem(slotItem, containerSlot)
print("itemFound: " .. itemFound)
if itemFound == itemID then
local charges = getItemAttribute(itemFound.uid, "charges")
print("charges: ".. charges)
-- over charges weapon on hands, refil:
addEvent (
function ()
local item = doCreateItemEx(ItemID, 1)
doItemSetAttribute(item, "charges", charges)
doPlayerAddItemEx(cid, item)
end, 100
)
addEvent (
function ()
doPlayerRemoveItem(cid, itemFound.uid, 1)
end, 150
)
end
end
end