• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 0.X Bless item not work

fyalhed

Member
Joined
Nov 18, 2017
Messages
156
Reaction score
20
I wanna make a bless using by items, i tried it:
Code:
<action itemid="11260;11259;11261;11262;11258" event="script" value="items_blesses.lua"/>

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   if(item == 11260) then
       if getPlayerBlessing(cid, 1) == true then
           doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You already have this bless!")
           return 1
       end
       doPlayerAddBlessing(cid, 1)
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recived the bless: The Spiritual Shielding!")
       doSendMagicEffect(getCreaturePosition (cid), 2)
   elseif(item == 11259) then
       if getPlayerBlessing(cid, 2) == true then
           doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You already have this bless!")
           return 1
       end
       doPlayerAddBlessing(cid, 2)
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recived the bless: The Embrace of Tibia!")
       doSendMagicEffect(getCreaturePosition (cid), 2)
   elseif(item == 11261) then
       if getPlayerBlessing(cid, 3) == true then
           doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You already have this bless!")
           return 1
       end
       doPlayerAddBlessing(cid, 3)
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recived the bless: The Fire of the Suns!")
       doSendMagicEffect(getCreaturePosition (cid), 2)
   elseif(item == 11262) then
       if getPlayerBlessing(cid, 4) == true then
           doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You already have this bless!")
           return 1
       end
       doPlayerAddBlessing(cid, 4)
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recived the bless: The Wisdom of Solitude!")
       doSendMagicEffect(getCreaturePosition (cid), 2)
   elseif(item == 11258) then
       if getPlayerBlessing(cid, 5) == true then
           doPlayerSendTextMessage (cid, MESSAGE_INFO_DESCR, "You already have this bless!")
           return 1
       end
       doPlayerAddBlessing(cid, 5)
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recived the bless: The Spark of the Phoenix!")
       doSendMagicEffect(getCreaturePosition (cid), 2)
   end
   return true
end

But not is working...
No errors, no work.
 
Solution
the reason it isn't working is cause you're comparing item with a number, not item.itemid (item is a table)
here's how your code can be improved and shortened though
LUA:
local items = {
    [11260] = {text = "Spiritual Shielding", id = 1},
    [11259] = {text = "Embrace of Tibia", id = 2},
    [11261] = {text = "Fire of the Suns", id = 3},
    [11262] = {text = "Wisdom of Solitude", id = 4},
    [11258] = {text = "Spark of the Phoenix", id = 5}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local blessItem = items[item.itemid]
    if blessItem then
        if getPlayerBlessing(cid, blessItem.id) then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already have this bless!")
            return true
        end...
the reason it isn't working is cause you're comparing item with a number, not item.itemid (item is a table)
here's how your code can be improved and shortened though
LUA:
local items = {
    [11260] = {text = "Spiritual Shielding", id = 1},
    [11259] = {text = "Embrace of Tibia", id = 2},
    [11261] = {text = "Fire of the Suns", id = 3},
    [11262] = {text = "Wisdom of Solitude", id = 4},
    [11258] = {text = "Spark of the Phoenix", id = 5}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local blessItem = items[item.itemid]
    if blessItem then
        if getPlayerBlessing(cid, blessItem.id) then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already have this bless!")
            return true
        end
        doPlayerAddBlessing(cid, blessItem.id)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recieved the bless: ".. blessItem.text .. "!")
        doSendMagicEffect(getCreaturePosition(cid), 2)
    end
    return true
end
 
Solution
the reason it isn't working is cause you're comparing item with a number, not item.itemid (item is a table)
here's how your code can be improved and shortened though
LUA:
local items = {
    [11260] = {text = "Spiritual Shielding", id = 1},
    [11259] = {text = "Embrace of Tibia", id = 2},
    [11261] = {text = "Fire of the Suns", id = 3},
    [11262] = {text = "Wisdom of Solitude", id = 4},
    [11258] = {text = "Spark of the Phoenix", id = 5}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local blessItem = items[item.itemid]
    if blessItem then
        if getPlayerBlessing(cid, blessItem.id) then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already have this bless!")
            return true
        end
        doPlayerAddBlessing(cid, blessItem.id)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have recieved the bless: ".. blessItem.text .. "!")
        doSendMagicEffect(getCreaturePosition(cid), 2)
    end
    return true
end

thanks
 
Back
Top