Action Daily Quest (different reward every day)

Jaed Le Raep

★Gaeming★
Joined
Sep 3, 2007
Messages
1,168
Reaction score
311
This is probably the most amateur way of doing this, but I added in a minimum level requirement for the daily chest so that players can't spam make new characters. All credit to Limos for the entire script, I just added in a small parameter.

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
    
    
     if getPlayerLevel(cid) < 10 then -- Edit level requirement here
         return player:sendCancelMessage("You must be level 10 in order to use this chest.")
     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
 

beenii

Member
Joined
Jul 26, 2010
Messages
460
Solutions
1
Reaction score
15
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: [Lua] Daily Quest - Pastebin.com


how add multiples items on reward?
 

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
217
Solutions
3
Reaction score
20
Location
Hell
Instead of week days, can it be accumulable through the days? I like this script so much, thanks!
 

LIINDI

New Member
Joined
Mar 14, 2018
Messages
78
Solutions
1
Reaction score
3
Are you supposed to map/spawn in the chest or does it appear randomly everyday?
Also how do you know when you got the quest to do it? Will it appear in quest log?

Cool script.
Thanks!
 

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,498
Solutions
45
Reaction score
1,075
Location
Arica - Chile
Are you supposed to map/spawn in the chest or does it appear randomly everyday?
Also how do you know when you got the quest to do it? Will it appear in quest log?

Cool script.
Thanks!

daily quest means a quest that change his content daily, also quest logs reads storage values so yay, you can make them appear in qlog.
 

LIINDI

New Member
Joined
Mar 14, 2018
Messages
78
Solutions
1
Reaction score
3
daily quest means a quest that change his content daily, also quest logs reads storage values so yay, you can make them appear in qlog.

Yeah i understand that but how do people know where the chest will spawn & know how to do the quest if the questlog is inactive? :)
 

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,498
Solutions
45
Reaction score
1,075
Location
Arica - Chile
Yeah i understand that but how do people know where the chest will spawn & know how to do the quest if the questlog is inactive? :)
I think you dont understand the code, the chest will never spawn is some position, its an action script so you should set the action/unique id to the chest somehow. why would they know how to do the quest via questlog? And why questlog would be inactive?
 

LIINDI

New Member
Joined
Mar 14, 2018
Messages
78
Solutions
1
Reaction score
3
I think you dont understand the code, the chest will never spawn is some position, its an action script so you should set the action/unique id to the chest somehow. why would they know how to do the quest via questlog? And why questlog would be inactive?

Haha yeah probably i don't lol. I have the chest as 3001 like original one. Should i now maybe add the chest via map editor somewhere on the map and set it as uniqueID 3001? Trying to learn how to implement it onto my server! =)
 

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
781
Solutions
18
Reaction score
320
Location
Santiago - Chile
Hi, If someone can help me, how can i make player get teleported after receiving reward from quest? Im using the old version of the script (0.4), thanks in advance
Lua:
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)
                local x = config.days[os.date("%A")]
                if getPlayerStorageValue(cid, config.storage) == tonumber(os.date("%w")) and exhaustion.check(cid, config.exstorage) then
                                return doPlayerSendCancel(cid, "The chest is empty, come back tomorrow for a new reward.")
                end
                local c = math.random(#x)
                local info, count = getItemInfo(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.plural
                else
                                text = info.article .. " " .. info.name
                end
                local itemx = doCreateItemEx(x[c].itemid, count)
                if doPlayerAddItemEx(cid, itemx, false) ~= RETURNVALUE_NOERROR then
                                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                                text = "You have found a reward weighing " .. getItemWeight(itemx) .. " oz. It is too heavy or you have not enough space."
                else
                                text = "You have received " .. text .. "."
                                setPlayerStorageValue(cid, config.storage, tonumber(os.date("%w")))
                                exhaustion.set(cid, config.exstorage, 24*60*60)
                end
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
                return true
end
 

Kabo Flow

New Member
Joined
May 17, 2020
Messages
50
Reaction score
4
Location
Mexico
Twitch
KaboFlow18
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: Daily Quest - Pastebin.com (http://pastebin.com/TJT0uYiT)


[03/03/2021 23:56:32] [Error - Action Interface]
[03/03/2021 23:56:32] data/actions/scripts/quests/Daily.lua:eek:nUse
[03/03/2021 23:56:32] Description:
[03/03/2021 23:56:32] data/actions/scripts/quests/Daily.lua:37: attempt to call global 'Player' (a nil value)
[03/03/2021 23:56:32] stack traceback:
[03/03/2021 23:56:32] data/actions/scripts/quests/Daily.lua:37: in function <data/actions/scripts/quests/Daily.lua:36>
 
Top