• 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 Daily Quest (different reward every day)

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,013
Solutions
8
Reaction score
3,055
Location
Netherlands
Tested with TFS 1.0 and TFS 1.1


latest
latest
latest



Every day people can get a different reward from the chest, which reward depens on which day it is.
You can add 1 or more items to 1 day. With more items people will get 1 of those items randomly so they won't always get the same item on a certain day.
It can be used in an actual quest so people can do it more often to get more rewards or be a part of something where people need certain items.


actions.xml
Code:
<action uniqueid="3001" script="quests/dailyquest.lua"/>


dailyquest.lua
Code:
local config = {
     storage = 45392,
     exstorage = 40822,
     days = {
         ["Monday"] = {
             {itemid = 8839, count = {1, 3}}
         },
         ["Tuesday"] = {
             {itemid = 2681, count = {1}},
             {itemid = 2682, count = {1}},
             {itemid = 2683, count = {1}}
         },
         ["Wednesday"] = {
             {itemid = 2674, count = {1, 10}},
             {itemid = 2675, count = {1, 10}},
             {itemid = 2676, count = {1, 10}},
             {itemid = 2673, count = {1, 10}}
         },
         ["Thursday"] = {
             {itemid = 2679, count = {2, 15}},
             {itemid = 2680, count = {1, 5}}
         },
         ["Friday"] = {
             {itemid = 2788, count = {1, 3}}
         },
         ["Saturday"] = {
             {itemid = 6393, count = {1}}
         },
         ["Sunday"] = {
             {itemid = 2389, count = {2, 12}},
             {itemid = 2690, count = {1, 5}}
         }
     }
}

function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
     local player = Player(cid)
     local x = config.days[os.date("%A")]
     if player:getStorageValue(config.storage) == tonumber(os.date("%w")) and player:getStorageValue(config.exstorage) > os.time() then
         return player:sendCancelMessage("The chest is empty, come back tomorrow for a new reward.")
     end
     local c = math.random(#x)
     local info, count = ItemType(x[c].itemid), x[c].count[2] and math.random(x[c].count[1], x[c].count[2]) or x[c].count[1]
     if count > 1 then
         text = count .. " " .. info:getPluralName()
     else
         text = info:getArticle() .. " " .. info:getName()
     end
     local itemx = Game.createItem(x[c].itemid, count)
     if player:addItemEx(itemx) ~= RETURNVALUE_NOERROR then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         text = "You have found a reward weighing " .. itemx:getWeight() .. " oz. It is too heavy or you have not enough space."
     else
         text = "You have received " .. text .. "."
         player:setStorageValue(config.storage, tonumber(os.date("%w")))
         player:setStorageValue(config.exstorage, os.time() + 24*60*60)
     end
     player:sendTextMessage(MESSAGE_INFO_DESCR, text)
     return true
end

For older versions: http://pastebin.com/TJT0uYiT
 
Last edited:
Tested with TFS 1.0


latest



Every day people can get a different reward from the chest, which reward depens on which day it is.
You can add 1 or more items to 1 day. With more items people will get 1 of those items randomly so they won't always get the same item on a certain day.
It can be used in an actual quest so people can do it more often to get more rewards or be a part of something where people need certain items.


actions.xml
Code:
<action uniqueid="3001" script="quests/dailyquest.lua"/>


dailyquest.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
     local config = {
         storage = 45392,
         exstorage = 40822,
         days = {
          ["Monday"] = {
               {itemid = 8839, count = math.random(1, 3)},
           },
           ["Tuesday"] = {
               {itemid = 2681, count = 1},
               {itemid = 2682, count = 1},
               {itemid = 2683, count = 1}
           },
           ["Wednesday"] = {
               {itemid = 2674, count = math.random(1, 10)},
               {itemid = 2675, count = math.random(1, 10)},
               {itemid = 2676, count = math.random(1, 10)},
               {itemid = 2673, count = math.random(1, 10)}
           },
           ["Thursday"] = {
               {itemid = 2679, count = math.random(2, 15)},
               {itemid = 2680, count = math.random(1, 5)},
           },
           ["Friday"] = {
               {itemid = 2788, count = math.random(1, 3)},
           },
           ["Saturday"] = {
               {itemid = 6393, count = 1},
           },
           ["Sunday"] = {
               {itemid = 2389, count = math.random(2, 12)},
               {itemid = 2690, count = math.random(1, 5)},
           }
         }
     }

     local player = Player(cid)
     local x = config.days[os.date("%A")]
     if player:getStorageValue(config.storage) == tonumber(os.date("%w")) and player:getStorageValue(config.exstorage) > os.time() then
         return player:sendCancelMessage("The chest is empty, come back tomorrow for a new reward.")
     end
     local c = math.random(#x)
     local info = ItemType(x[c].itemid)
     if x[c].count > 1 then
         text = x[c].count .. " " .. info:getPluralName()
     else
         text = info:getArticle() .. " " .. info:getName()
     end
     local itemx = Game.createItem(x[c].itemid, x[c].count)
     if player:addItemEx(itemx) ~= RETURNVALUE_NOERROR then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         text = "You have found a reward weighing " .. itemx:getWeight() .. " oz. It is too heavy or you have not enough space."
     else
         text = "You have received " .. text .. "."
         player:setStorageValue(config.storage, tonumber(os.date("%w")))
         player:setStorageValue(config.exstorage, os.time() + 24*60*60)
     end
     player:sendTextMessage(MESSAGE_INFO_DESCR, text)
     return true
end

For older versions: http://pastebin.com/pmAqZ1dC
Whicn one of these two is for 0.4? :) will use this
 
At the bottom there is a pastebin link for older versions, that one will work for TFS 0.4.
 
At the bottom there is a pastebin link for older versions, that one will work for TFS 0.4.
is it working for 0.3.6? :D
EDITED: Working good but may you make it for level? I mean you can't open this chest until you reach level X and if it is possible to make Special level for each prize? Like on Wednesday you can receive 1 item from 5 items but there is special level to get better reward At level 100 you can get 1 from fitst 2 items and at level 150 You can get anyone from those 5 items randomly :p
Btw found error when there isn't space on my backpack :S
Code:
[18/03/2015 10:32:12] [Error - Action Interface]
[18/03/2015 10:32:12] data/actions/scripts/chest.lua:onUse
[18/03/2015 10:32:12] Description:
[18/03/2015 10:32:12] (luaGetItemWeight) Item not found

[18/03/2015 10:32:12] [Error - Action Interface]
[18/03/2015 10:32:12] data/actions/scripts/chest.lua:onUse
[18/03/2015 10:32:12] Description:
[18/03/2015 10:32:12] data/actions/scripts/chest.lua:51: attempt to concatenate a boolean value
[18/03/2015 10:32:12] stack traceback:
[18/03/2015 10:32:12]     data/actions/scripts/chest.lua:51: in function <data/actions/scripts/chest.lua:1>
Thanks and You are the best as usual
 
Last edited:
Well thanks but i need this script level with chance and days at same time like main one :D
what u mean with "level with chance and days at same time like main one "?
cus u can add more values to the table and another line like if x[c].level >= math.random(50, 100) then
 
what u mean with "level with chance and days at same time like main one "?
cus u can add more values to the table and another line like if x[c].level >= math.random(50, 100) then
Like this
["Wednesday"] = {
[1000] = {
{itemid = 2674, count = math.random(1, 10)},
{itemid = 2675, count = math.random(1, 10)},
[100] = {
{itemid = 2676, count = math.random(1, 10)},
{itemid = 2673, count = math.random(1, 10)}
[300] = {
{id = 2152, chance = 70, count = math.random(1, 20)}
{id = 2158, chance = 70, count = math.random(1, 20)}
 
Like this
["Wednesday"] = {
[1000] = {
{itemid = 2674, count = math.random(1, 10)},
{itemid = 2675, count = math.random(1, 10)},
[100] = {
{itemid = 2676, count = math.random(1, 10)},
{itemid = 2673, count = math.random(1, 10)}
[300] = {
{id = 2152, chance = 70, count = math.random(1, 20)}
{id = 2158, chance = 70, count = math.random(1, 20)}
yes u can do it
 
Like this
["Wednesday"] = {
[1000] = {
{itemid = 2674, count = math.random(1, 10)},
{itemid = 2675, count = math.random(1, 10)},
[100] = {
{itemid = 2676, count = math.random(1, 10)},
{itemid = 2673, count = math.random(1, 10)}
[300] = {
{id = 2152, chance = 70, count = math.random(1, 20)}
{id = 2158, chance = 70, count = math.random(1, 20)}
You can do it like in the third script I linked, the variables are named different, but you can use it as example.
In that script the table is rewarditems, in this script the table is x. So instead of rewarditems you use x.
So it will look like this: x[level][c].count
 
You can do it like in the third script I linked, the variables are named different, but you can use it as example.
In that script the table is rewarditems, in this script the table is x. So instead of rewarditems you use x.
So it will look like this: x[level][c].count
Is it possible to fix so sometimes it gives zero items?
 
You can do it like in the third script I linked, the variables are named different, but you can use it as example.
In that script the table is rewarditems, in this script the table is x. So instead of rewarditems you use x.
So it will look like this: x[level][c].count
Alright thanks i will try it
 
Is it possible to fix so sometimes it gives zero items?
On line 41, you can add an if statement with math.random.
Code:
if math.random(10) == 1 then -- 10% chance to fail
     doPlayerSendCancel(cid, "Sorry, no reward today, come back tomorrow.")
     setPlayerStorageValue(cid, config.storage, tonumber(os.date("%w")))
     exhaustion.set(cid, config.exstorage, 24*60*60)
     return true
end
 
Last edited:
The uniqueid is 3001, not the itemid :p
It's just an example though, you can choose any uniqueid you want that is not used yet.
 
The uniqueid is 3001, not the itemid :p
It's just an example though, you can choose any uniqueid you want that is not used yet.
DAMN well can i add a unique id to an item within game? or set it to an action id?
 
Only add the uniqueid you used in actions.xml, so not an actionid since it's not used here.
 
Well done, perfect idea. Would I be able to use it in my project ? :)
 
I don't know which server you use atm but if you use an older version you can use the one from the pastbin link.
 
You think it could work in trunk 3777? or 3884:) @Limos if you could check new thread in support need a little help.
 
Back
Top