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

Error when opening chest

Tyson12302

New Member
Joined
Aug 6, 2014
Messages
264
Reaction score
4
I've taken a script which gives you a different reward every day. Heres the script. Whats causing the problem? I've choosen the UID 3004 and i put that in the actions.xml and also on the chest on RME.
Code:
local config = {
     storage = 45392,
     exstorage = 40822,
     days = {
         ["Monday"] = {
             {itemid = 2536, count = {1, 3}}
         },
         ["Tuesday"] = {
             {itemid = 11296, count = {1}}
         },
         ["Wednesday"] = {
             {itemid = 8877, count = {1, 10}}
         },
         ["Thursday"] = {
             {itemid = 11298, count = {2, 15}}
         },
         ["Friday"] = {
             {itemid = 2195, count = {1, 3}}
         },
         ["Saturday"] = {
             {itemid = 8922, count = {1}}
         },
         ["Sunday"] = {
             {itemid = 8910, count = {2, 12}}
         }
     }
}

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

The Error
otland [11/06/2015 19:33:06] data/actions/scripts/quests/dailyquest.lua:30: attempt to call global 'Player' (a nil value)
 
You are using a different server, that script is for TFS 1+.
In the thread there is a pastebin link for older versions.
 
You are using a different server, that script is for TFS 1+.
In the thread there is a pastebin link for older versions.
The older version should work then right? Sorry didn't see it was for TFS 1+

Sorry for the Double Post the "Edit" Button wasnt there. I'm getting this error now
[11/06/2015 19:57:25] [Error - LuaScriptInterface::loadFile] data/actions/scripts/quests/dailyquest.lua:37: ')' expected near ']'
[11/06/2015 19:57:25] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests/dailyquest.lua)
[11/06/2015 19:57:25] data/actions/scripts/quests/dailyquest.lua:37: ')' expected near ']'

Heres the code
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 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 = getItemInfo(x[c].itemid)
     if x[c].count > 1 then
         text = x[c].count .. " " .. info.plural
     else
         text = info.article .. " " .. info.name
     end
     local itemx = doCreateItemEx(x[c].itemid, x[c].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
 
Last edited by a moderator:
The exhaustion function returns false for gods, so the exhaustion only works for normal players.
Updated the link in the thread.
 
Thanks that worked perfectly with a normal player. 1 more question! If i want it to pick a random items between 4 items do i just put all the 4 items in one day and then put "math.random" next to it like this for example
Code:
{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)}
will that code randomly pick one of those items? Also what does the
Code:
(1,10)}
mean?
 
So this code for example will chose only one of the follow correct?
Code:
{itemid = 2681, count = 1},
{itemid = 2682, count = 1},
{itemid = 2683, count = 1}
 
One more thing before you mark this as "Solved" I made a Daily quest with 3 difficulties meaning it as 3 chests. Can i use this code 3 times with different ItemID's chaning the name to "dailyquestv2.lua" and chaning the UID in actions.xml. Will the other chests be working if i do that. thanks
 
Back
Top