• 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 think 10 days = 240 hours online in game
I'll use it if someone know how to do.
I tought about this before, but players could logout in front chest, if you know how to check online times pls share

bump

bump
 
Last edited by a moderator:
This has been done many times just recently, using the search function with some choice key words or looking back on this board a little will net you what you want

this is what you need to do
Lua:
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) > (os.time() + 3*24*60*60) then
                doPlayerAddItem(cid, quest, 1)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                setPlayerStorageValue(cid, storage, os.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
   
    return true
end
 
This has been done many times just recently, using the search function with some choice key words or looking back on this board a little will net you what you want

this is what you need to do
Lua:
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) > (os.time() + 3*24*60*60) then
                doPlayerAddItem(cid, quest, 1)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(quest)..'.')
                setPlayerStorageValue(cid, storage, os.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
  
    return true
end

It's too wrong..
You didnt set the variable in array for example:
[8001] = { item = 2485, lvl = 2, days = 2}, -- doublet

You made only a check to every items and this way you show up will break in the same thing the author topic said:
Players will logout makers in front chests and login again latter only to do the quest, he want a way to this quest time dont count offline
 
yeah I didn't read it, too many dumb questions on this board
change script to this
Lua:
local quests = {
    [8000] = { item = 2385, lvl = 1, days = 10 }, -- 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
        local days = quests[item.actionid].days
        if getPlayerFreeCap(cid) >= getItemWeightById(quest, 1) then
            if getPlayerStorageValue(cid,storage) > days 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
in creaturescripts.xml
put
XML:
<event type="logout" name="questslogout" script="quests.lua" />
<event type="login" name="questslogin" script="quests.lua" />
and in quests.lua
Lua:
local quests = {8000,8001,8002,8103}
function onLogin(cid)
    registerCreatureEvent(cid, "questslogout")
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
end
Idk what distro your using so you will have to debug it yourself
 
yeah I didn't read it, too many dumb questions on this board
change script to this
Lua:
local quests = {
    [8000] = { item = 2385, lvl = 1, days = 10 }, -- 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
        local days = quests[item.actionid].days
        if getPlayerFreeCap(cid) >= getItemWeightById(quest, 1) then
            if getPlayerStorageValue(cid,storage) > days 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
in creaturescripts.xml
put
XML:
<event type="logout" name="questslogout" script="quests.lua" />
<event type="login" name="questslogin" script="quests.lua" />
and in quests.lua
Lua:
local quests = {8000,8001,8002,8103}
function onLogin(cid)
    registerCreatureEvent(cid, "questslogout")
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
end
Idk what distro your using so you will have to debug it yourself

Loool it's sounds better then i trough, i was thiking about make a globalevent, it's working on 0.4?
 
yeah I didn't read it, too many dumb questions on this board
change script to this
Lua:
local quests = {
    [8000] = { item = 2385, lvl = 1, days = 10 }, -- 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
        local days = quests[item.actionid].days
        if getPlayerFreeCap(cid) >= getItemWeightById(quest, 1) then
            if getPlayerStorageValue(cid,storage) > days 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
in creaturescripts.xml
put
XML:
<event type="logout" name="questslogout" script="quests.lua" />
<event type="login" name="questslogin" script="quests.lua" />
and in quests.lua
Lua:
local quests = {8000,8001,8002,8103}
function onLogin(cid)
    registerCreatureEvent(cid, "questslogout")
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
end
Idk what distro your using so you will have to debug it yourself

If i want some in hours and some in days i should set:
Code:
[8000] = { item = 2385, lvl = 1, days = 0.04}, -- sabre
???
 
I mean.. there is a way to set days or minutes?

Some quests should be good in 3 days, 30 days, another ones 30 minutes, 1 minute, 120 minutes...

I tried to:
If i want some in hours and some in days i should set:
Code:
[8000] = { item = 2385, lvl = 1, days = 0.04}, -- sabre
???

But return me
[10:52:41.573] [Error - LuaInterface::loadFile] data/actions/scripts/quests.lua:1: unexpected symbol near '0.04'
[10:52:41.573] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests.lua)
[10:52:41.573] data/actions/scripts/quests.lua:1: unexpected symbol near '0.04'
 
I mean.. there is a way to set days or minutes?

Some quests should be good in 3 days, 30 days, another ones 30 minutes, 1 minute, 120 minutes...

I tried to:


But return me
[10:52:41.573] [Error - LuaInterface::loadFile] data/actions/scripts/quests.lua:1: unexpected symbol near '0.04'
[10:52:41.573] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests.lua)
[10:52:41.573] data/actions/scripts/quests.lua:1: unexpected symbol near '0.04'

Use something like this;
Lua:
local quests = {
    [storageId] = { itemid = 1234, time = 10 * 1000 }
}

local quest = quests[item.actionid]
if quest then
    local timeNow = os.time()
    if timeNow - player:getStorageValue(item.actionid) >= 0 then
        player:addItem(quest.itemid)
        player:setStorageValue(item.actionid, timeNow + quest.time)
    else
        -- need to wait
    end
end

Just config the quests table, set the storage value, itemid and the time and it should work.
Now you can use ex mins * 60 * 1000 to make it x mins etc etc
 
Use something like this;
Lua:
local quests = {
    [storageId] = { itemid = 1234, time = 10 * 1000 }
}

local quest = quests[item.actionid]
if quest then
    local timeNow = os.time()
    if timeNow - player:getStorageValue(item.actionid) >= 0 then
        player:addItem(quest.itemid)
        player:setStorageValue(item.actionid, timeNow + quest.time)
    else
        -- need to wait
    end
end

Just config the quests table, set the storage value, itemid and the time and it should work.
Now you can use ex mins * 60 * 1000 to make it x mins etc etc

I think on this way should be unmannaged
There is no way to choose one of mins, hours, days?

For example:
Code:
local quests = {
    [8000] = { item = 2385, lvl = 1, mins = 1}, -- sabre
    [8001] = { item = 2485, lvl = 2, mins = 5}, -- doublet
    [8002] = { item = 2526, lvl = 3, hours = 2}, -- studded shield
    [8103] = { item = 8293, lvl = 200, days = 1}, -- hallowed axe
}
 
I think on this way should be unmannaged
There is no way to choose one of mins, hours, days?

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

It's posible but requires more code, better to just write out the time insted
min = mins * 60 * 1000
hours = hours * 60 * 60 * 1000
days = days * 24 * 60 * 60 * 1000

etc etc
 
It's posible but requires more code, better to just write out the time insted
min = mins * 60 * 1000
hours = hours * 60 * 60 * 1000
days = days * 24 * 60 * 60 * 1000

etc etc

It would make the code heavy?

Because its too more easy take a look and manage on mins,hours,days then *60*1000, *60*60*1000, *24*60*60*1000

Did you know how to
Code:
if choose days then
    time = time * 24 * 60 * 60 * 1000
elseif choose hours then
    time = time * 60 * 60 * 1000
elseif choose min then
     time = time * 60 * 1000
end

On that code?
 
It would make the code heavy?

Because its too more easy take a look and manage on mins,hours,days then *60*1000, *60*60*1000, *24*60*60*1000

Did you know how to
Code:
if choose days then
    time = time * 24 * 60 * 60 * 1000
elseif choose hours then
    time = time * 60 * 60 * 1000
elseif choose min then
     time = time * 60 * 1000
end

On that code?

Well atleast heavier then the one I posted.
And about messing up on the time stamps, sure but this isn't a thing you change often (in most cases) and if it's a big problem just make a couple of global variables ex:
Lua:
MILLISECS_ONE_HOUR = 60 * 60 * 1000
hours = 1 * MILLISECS_ONE_HOUR

You wanna avoid executing the same or more code unless you have to.

To make the code you posted work you need to do this;

Change:
Lua:
player:setStorageValue(item.actionid, timeNow + quest.time)

With:
Lua:
player:setStorageValue(item.actionid, timeNow + time)

And change your if statments to this;
Lua:
local time
if choose days then
    time = quest.time* 24 * 60 * 60 * 1000
elseif choose hours then
    time = quest.time * 60 * 60 * 1000
elseif choose min then
     time = quest.time * 60 * 1000
else
     -- Remember to handle this or set the variable time to a set value, if you were to forget to add a time
end
 
Well atleast heavier then the one I posted.
And about messing up on the time stamps, sure but this isn't a thing you change often (in most cases) and if it's a big problem just make a couple of global variables ex:
Lua:
MILLISECS_ONE_HOUR = 60 * 60 * 1000
hours = 1 * MILLISECS_ONE_HOUR

You wanna avoid executing the same or more code unless you have to.

To make the code you posted work you need to do this;

Change:
Lua:
player:setStorageValue(item.actionid, timeNow + quest.time)

With:
Lua:
player:setStorageValue(item.actionid, timeNow + time)

And change your if statments to this;
Lua:
local time
if choose days then
    time = quest.time* 24 * 60 * 60 * 1000
elseif choose hours then
    time = quest.time * 60 * 60 * 1000
elseif choose min then
     time = quest.time * 60 * 1000
else
     -- Remember to handle this or set the variable time to a set value, if you were to forget to add a time
end

Oh srry, thank you so much, u gave a better way...

Did i made right?
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, 1) then
                local timeNow = os.time()
                if timeNow - player:getStorageValue(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
 
Oh srry, thank you so much, u gave a better way...

Did i made right?
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, 1) then
                local timeNow = os.time()
                if timeNow - player:getStorageValue(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

Yeah that should be fine :)
 
Yeah that should be fine :)

This script is not working here bro, did u know how to fix?
Code:
[11:20:30.316] [Error - Action Interface]
[11:20:30.316] data/actions/scripts/quests.lua:onUse
[11:20:30.316] Description:
[11:20:30.317] data/actions/scripts/quests.lua:28: attempt to compare boolean with number
[11:20:30.317] stack traceback:
[11:20:30.317]    data/actions/scripts/quests.lua:28: in function <data/actions/scripts/quests.lua:14>

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, 1) then
                local timeNow = os.time()
                if timeNow - player:getStorageValue(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
 
This script is not working here bro, did u know how to fix?
Code:
[11:20:30.316] [Error - Action Interface]
[11:20:30.316] data/actions/scripts/quests.lua:onUse
[11:20:30.316] Description:
[11:20:30.317] data/actions/scripts/quests.lua:28: attempt to compare boolean with number
[11:20:30.317] stack traceback:
[11:20:30.317]    data/actions/scripts/quests.lua:28: in function <data/actions/scripts/quests.lua:14>

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, 1) then
                local timeNow = os.time()
                if timeNow - player:getStorageValue(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

Replace this (line 27):
Lua:
if getPlayerFreeCap(cid) >= getItemWeightById(quest, 1) then
with
Lua:
if getPlayerFreeCap(cid) >= getItemWeightById(quest.item, 1) then
 
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...
 
Back
Top