roriscrave
Advanced OT User
- Joined
- Dec 7, 2011
- Messages
- 1,188
- Solutions
- 34
- Reaction score
- 200
Hello, I made this code where the player uses a rune that has 300 charges. Each charge will give him 1 crystal coin.
But there is a bug, when there are 2 runes in the backpack.
When I use rune 2, the charge is being deducted from rune 1 (I think it's because it comes first in the backpack).
how do I get discounted from the rune the player used and not the first one in the backpack?
But there is a bug, when there are 2 runes in the backpack.
When I use rune 2, the charge is being deducted from rune 1 (I think it's because it comes first in the backpack).
how do I get discounted from the rune the player used and not the first one in the backpack?
Lua:
function removeCharges (cid, itemID)
local player = Player(cid)
if player then
local checkItem = player:getItemById(itemID, true)
if checkItem:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
local currentCharges = checkItem:getAttribute(ITEM_ATTRIBUTE_CHARGES)
if currentCharges >= 1 then
checkItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, (currentCharges - 1))
player:addItem(2160, 1)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You gained 1 bar.")
addEvent(removeCharges, 1500, player:getId(), itemID)
end
end
end
return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid == 7415 then
removeCharges(player:getId(), item.itemid)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Start Charge Rune.")
end
return true
end