• 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...
os.time() is in seconds not milliseconds
Lua 5.1
Icy04h6.png


Lua 5.2
b66gbjB.png


Lua 5.3
XEEreIb.png
 
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


@Aled and if i had quests from 8000 to 8300, i mean 300 quests.
There is a way to put local quests = {8000 to 8300}
Or do i need to write number by number?
 
if they all have the same reward and days exhaust
Lua:
for i = 8000,8300 do
   quests[i] = {item = xxxx, days = y}
end
go read this then ask your questions
Lua: documentation
I hope you learn a lot, good luck
 
if they all have the same reward and days exhaust
Lua:
for i = 8000,8300 do
   quests[i] = {item = xxxx, days = y}
end
go read this then ask your questions
Lua: documentation
I hope you learn a lot, good luck

No bro, i was talking about the creaturescript:
Code:
local quests = {}

for i = 8000,i < 8300, i++ do
   add.quests i
end

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

I did said about the action script, i was talking about the create script...
I got or u was talking about the creaturescript too?
 
Last edited by a moderator:
I making one by one...

Should have a way to add a list, one by one is sick... No offense.

Is anybody could share the way to dont need to add one by one on creaturscript?

Code:
local quests = {8000,8001,8002,8103,8014,8015,8016,8017}
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

To add something like 8000 to 8017

It would be better because i have something like 500 quests and i could put a value to 1000 quests, so when i need to create a new one, that would be registered there...
 
Last edited by a moderator:
Lua:
local quests = {}
local start = 8000
local _end = 8017
for i = start, _end do
    quests[#quests+1] = i
end
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
 
Lua:
local quests = {}
local start = 8000
local _end = 8017
for i = start, _end do
    quests[#quests+1] = i
end
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

Thank you!
 
Back
Top