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

reward quest chest

_M4G0_

Intermediate OT User
Joined
Feb 6, 2016
Messages
550
Solutions
17
Reaction score
108
this script work ok but don't add all reward, receives only the first item
tfs 1.2
LUA:
local rewards = {
    [19001] = {
        storage = 55555,
        items = {
            {itemId = 18415, count = 1},
            {itemId = 18423, count = 1000}
        },
      
    },
  
    [19002] = {
        storage = 55555,
        items = {
            {itemId = 18415, count = 1},
            {itemId = 18423, count = 1000}
        },
      
    },
  
    [19003] = {
        storage = 55555,
        items = {
            {itemId = 18415, count = 1},
            {itemId = 18423, count = 1000}
        },
      
    },
  
    [19004] = {
        storage = 55555,
        items = {
            {itemId = 11400, count = 1},
            {itemId = 18423, count = 1000}
        },
      
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local reward = rewards[item.uid]

    for i = 1, #reward.items do
        local items = reward.items[i]
        if player:getStorageValue(reward.storage) < 1 then
            if player:getFreeCapacity() > item:getWeight(items.itemId, items.count) then
                player:addItem(items.itemId, items.count)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found ".. items.count .." ".. item:getName(items.itemId) ..".")
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
                player:setStorageValue(reward.storage, 1)
            else  
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found ".. item:getName(items.itemId) .." but has ".. item:getWeight(items.itemId, items.count) .." free capacity.")
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The chest is empty.")
        end
    end
     return true
end
 
Last edited:
Solution
X
This is the original script without the changes i tried, but i don't know how to add 2 items
LUA:
local t = {
storage = 55555, -- Storage utilizada na quest.
[19001] = {reward = 18423, count = 100}, -- Aqui você coloca [uniqueid] = {reward = IDDOITEM, count = QUANTIDADE}.
[19002] = {reward = 18423, count = 100},
[19003] = {reward = 18423, count = 100},
[19004] = {reward = 18423, count = 1000}
}


function onUse(cid, item)
    local actions = t[item.uid]
    if actions then
       if getPlayerStorageValue(cid, t.storage) < 1 then
          if getPlayerFreeCap(cid) > getItemWeight(actions.reward, actions.count) then
             doPlayerAddItem(cid, actions.reward, actions.count)
             doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found...
This script has a lot of issues beyond only giving you the one item.
I'd suggest finding another script.

If your curious though..

The script loops through the reward table, based on the chest you click.
It then proceeds to check if you've completed the quest before
and if you have enough capacity to receive the item.

On the first item, everything goes through fine, and you receive the item and receive the reward storage.
On the second item, you've already 'completed the quest' so you get nothing.

--
Also be careful with the amount of items you are attempting to give players.
You can't get stacks of 1000, and 1000 of an item that is not stackable, is likely to completely fill all of someone's available backpack space.
 
This script has a lot of issues beyond only giving you the one item.
I'd suggest finding another script.

If your curious though..

The script loops through the reward table, based on the chest you click.
It then proceeds to check if you've completed the quest before
and if you have enough capacity to receive the item.

On the first item, everything goes through fine, and you receive the item and receive the reward storage.
On the second item, you've already 'completed the quest' so you get nothing.

--
Also be careful with the amount of items you are attempting to give players.
You can't get stacks of 1000, and 1000 of an item that is not stackable, is likely to completely fill all of someone's available backpack space.

This is the original script without the changes i tried, but i don't know how to add 2 items
LUA:
local t = {
storage = 55555, -- Storage utilizada na quest.
[19001] = {reward = 18423, count = 100}, -- Aqui você coloca [uniqueid] = {reward = IDDOITEM, count = QUANTIDADE}.
[19002] = {reward = 18423, count = 100},
[19003] = {reward = 18423, count = 100},
[19004] = {reward = 18423, count = 1000}
}


function onUse(cid, item)
    local actions = t[item.uid]
    if actions then
       if getPlayerStorageValue(cid, t.storage) < 1 then
          if getPlayerFreeCap(cid) > getItemWeight(actions.reward, actions.count) then
             doPlayerAddItem(cid, actions.reward, actions.count)
             doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found ".. actions.count .." ".. getItemName(actions.reward) ..".")
             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED)
             setPlayerStorageValue(cid, t.storage, 1)
          else
             doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found ".. getItemName(actions.reward) .." but has ".. getItemWeight(actions.reward, actions.count) .." free capacity.")
          end
       else
          doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The chest is empty.")
       end
    end
   return true
end
 
This is the original script without the changes i tried, but i don't know how to add 2 items
LUA:
local t = {
storage = 55555, -- Storage utilizada na quest.
[19001] = {reward = 18423, count = 100}, -- Aqui você coloca [uniqueid] = {reward = IDDOITEM, count = QUANTIDADE}.
[19002] = {reward = 18423, count = 100},
[19003] = {reward = 18423, count = 100},
[19004] = {reward = 18423, count = 1000}
}


function onUse(cid, item)
    local actions = t[item.uid]
    if actions then
       if getPlayerStorageValue(cid, t.storage) < 1 then
          if getPlayerFreeCap(cid) > getItemWeight(actions.reward, actions.count) then
             doPlayerAddItem(cid, actions.reward, actions.count)
             doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found ".. actions.count .." ".. getItemName(actions.reward) ..".")
             doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED)
             setPlayerStorageValue(cid, t.storage, 1)
          else
             doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have found ".. getItemName(actions.reward) .." but has ".. getItemWeight(actions.reward, actions.count) .." free capacity.")
          end
       else
          doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The chest is empty.")
       end
    end
   return true
end
Install this.
Give player infinite items from table, with 1 small function.

Use this.
LUA:
local rewards = {
    [19001] = {storage = 55555, items = { {18415, 1}, {18423, 100} }},
    [19002] = {storage = 55555, items = { {18415, 1}, {18423, 100} }},
    [19003] = {storage = 55555, items = { {18415, 1}, {18423, 100} }},
    [19004] = {storage = 55555, items = { {11400, 1}, {18423, 100} }}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local x = t[item.uid]
    if x then
        if getPlayerStorageValue(cid, x.storage) < 1 then
            if giveItemsFromTable(cid, x.items) == true then
                setPlayerStorageValue(cid, x.storage, 1)
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "The chest is empty.")
        end
    end
    return true
end
 
Solution
Back
Top