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

Lua quest/system.lua problem. Chest give me chest. Uid unwalkable doesnt work.

bury

Active Member
Joined
Jul 27, 2008
Messages
421
Solutions
7
Reaction score
25
I'm using The Forgotten Server - Edited By Cyko V8, version 0.3.6

Quest with normal script works properly, but quest made with RME map editor with Aid = 2000 and Uid = X doesn't work. The chest give another chest:

04:52 You have found a chest.

actions.xml

Code:
 <action actionid="2000" event="script" value="quests/system.lua"/>
<action actionid="2002" event="script" value="quests/system.lua"/>

quests/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
    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

    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

Is not supossed that the item with Uid becomes unwalkable? You can walk on the chests lol.

What is wrong with the system? SOS!
 
Solution
Hey wibben, thanks for your answer.

Now it gives me the item I set in the RME (bag, bp, bp of holding etc) but its always empty. All of them have items inside like boh, magic set (in RME I mean)....

Yeah im pretty sure there was a problem with doCopyItem on 0.3 and maybe even 0.4?
Thats why most servers had 1000 chest scripts, not sure if it can be done in another way via Lua or if you need to fix something in the source code.
Give this a try;
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

And to make chests non walkable;
tfs-old-svn/walkback.lua at master · otland/tfs-old-svn · GitHub
tfs-old-svn/movements.xml at master · otland/tfs-old-svn · GitHub
 
Give this a try;
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

And to make chests non walkable;
tfs-old-svn/walkback.lua at master · otland/tfs-old-svn · GitHub
tfs-old-svn/movements.xml at master · otland/tfs-old-svn · GitHub

Hey wibben, thanks for your answer.

Now it gives me the item I set in the RME (bag, bp, bp of holding etc) but its always empty. All of them have items inside like boh, magic set (in RME I mean)....
 
Hey wibben, thanks for your answer.

Now it gives me the item I set in the RME (bag, bp, bp of holding etc) but its always empty. All of them have items inside like boh, magic set (in RME I mean)....

Yeah im pretty sure there was a problem with doCopyItem on 0.3 and maybe even 0.4?
Thats why most servers had 1000 chest scripts, not sure if it can be done in another way via Lua or if you need to fix something in the source code.
 
Solution
Yeah im pretty sure there was a problem with doCopyItem on 0.3 and maybe even 0.4?
Thats why most servers had 1000 chest scripts, not sure if it can be done in another way via Lua or if you need to fix something in the source code.

Okay, the thing is I made a lot of quests with RME like 30 or something... so I'll make a lot of scripts of all the quests :(

Thanks, WibbenZ

Hey @WibbenZ I realized today there is a 0.4 64 bits version and tried it. My datapack was used in ovh some years ago and the quest/system.lua worked properly. At first without modifying anything I received again a chest in the quests (lol), I used the script u gave and is the same. If the quest is not giving containers it gives you only the first item selected in the RME content (for example, doing the magma set quest, I only received the coat and the boots lol it doesnt give you the second or more item), and if it gives any tipe of container it's always empty.

This new 0.4 64 bits has the code corrupted too? This is the link:

[8.60] The Forgotten Server 0.4

It's weird because it worked properly when I had it on debian :S

(I will post this in that thread too and check if there is any solution)
 
Last edited by a moderator:
Hey @WibbenZ I realized today there is a 0.4 64 bits version and tried it. My datapack was used in ovh some years ago and the quest/system.lua worked properly. At first without modifying anything I received again a chest in the quests (lol), I used the script u gave and is the same. If the quest is not giving containers it gives you only the first item selected in the RME content (for example, doing the magma set quest, I only received the coat and the boots lol it doesnt give you the second or more item), and if it gives any tipe of container it's always empty.

This new 0.4 64 bits has the code corrupted too? This is the link:

[8.60] The Forgotten Server 0.4

It's weird because it worked properly when I had it on debian :S

(I will post this in that thread too and check if there is any solution)

Please read the rules; Rules for the Support board
#2

I reall'y can't say, but if I remember correctly it was a problem with doCopyItem on 0.3 and as I said maybe 0.4.
Thats why people used scripts for all the chests, or atleast 1 and then had an array with the items.

Could maybe be OS related in that case? Highly doubt it tho.
 
Back
Top