• 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!

TFS 0.X Behemoth Quest give Empty Bag.

Daniel Kopeć

Member
Joined
Dec 8, 2018
Messages
125
Solutions
4
Reaction score
12
Location
Poland
There are no items in the chest bag from Behemoth Quest. TFS 0.4

But there are items in the editor map.
empty bag behemoth quest.png

actions/xml:
XML:
<action actionid="2000" event="script" value="quests/system.lua"/>

actions/scripts/quest/system.lua:

Lua:
local specialQuests = {
    [2001] = 30015 --Annihilator
}

local questsExperience = {
    [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    --[[if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF, cid)
        return true
    end]]

    local storage = specialQuests[item.actionid]
    if(not storage) then
        storage = item.uid
        if(storage > 65535) then
            return false
        end
    end

    if(getPlayerStorageValue(cid, storage) > 0) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local items = {}
    local reward = 0

    local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
        for i = 0, size do
            local tmp = getContainerItem(item.uid, i)
            if(tmp.itemid > 0) then
                table.insert(items, tmp)
            end
        end

    size = table.maxn(items)
    if(size == 1) then
        reward = doCopyItem(items[1], true)
    end

    local result = ""
    if(reward ~= 0) then
        local ret = getItemDescriptions(reward.uid)
        if(reward.type > 0 and isItemRune(reward.itemid)) then
            result = reward.type .. " charges " .. ret.name
        elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
            result = reward.type .. " " .. ret.plural
        else
            result = ret.article .. " " .. ret.name
        end
    else
        if(size > 20) then
            reward = doCopyItem(item, false)
        elseif(size > 8) then
            reward = getThing(doCreateItemEx(1988, 1))
        else
            reward = getThing(doCreateItemEx(1987, 1))
        end

        for i = 1, size do
            local tmp = doCopyItem(items[i], true)
            if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
                print("[Warning] QuestSystem:", "Could not add quest reward")
            else
                local ret = ", "
                if(i == 2) then
                    ret = " and "
                elseif(i == 1) then
                    ret = ""
                end

                result = result .. ret
                ret = getItemDescriptions(tmp.uid)
                if(tmp.type > 0 and isItemRune(tmp.itemid)) then
                    result = result .. tmp.type .. " charges " .. ret.name
                elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
                    result = result .. tmp.type .. " " .. ret.plural
                else
                    result = result .. ret.article .. " " .. ret.name
                end
            end
        end
    end

    if(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
        result = "You have found a reward weighing " .. getItemWeight(reward.uid) .. " oz. It is too heavy or you have not enough space."
    else
        result = "You have found " .. result .. "."
        setPlayerStorageValue(cid, storage, 1)
        if(questsExperience[storage] ~= nil) then
            doPlayerAddExp(cid, questsExperience[storage])
            doSendAnimatedText(getCreaturePosition(cid), questsExperience[storage], TEXTCOLOR_WHITE)
        end
    end

    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
    return true
end

How to fix it ?
 
There are no items in the chest bag from Behemoth Quest. TFS 0.4

But there are items in the editor map.
View attachment 58363

actions/xml:
XML:
<action actionid="2000" event="script" value="quests/system.lua"/>

actions/scripts/quest/system.lua:
Lua:
local specialQuests = {
    [2001] = 30015 --Annihilator
}

local questsExperience = {
    [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    --[[if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF, cid)
        return true
    end]]

    local storage = specialQuests[item.actionid]
    if(not storage) then
        storage = item.uid
        if(storage > 65535) then
            return false
        end
    end

    if(getPlayerStorageValue(cid, storage) > 0) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local items = {}
    local reward = 0

    local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
        for i = 0, size do
            local tmp = getContainerItem(item.uid, i)
            if(tmp.itemid > 0) then
                table.insert(items, tmp)
            end
        end

    size = table.maxn(items)
    if(size == 1) then
        reward = doCopyItem(items[1], true)
    end

    local result = ""
    if(reward ~= 0) then
        local ret = getItemDescriptions(reward.uid)
        if(reward.type > 0 and isItemRune(reward.itemid)) then
            result = reward.type .. " charges " .. ret.name
        elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
            result = reward.type .. " " .. ret.plural
        else
            result = ret.article .. " " .. ret.name
        end
    else
        if(size > 20) then
            reward = doCopyItem(item, false)
        elseif(size > 8) then
            reward = getThing(doCreateItemEx(1988, 1))
        else
            reward = getThing(doCreateItemEx(1987, 1))
        end

        for i = 1, size do
            local tmp = doCopyItem(items[i], true)
            if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
                print("[Warning] QuestSystem:", "Could not add quest reward")
            else
                local ret = ", "
                if(i == 2) then
                    ret = " and "
                elseif(i == 1) then
                    ret = ""
                end

                result = result .. ret
                ret = getItemDescriptions(tmp.uid)
                if(tmp.type > 0 and isItemRune(tmp.itemid)) then
                    result = result .. tmp.type .. " charges " .. ret.name
                elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
                    result = result .. tmp.type .. " " .. ret.plural
                else
                    result = result .. ret.article .. " " .. ret.name
                end
            end
        end
    end

    if(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
        result = "You have found a reward weighing " .. getItemWeight(reward.uid) .. " oz. It is too heavy or you have not enough space."
    else
        result = "You have found " .. result .. "."
        setPlayerStorageValue(cid, storage, 1)
        if(questsExperience[storage] ~= nil) then
            doPlayerAddExp(cid, questsExperience[storage])
            doSendAnimatedText(getCreaturePosition(cid), questsExperience[storage], TEXTCOLOR_WHITE)
        end
    end

    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
    return true
end

How to fix it ?
Didn't took the time to compare the codes but this system.lua should work (it's the one I used on my old 0.3.7)

system.lua
Lua:
local specialQuests = {
    [2001] = 30015 --Annihilator
}

local questsExperience = {
    [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getBooleanFromString(getConfigValue('enableProtectionQuestForGM'))) then
        if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF, cid)
            return true
        end
    end

    local storage = specialQuests[item.actionid]
    if(not storage) then
        storage = item.uid
        if(storage > 65535) then
            return false
        end
    end

    if(getCreatureStorage(cid, storage) > 0) then
    local ret = getItemDescriptions(item.uid)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The " .. ret.name .. " is empty.")
        return true
    end

    local items = {}
    local reward = 0

    local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
    if(size == 0) then
        reward = doCopyItem(item, false)
    else
        for i = 0, size do
            local tmp = getContainerItem(item.uid, i)
            if(tmp.itemid > 0) then
                table.insert(items, tmp)
            end
        end
    end

    size = table.maxn(items)
    if(size == 1) then
        reward = doCopyItem(items[1], true)
    end

    local result = ""
    if(reward ~= 0) then
        local ret = getItemDescriptions(reward.uid)
        if(reward.type > 0 and isItemRune(reward.itemid)) then
            result = reward.type .. " charges " .. ret.name
        elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
            result = reward.type .. " " .. ret.plural
        else
            result = ret.article .. " " .. ret.name
        end
    else
        if(size > 20) then
            reward = doCopyItem(item, false)
        elseif(size > 8) then
            reward = getThing(doCreateItemEx(1988, 1))
        else
            reward = getThing(doCreateItemEx(1987, 1))
        end

        for i = 1, size do
            local tmp = doCopyItem(items[i], true)
            if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
                print("[Warning] QuestSystem:", "Could not add quest reward")
            else
                local ret = ", "
                if(i == 2) then
                    ret = " and "
                elseif(i == 1) then
                    ret = ""
                end

                result = result .. ret
                ret = getItemDescriptions(tmp.uid)
                if(tmp.type > 0 and isItemRune(tmp.itemid)) then
                    result = result .. tmp.type .. " charges " .. ret.name
                elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
                    result = result .. tmp.type .. " " .. ret.plural
                else
                    result = result .. ret.article .. " " .. ret.name
                end
            end
        end
    end

    local ret = getItemDescriptions(reward.uid)
    result = "You have found " .. ret.article .. " " .. ret.name
    if(doPlayerAddItemEx(cid, reward.uid, false) == RETURNVALUE_NOERROR)then
        result = result .. "."
        doCreatureSetStorage(cid, storage, 1)
    else
        result = (getPlayerFreeCap(cid) < getItemWeight(reward.uid)) and result .. ". Weighing " .. getItemWeight(reward.uid) .. " oz it is too heavy." or result .. ", but you have no room to take it."
    end    
        if(questsExperience[storage] ~= nil) then
            doPlayerAddExpEx(cid, questsExperience[storage])
        end

    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, result)
    return true
end
 
Didn't took the time to compare the codes but this system.lua should work (it's the one I used on my old 0.3.7)

system.lua
Lua:
local specialQuests = {
    [2001] = 30015 --Annihilator
}

local questsExperience = {
    [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getBooleanFromString(getConfigValue('enableProtectionQuestForGM'))) then
        if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF, cid)
            return true
        end
    end

    local storage = specialQuests[item.actionid]
    if(not storage) then
        storage = item.uid
        if(storage > 65535) then
            return false
        end
    end

    if(getCreatureStorage(cid, storage) > 0) then
    local ret = getItemDescriptions(item.uid)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The " .. ret.name .. " is empty.")
        return true
    end

    local items = {}
    local reward = 0

    local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
    if(size == 0) then
        reward = doCopyItem(item, false)
    else
        for i = 0, size do
            local tmp = getContainerItem(item.uid, i)
            if(tmp.itemid > 0) then
                table.insert(items, tmp)
            end
        end
    end

    size = table.maxn(items)
    if(size == 1) then
        reward = doCopyItem(items[1], true)
    end

    local result = ""
    if(reward ~= 0) then
        local ret = getItemDescriptions(reward.uid)
        if(reward.type > 0 and isItemRune(reward.itemid)) then
            result = reward.type .. " charges " .. ret.name
        elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
            result = reward.type .. " " .. ret.plural
        else
            result = ret.article .. " " .. ret.name
        end
    else
        if(size > 20) then
            reward = doCopyItem(item, false)
        elseif(size > 8) then
            reward = getThing(doCreateItemEx(1988, 1))
        else
            reward = getThing(doCreateItemEx(1987, 1))
        end

        for i = 1, size do
            local tmp = doCopyItem(items[i], true)
            if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
                print("[Warning] QuestSystem:", "Could not add quest reward")
            else
                local ret = ", "
                if(i == 2) then
                    ret = " and "
                elseif(i == 1) then
                    ret = ""
                end

                result = result .. ret
                ret = getItemDescriptions(tmp.uid)
                if(tmp.type > 0 and isItemRune(tmp.itemid)) then
                    result = result .. tmp.type .. " charges " .. ret.name
                elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
                    result = result .. tmp.type .. " " .. ret.plural
                else
                    result = result .. ret.article .. " " .. ret.name
                end
            end
        end
    end

    local ret = getItemDescriptions(reward.uid)
    result = "You have found " .. ret.article .. " " .. ret.name
    if(doPlayerAddItemEx(cid, reward.uid, false) == RETURNVALUE_NOERROR)then
        result = result .. "."
        doCreatureSetStorage(cid, storage, 1)
    else
        result = (getPlayerFreeCap(cid) < getItemWeight(reward.uid)) and result .. ". Weighing " .. getItemWeight(reward.uid) .. " oz it is too heavy." or result .. ", but you have no room to take it."
    end   
        if(questsExperience[storage] ~= nil) then
            doPlayerAddExpEx(cid, questsExperience[storage])
        end

    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, result)
    return true
end
It doesn't work, i get empty chests from the chest :D
behemoth lol.png
 
It doesn't work, i get empty chests from the chest :D
View attachment 58394
Does it send any error in console? This might be cause because you don't have doCopyItem function in lib/050-function.lua
Try adding it:
Lua:
function doCopyItem(item, attributes)
    local attributes = ((type(attributes) == 'table') and attributes or { "aid" })

    local ret = doCreateItemEx(item.itemid, item.type)
    for _, key in ipairs(attributes) do
        local value = getItemAttribute(item.uid, key)
        if(value ~= nil) then
            doItemSetAttribute(ret, key, value)
        end
    end

    if(isContainer(item.uid)) then
        for i = (getContainerSize(item.uid) - 1), 0, -1 do
            local tmp = getContainerItem(item.uid, i)
            if(tmp.itemid > 0) then
                doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
            end
        end
    end

    return getThing(ret)
end
Or compare/use the 050-function.lua I attached below
If any error shows up, post it here. Regards!
 

Attachments

Does it send any error in console? This might be cause because you don't have doCopyItem function in lib/050-function.lua
Try adding it:
Lua:
function doCopyItem(item, attributes)
    local attributes = ((type(attributes) == 'table') and attributes or { "aid" })

    local ret = doCreateItemEx(item.itemid, item.type)
    for _, key in ipairs(attributes) do
        local value = getItemAttribute(item.uid, key)
        if(value ~= nil) then
            doItemSetAttribute(ret, key, value)
        end
    end

    if(isContainer(item.uid)) then
        for i = (getContainerSize(item.uid) - 1), 0, -1 do
            local tmp = getContainerItem(item.uid, i)
            if(tmp.itemid > 0) then
                doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
            end
        end
    end

    return getThing(ret)
end
Or compare/use the 050-function.lua I attached below
If any error shows up, post it here. Regards!
I have it. It was the first thing I checked then I checked systems.lua and it looks fine too.
So I don't understand why he gets an empty Behemoth Quest bag.

The only question is where is the problem or some mistake :)
 

Similar threads

Back
Top