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

Lua Quest time online to do again

newby

Active Member
Joined
Jun 11, 2016
Messages
183
Reaction score
43
I have a idea but idk how to do:
Days to be able to do the quest again

I have this quests.lua script to set min lvl, storage, itemid

But how to add:
exausted days?

I mean
[8000] = { item = 2385, lvl = 1 , days = 10},

And after 10 days online you be able to do the quest again
But need to be days online, else not players will logout makers on chest

quests.lua
Code:
local quests = {
    [8000] = { item = 2385, lvl = 1 }, -- sabre
    [8001] = { item = 2485, lvl = 2 }, -- doublet
    [8002] = { item = 2526, lvl = 3 }, -- studded shield
    [8103] = { item = 8293, lvl = 200 }, -- hallowed axe
}

function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end

function onUse(cid, item, fromPos, item2, toPos)

    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
 
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
 
    if quest then
        local storage = 200000 + item.actionid
        if getPlayerFreeCap(cid) >= getItemWeightById(quest, 1) then
            if getPlayerStorageValue(cid, storage) < 1 then
                doPlayerAddItem(cid, quest, 1)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                setPlayerStorageValue(cid, storage, 1)
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'. It weighs '..getItemWeightById(quest, 1)..'.00 and it is too heavy.')
        end
    end
   
    return true
end
 
Solution
Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher...
I've tried this:
Code:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins }, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                local timeNow = os.time()
                if timeNow - player:getStorageValue(item.actionid) >= 0 then
                if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                    doPlayerAddItem(cid, quest, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'. It weighs '..getItemWeightById(quest, 1)..'.00 and it is too heavy.')
            end
        end
    end
    return true
end

But now, no errors on console, but when i try to open a quest, nothing happen...

Your two if statements break scoping / blocks. Try this:
Lua:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins }, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - player:getStorageValue(item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'. It weighs '..getItemWeightById(quest, 1)..'.00 and it is too heavy.')                   
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end
 
Your two if statements break scoping / blocks. Try this:
Lua:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins }, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - player:getStorageValue(item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'. It weighs '..getItemWeightById(quest, 1)..'.00 and it is too heavy.')                  
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end


Thank you to be helping me...

But not working:
Code:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins }, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'. It weighs '..getItemWeightById(quest, 1)..'.00 and it is too heavy.')                 
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end

Code:
[17:2:24.017] [Error - Action Interface]
[17:2:24.017] data/actions/scripts/quests.lua:onUse
[17:2:24.017] Description:
[17:2:24.017] (luaDoPlayerAddItem) Item not found

[17:2:24.017] [Error - Action Interface]
[17:2:24.017] data/actions/scripts/quests.lua:onUse
[17:2:24.017] Description:
[17:2:24.017] data/lib/050-function.lua:241: attempt to index a boolean value
[17:2:24.017] stack traceback:
[17:2:24.017]    data/lib/050-function.lua:241: in function 'getItemNameById'
[17:2:24.017]    data/actions/scripts/quests.lua:30: in function <data/actions/scripts/quests.lua:13>
 
Thank you to be helping me...

But not working:
Code:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins }, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'. It weighs '..getItemWeightById(quest, 1)..'.00 and it is too heavy.')                
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end

Code:
[17:2:24.017] [Error - Action Interface]
[17:2:24.017] data/actions/scripts/quests.lua:onUse
[17:2:24.017] Description:
[17:2:24.017] (luaDoPlayerAddItem) Item not found

[17:2:24.017] [Error - Action Interface]
[17:2:24.017] data/actions/scripts/quests.lua:onUse
[17:2:24.017] Description:
[17:2:24.017] data/lib/050-function.lua:241: attempt to index a boolean value
[17:2:24.017] stack traceback:
[17:2:24.017]    data/lib/050-function.lua:241: in function 'getItemNameById'
[17:2:24.017]    data/actions/scripts/quests.lua:30: in function <data/actions/scripts/quests.lua:13>

Sorry. I didn't really check the parts I didn't modify and they contained more errors.

Lua:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins }, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')               
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end

Before using it you should also reset player's storage value (or use another player)!
 
Why it's always show chest empty? Even after beeing online the time required and re-logged...

@Ziker @Aled
Did u know?

Code:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')             
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end

creaturescripts
Code:
local quests = {8000,8001,8002,8103}
function onLogin(cid)
    registerCreatureEvent(cid, "questslogout")
    return true
end
function onLogout(cid)
    local lastLogin = getPlayerLastLoginSaved(cid)
    local onlineTime = os.time() - lastLogin or 0
    for i, k in ipairs(quests) do
        if getPlayerStorageValue(cid,k) > 0 then
            setPlayerStorageValue(cid,k,getPlayerStorageValue(cid,k)+onlineTime)
        end
    end
    return true
end
 
Why it's always show chest empty? Even after beeing online the time required and re-logged...

@Ziker @Aled
Did u know?

Code:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')            
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            end
        end
    end
    return true
end

creaturescripts
Code:
local quests = {8000,8001,8002,8103}
function onLogin(cid)
    registerCreatureEvent(cid, "questslogout")
    return true
end
function onLogout(cid)
    local lastLogin = getPlayerLastLoginSaved(cid)
    local onlineTime = os.time() - lastLogin or 0
    for i, k in ipairs(quests) do
        if getPlayerStorageValue(cid,k) > 0 then
            setPlayerStorageValue(cid,k,getPlayerStorageValue(cid,k)+onlineTime)
        end
    end
    return true
end
os.time() is in seconds not milliseconds
change
Lua:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
to
Lua:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
 
os.time() is in seconds not milliseconds
change
Lua:
local mins = 60 * 1000
local hours = 60 * 60 * 1000
local days = 24 * 60 * 60 * 1000
to
Lua:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60

Did you know how to show something like:
06:11 It is empty.
06:11 It is empty (2 days, 14 hours, 5 minutes).
 
Did you know how to show something like:
06:11 It is empty.
06:11 It is empty (2 days, 14 hours, 5 minutes).
change
Lua:
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
for
Lua:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid) > 60*60
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')
 
change
Lua:
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
for
Lua:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid) > 60*60
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')

Code:
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid) > 60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')
            end

Showing:
It is empty, you must wait -0.0016666666666667 days to do it again.
 
post whole script

Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60


local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}

function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end

function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')             
                end
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid) > 60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')
            end
        end
    end
    return true
end
 
yeah sorry I was just being dumb and lazy
change
Lua:
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid) > 60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')
for
Lua:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/days)..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/hours)..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/mins)..' minutes to do it again.')
if it still doesn't work its cause your storage values are fucked or im too tired to think properly right now and ill try again in the morning
 
yeah sorry I was just being dumb and lazy
change
Lua:
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid) > 60*60 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')
for
Lua:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/days)..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/hours)..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/mins)..' minutes to do it again.')
if it still doesn't work its cause your storage values are fucked or im too tired to think properly right now and ill try again in the morning

I dont understand
[6:5:49.283] [Error - LuaInterface::loadFile] data/actions/scripts/quests.lua:42: unexpected symbol near '..'
[6:5:49.283] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests.lua)
[6:5:49.283] data/actions/scripts/quests.lua:42: unexpected symbol near '..'

Why this error?
 
Code:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/days) ..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/hours) ..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/mins) ..' minutes to do it again.')
 
Code:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/days) ..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/hours) ..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/mins) ..' minutes to do it again.')

Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60


local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}

function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end

function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')             
                end
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil((getPlayerStorageValue(cid, item.actionid))-timenow)/mins) ..' minutes to do it again.')
            end
        end
    end
    return true
end

Code:
[21:4:33.316] [Error - LuaInterface::loadFile] data/actions/scripts/quests.lua:42: unexpected symbol near '..'
[21:4:33.316] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests.lua)
[21:4:33.316] data/actions/scripts/quests.lua:42: unexpected symbol near '..'
 
not enough brackets was the problem
Lua:
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/mins) ..' minutes to do it again.')
 
not enough brackets was the problem
Lua:
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timenow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timenow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/mins) ..' minutes to do it again.')

Code:
[0:36:46.541] [Error - Action Interface]
[0:36:46.541] data/actions/scripts/quests.lua:onUse
[0:36:46.541] Description:
[0:36:46.541] data/actions/scripts/quests.lua:41: attempt to perform arithmetic on global 'timenow' (a nil value)
[0:36:46.541] stack traceback:
[0:36:46.542]    data/actions/scripts/quests.lua:41: in function <data/actions/scripts/quests.lua:17>
 
can't you think for yourself?
I used timenow
in your script its timeNow
so change one of them

I had changed this bro, i saw this before, like i saw this:
change
Lua:
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
for
Lua:
elseif getPlayerStorageValue(cid, item.actionid) < 0 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
elseif getPlayerStorageValue(cid, item.actionid) > 24*60*60
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/days..' days to do it again.')
elseif getPlayerStorageValue(cid, item.actionid) > 60*60
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/hours..' hours to do it again.')
else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '..(timeNow - getPlayerStorageValue(cid, item.actionid))/minutes..' minutes to do it again.')


Without thens

This is my script:
Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60


local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}

function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end

function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')             
                end
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid))-timenow)/mins) ..' minutes to do it again.')
            end
        end
    end
    return true
end

This is the error:
Code:
[8:21:53.590] [Error - Action Interface]
[8:21:53.590] data/actions/scripts/quests.lua:onUse
[8:21:53.590] Description:
[8:21:53.590] data/actions/scripts/quests.lua:46: attempt to perform arithmetic on global 'timenow' (a nil value)
[8:21:53.590] stack traceback:
[8:21:53.590]    data/actions/scripts/quests.lua:46: in function <data/actions/scripts/quests.lua:17>

I doing my best i can do, srry if look abusing of your good will
 
Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    [8000] = { item = 2385, lvl = 1, time = 1 * mins}, -- sabre
    [8001] = { item = 2485, lvl = 2, time = 5 * mins}, -- doublet
    [8002] = { item = 2526, lvl = 3, time = 1 * hours}, -- studded shield
    [8103] = { item = 8293, lvl = 200, time = 1 * days}, -- hallowed axe
}
function isLevelRequired(value)
    return type(value) == "table" and true, value.item, value.lvl or false, value
end
function onUse(cid, item, fromPos, item2, toPos)
    local levelRequired, quest, level = isLevelRequired(quests[item.actionid])
    if levelRequired then
        if getPlayerLevel(cid) < level then
            doPlayerSendCancel(cid, "Sorry, level: " .. level .. " or higher to complete this quest.")
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            return true
        end
    end
    if quest then
        local storage = 200000 + item.actionid
        local quest = quests[item.actionid]
        if quest then
            local timeNow = os.time()
            if timeNow - getPlayerStorageValue(cid, item.actionid) >= 0 then
                if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
                    doPlayerAddItem(cid, quest.item, 1)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'.')
                    setPlayerStorageValue(cid, item.actionid, timeNow + quest.time)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest.item)..'. It weighs '..getItemWeightById(quest.item, 1)..'.00 and it is too heavy.')           
                end
            elseif getPlayerStorageValue(cid, item.actionid) < 0 then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > days then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/days) ..' days to do it again.')
            elseif getPlayerStorageValue(cid, item.actionid)-timeNow > hours then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/hours) ..' hours to do it again.')
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is empty, you must wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/mins) ..' minutes to do it again.')
            end
        end
    end
    return true
end
 
Solution
Back
Top