• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Item charges On use does not take charge!

Marvo

New Member
Joined
Sep 24, 2017
Messages
22
Reaction score
0
Location
USA
Hello yes I hope i am posting this in the right section. I need help fixing a script I am trying to make a book of blessings but with charges and no matter what i do i can't seem to make it use charges. I added charges in items.xml ive try the script with doremoveitem(item.uid) and it will just take all charges and not just one! what am i missing?
Lua:
local cfg = {
    bless = { 1, 2, 3, 4, 5 },
    level = 8
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, table.maxn(cfg.bless) do
        if(getPlayerBlessing(cid, cfg.bless[i])) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            doCreatureSay(cid, "You have already been blessed.", TALKTYPE_ORANGE_1)
            return true
        end
    end
    if getPlayerLevel(cid) >= cfg.level then
        for i = 1, table.maxn(cfg.bless) do
            doPlayerAddBlessing(cid, cfg.bless[i])
        end
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYAREA)
        doSendAnimatedText(getCreaturePosition(cid), "BLESSED!", TEXTCOLOR_RED)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have been blessed by the gods.")
    end
    return true
end
 
doRemoveItem(item.uid, 1)
the 2nd parameter is to define how many charges should be taken away. if you don't use it, it removes the whole item.
 
are you actually talking about charges on the item? or the items in a stack
because those two are completely different
 
charges on the item.

Code:
22:46 You see tome of knowledge that has 5 charges left.
It weighs 15.00 oz.
Use this Tome to gain Blessing on each death!.
ItemID: [11128].
Position: [X: 983] [Y: 1025] [Z: 7].
 
Still no luck :( it is okay. I just notice i should add someinfo about server it is 8.60 TFS 0.3.6 I am sorry if tat is why the suggestions have not worked.
 
Thx delusion for the lead. i've been looking for this exact feature.
I rebuild the line for tfs 1.2 functions

only thing is that the item does not automaticaly decay to something else.

so i made this.

for anyone looking for that feature.

Code:
        if item:setAttribute( ITEM_ATTRIBUTE_CHARGES, item:getAttribute(ITEM_ATTRIBUTE_CHARGES) - 1) then
         

        if (item:getAttribute(ITEM_ATTRIBUTE_CHARGES) <= 0)then
            if item:getType():getDecayId() == 0 then
                item:remove()
            else
                item:transform(item:getType():getDecayId())
            end
        end
        -- place action here

        end
 
Last edited:
Back
Top