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

Action [TFS 1.X] Reward Chest

Elwyn

Well-Known Member
Joined
Aug 24, 2014
Messages
212
Reaction score
76
It's meant to help mappers who doesn't know Lua, so they can make their quest chest reward without the help of scripters.

Create a reward.lua at actions/scripts and copy-paste the following code:
Code:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
   local chest = Container(item.uid)
   local player = Player(cid)
   if not chest or not player then
     return true
   end

   local uniqueid = chest:getUniqueId()
   if player:getStorageValue(uniqueid) == -2 then
     player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
     return true
   end

   local start = player:getStorageValue(uniqueid) == -1 and 0 or player:getStorageValue(uniqueid)
   for i = start, chest:getSize() do
     local reward = chest:getItem(i)
     if not reward then
       break
     end

     local rewardWeight = reward.getWeight and reward:getWeight() or ItemType(reward:getId()):getWeight(reward:getCount())
     if rewardWeight > player:getFreeCapacity() then
       player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. rewardWeight/100 .. ' oz it\'s too heavy.')
       player:setStorageValue(uniqueid, i)
       break
     else
       reward = reward:clone()
       if player:addItemEx(reward) ~= RETURNVALUE_NOERROR then
         player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. rewardWeight/100 .. ' oz it\'s too heavy.')
         break
       end

       local reward_msg = reward:getArticle() .. ' ' .. reward:getName()
       if reward:getCount() > 1 then
         reward_msg = reward:getCount() .. ' ' .. reward:getPluralName()
       end

       player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found ' .. reward_msg .. '.')

       player:setStorageValue(uniqueid, -2)
     end
   end

   return true
end
Then register at actions.xml using the following tag:

Code:
  <action actionid="15000" script="reward.lua"/>

To use it, when mapping your quest, create a chest and change its actionid to 15000 and give a uniqueid to it. Remember to not use a uniqueid that's already in use, and only use uniqueid whose the storage of the same value is not being used.

If you use the same uniqueid for two different chests, you'll get a warning when starting up the server and the player will only be able to open one of the two chests.
 
Last edited:
It's meant to help mappers who doesn't know Lua, so they can make their quest chest reward without the help of scripters.

Create a reward.lua at actions/scripts and copy-paste the following code:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chest = Container(item.uid)

    if not chest then
        return true
    end

    local uniqueid = chest:getUniqueId()
    if player:getStorageValue(uniqueid) == -2 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
        return true
    end

    local size = chest:getSize()
    local reward = nil

    local start = player:getStorageValue(uniqueid) == -1 and 0 or player:getStorageValue(uniqueid)

    for i = start, size do
        reward = chest:getItem(i)
        if not reward then
            break
        end

        if reward:getWeight() > player:getFreeCapacity() then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. ' weighing ' .. reward:getWeight()/100 .. ' oz it\'s too heavy.')
            player:setStorageValue(uniqueid, i)
            break
        else
            local reward_container = Container(reward:getUniqueId())
            if reward_container then
                reward_container = reward_container:clone()
                reward_container:moveTo(player)
            else
                player:addItem(reward:getId(), 1)
            end
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. reward:getName() .. '.')

            player:setStorageValue(uniqueid, -2)
        end
    end

    return true
end
Then register at actions.xml using the following tag:

Code:
  <action actionid="15000" script="reward.lua"/>

To use it, when mapping your quest, create a chest and change its actionid to 15000 and give a uniqueid to it. Remember to not use a uniqueid that's already in use, and only use uniqueid whose the storage of the same value is not being used.

If you use the same uniqueid for two different chests, you'll get a warning when starting up the server and the player will only be able to open one of the two chests.
Hmm but i think this one is more easier than yours :p
Code:
local specialQuests = {
    [2001] = 30015,    --Annihilator
    [2002] = 30016,
    [2010] = 30017
}

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
:p But its great work from you, Keep going
 
Hmm but i think this one is more easier than yours :p
Code:
local specialQuests = {
    [2001] = 30015,    --Annihilator
    [2002] = 30016,
    [2010] = 30017
}

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
:p But its great work from you, Keep going
LOL the thread creator made that script for 1.1
 
My bad. I forgot to put it on the title when I sent.
 
My bad. I forgot to put it on the title when I sent.
could you help me a bit with this im kind of lost with 1.1 i have your scipt implemented but where can i get uid's and how do i set them up so that they give me the right items? @Tarek1337
maybe you could hel p me bud?
 
Last edited:
Put a chest, or any container, on the map using your map editor. Put actionid 15000 on that chest/container, and an uniqueid that's not in use and that the storage is not in use too, then you put what you want to give as reward inside the chest/container.
 
Put a chest, or any container, on the map using your map editor. Put actionid 15000 on that chest/container, and an uniqueid that's not in use and that the storage is not in use too, then you put what you want to give as reward inside the chest/container.
i did that but i dont know how to set the unique id's how can i find them and how can i apply them so that they register when i use them on aitem as of now the item just spawns in the chest and once taken it is gone untill server is restarted anyhelp would be great
 
Using the map editor, when you select an item clicking with your right mouse button, there's an "Properties" option, click it. A popup will appear with some informations, one of them are Action ID and Unique ID, you have to change them.
 
Using the map editor, when you select an item clicking with your right mouse button, there's an "Properties" option, click it. A popup will appear with some informations, one of them are Action ID and Unique ID, you have to change them.
yes i did that :/ but now i notice that im getting this console error any ideas what i can do?
EpyafT.png
 
Back
Top