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

TFS 0.X talkaction to show the date you can do the quest again

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
i have this amazing quest system, where players can do quests more then one time, i mean
you can do katana quest on rookgaard each 10 hours, it is working for every quest

quests.lua

Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    -- /data/creaturescripts/quests.lua
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}
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


I tried this, but its not working
/talkactions/scripts/quests.lua
Code:
dofile(getDataDir() .. "actions/scripts/actions.lua")

function onSay(cid, words, param, channel)
    local finalStr = ""
    for q=8000,8200,+1 do
        if quest then
            if getPlayerStorageValue(cid, item.actionid) < 0 then
                local timeToWait
                elseif getPlayerStorageValue(cid, item.actionid)-timeNow > days then
                    timeToWait = 'is in exausted, wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/days) ..' days to do it again.')
                elseif getPlayerStorageValue(cid, item.actionid)-timeNow > hours then
                    timeToWait = 'is in exausted, wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/hours) ..' hours to do it again.')
                else
                    timeToWait = 'is in exausted, wait '.. math.ceil(((getPlayerStorageValue(cid, item.actionid)) - timeNow)/mins) ..' minutes to do it again.')
                end
                finalStr = finalStr .. "[" .. quest.name .. "]: " .. timeToWait .. + "\n"
            end
        end
    end
    doShowTextDialog(cid, 2175, finalStr)
    return true
end

Is anyone could help me to make it work?
 

Mr Trala

Advanced OT User
Joined
Aug 26, 2014
Messages
230
Solutions
12
Reaction score
189
Location
Mexico
Lua:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}

function onSay(cid, words, param, channel)
    local time = os.time()
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        if time - getPlayerStorageValue(cid, q) >= 0 then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You can now do '..storage.name..' quest again!')
        elseif getPlayerStorageValue(cid, q) < 0 then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have never done '..storage.name..' quest! Time to get to it.')
        elseif getPlayerStorageValue(cid, q) - time > days then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.')
        elseif getPlayerStorageValue(cid, q) - time > hours then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.')
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.')
        end
    end
end

Something like this I guess, didn't try it and made it basically how you have it.
 
Last edited:

Akela

Active Member
Joined
Dec 14, 2020
Messages
42
Solutions
2
Reaction score
25
Off topic: is there away for me to delete a post?
I wanted to remove my reply but can only figure out how to change it via Edit.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,610
Solutions
395
Reaction score
3,724
Off topic: is there away for me to delete a post?
I wanted to remove my reply but can only figure out how to change it via Edit.
If you have OtLand premium, that becomes an option.

Regarding OtLand Premium - Information & Questions | OTLand

Alternatively, you can 'report' your own post and ask a mod to remove it.
Assuming the reason for the removal is valid and not petty, they usually honour such requests.
 
OP
OP
zexus

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
i'm so sorry this so long, i didn't know someone was help...
thank you so much for this base...

@Mr Trala
I tried to do something with your base:

Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}

function onSay(cid, words, param, channel)
    local time = os.time()
    local final = ''
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'
        elseif getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'

        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        print(str)
        print(storage.name)
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    print(final)
    doShowTextDialog(cid, 2175, final)
end


but there is a problem:
Code:
str = 'You have never done '..storage.name..' quest! Time to get to it.'
is not working

when should show this message, shows:
Code:
str = 'You can now do '..storage.name..' quest again!'
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,610
Solutions
395
Reaction score
3,724
i'm so sorry this so long, i didn't know someone was help...
thank you so much for this base...

@Mr Trala
I tried to do something with your base:

Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}

function onSay(cid, words, param, channel)
    local time = os.time()
    local final = ''
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'
        elseif getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'

        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        print(str)
        print(storage.name)
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    print(final)
    doShowTextDialog(cid, 2175, final)
end


but there is a problem:
Code:
str = 'You have never done '..storage.name..' quest! Time to get to it.'
is not working

when should show this message, shows:
Code:
str = 'You can now do '..storage.name..' quest again!'
Just a matter of swapping the checks around, to make sure that the player has completed the quest before, before checking if they can do it again.
Lua:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
	[8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
	[8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
	[8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
	[8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
	[8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
	[8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}

function onSay(cid, words, param, channel)
	local time = os.time()
	for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
		local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
		local playerStorage = getPlayerStorageValue(cid, q)
		if playerStorage < 0 then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have never done '..storage.name..' quest! Time to get to it.')		
		elseif time - playerStorage >= 0 then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You can now do '..storage.name..' quest again!')
		elseif playerStorage - time > days then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((playerStorage) - time) / days) ..' days to do the '..storage.name..' quest again.')
		elseif playerStorage - time > hours then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((playerStorage) - time) / hours) ..' hours to do the '..storage.name..' quest again.')
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((playerStorage) - time) / mins) ..' minutes to do the '..storage.name..' quest again.')
		end
	end
	return true
end
 
OP
OP
zexus

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
Just a matter of swapping the checks around, to make sure that the player has completed the quest before, before checking if they can do it again.
Lua:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60
local quests = {
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}

function onSay(cid, words, param, channel)
    local time = os.time()
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local playerStorage = getPlayerStorageValue(cid, q)
        if playerStorage < 0 then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have never done '..storage.name..' quest! Time to get to it.')       
        elseif time - playerStorage >= 0 then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You can now do '..storage.name..' quest again!')
        elseif playerStorage - time > days then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((playerStorage) - time) / days) ..' days to do the '..storage.name..' quest again.')
        elseif playerStorage - time > hours then
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((playerStorage) - time) / hours) ..' hours to do the '..storage.name..' quest again.')
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You must wait '.. math.ceil(((playerStorage) - time) / mins) ..' minutes to do the '..storage.name..' quest again.')
        end
    end
    return true
end


You was right...


I tried to don't need to always need to ctrl+c ctrl+v quests
By loading quests from actions to use on talkactions

To do this i tried:

quests.lua (talkactions)
Code:
dofile(getDataDir() .. "actions/scripts/quests.lua")

function onSay(cid, words, param, channel)
    print(mins)
    print(hours)
    print(days)
    print(quests)
    local time = os.time()
    local final = ''
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'
        elseif time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'


        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    doShowTextDialog(cid, 2175, final)
    return true
end

quest.lua (actions) i remove the local on mins,hours,days,quests:
Code:
mins = 60
hours = 60 * 60
days = 24 * 60 * 60
quests = {
    -- /data/creaturescripts/quests.lua
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}
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

But don't work and on console prints only:
Code:
60
3600
86400
Why?
 
OP
OP
zexus

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
You was right...


I tried to don't need to always need to ctrl+c ctrl+v quests
By loading quests from actions to use on talkactions

To do this i tried:

quests.lua (talkactions)
Code:
dofile(getDataDir() .. "actions/scripts/quests.lua")

function onSay(cid, words, param, channel)
    print(mins)
    print(hours)
    print(days)
    print(quests)
    local time = os.time()
    local final = ''
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'
        elseif time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'


        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    doShowTextDialog(cid, 2175, final)
    return true
end

quest.lua (actions) i remove the local on mins,hours,days,quests:
Code:
mins = 60
hours = 60 * 60
days = 24 * 60 * 60
quests = {
    -- /data/creaturescripts/quests.lua
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}
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

But don't work and on console prints only:
Code:
60
3600
86400
Why?

This script did this same stuff: CreatureEvent - Skills & magic level stages (https://otland.net/threads/skills-magic-level-stages.49165/)
To don't have to reply the same configs everywhere
What do i doing wrong?
 
OP
OP
zexus

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
You was right...


I tried to don't need to always need to ctrl+c ctrl+v quests
By loading quests from actions to use on talkactions

To do this i tried:

quests.lua (talkactions)
Code:
dofile(getDataDir() .. "actions/scripts/quests.lua")

function onSay(cid, words, param, channel)
    print(mins)
    print(hours)
    print(days)
    print(quests)
    local time = os.time()
    local final = ''
    for q in pairs(quests) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'
        elseif time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'


        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    doShowTextDialog(cid, 2175, final)
    return true
end

quest.lua (actions) i remove the local on mins,hours,days,quests:
Code:
mins = 60
hours = 60 * 60
days = 24 * 60 * 60
quests = {
    -- /data/creaturescripts/quests.lua
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}
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

But don't work and on console prints only:
Code:
60
3600
86400
Why?

i don't understand why this one works CreatureEvent - Skills & magic level stages (https://otland.net/threads/skills-magic-level-stages.49165/)
and this mine not, looks same :(
anybody knows?
 
OP
OP
zexus

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
Best guess: something else is using those (poorly named) globals.

Easy to test.

I tried to rename quests to quests_list

data/actions/scripts/quests.lua
Code:
local mins = 60
local hours = 60 * 60
local days = 24 * 60 * 60

quests_list = {
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}
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_list[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_list[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

so on talkactions
Code:
dofile(getDataDir() .. "actions/scripts/quests.lua")

function onSay(cid, words, param, channel)
    local mins = 60
    local hours = 60 * 60
    local days = 24 * 60 * 60

    print("----------")
    print(mins)
    print(hours)
    print(days)
    print("-")
    print(quests_list)
    print("----------")

    local time = os.time()
    local final = ''
    for q in pairs(quests_list) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = quests_list[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'
        elseif time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'


        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    doShowTextDialog(cid, 2175, final)
    return true
end

and on console it prints:
Code:
----------
60
3600
86400
-

----------
 

Akela

Active Member
Joined
Dec 14, 2020
Messages
42
Solutions
2
Reaction score
25
This is a situation where you could have done a more comprehensive test "single pass" test, but it makes sense to focus on the big problem for now:

By using "quest_list" you've greatly reduced the possibility that something is unsetting "quests".
Though for next time, add something to the variable name that will almost certainly make a name that has never been used been used (like "zexus_quest_list"). False positives/negatives caused by names that have been used elsewhere can waste a huge amount of time).

So there might be a typo in the initial setup of the table, or it's not functioning as a global variable.

Test the first part with "print quest_list" (or "print zexus_quest_list" :) immediately after setting it in quests.lua.

If it prints nothing, remove the two comments and the trailing comma and try again.
BTW those should be ok, but a table as a global should be ok too, so now we're considering weird Lua or OT bugs as well as coding issues.
 
OP
OP
zexus

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
This is a situation where you could have done a more comprehensive test "single pass" test, but it makes sense to focus on the big problem for now:

By using "quest_list" you've greatly reduced the possibility that something is unsetting "quests".
Though for next time, add something to the variable name that will almost certainly make a name that has never been used been used (like "zexus_quest_list"). False positives/negatives caused by names that have been used elsewhere can waste a huge amount of time).

So there might be a typo in the initial setup of the table, or it's not functioning as a global variable.

Test the first part with "print quest_list" (or "print zexus_quest_list" :) immediately after setting it in quests.lua.

If it prints nothing, remove the two comments and the trailing comma and try again.
BTW those should be ok, but a table as a global should be ok too, so now we're considering weird Lua or OT bugs as well as coding issues.

You are right, i made another test:

talkaction
Code:
dofile(getDataDir() .. "actions/scripts/quests.lua")

function onSay(cid, words, param, channel)
    local mins = 60
    local hours = 60 * 60
    local days = 24 * 60 * 60

    print("----------")
    print(mins)
    print(hours)
    print(days)
    print("-")
    print(zexus_quest_list)
    print(zexus_two)
    print("----------")

    local time = os.time()
    local final = ''
    for q in pairs(zexus_quest_list) do -- We are looping from 8000 to 8005, so those are the storages that we will check.
        local storage = zexus_quest_list[q] -- In this local we get the information, for example if q is equal to 8000 and you print storage.name you will get "Sabre Rook".
        local str = ''
        if getPlayerStorageValue(cid, q) < 0 then
            str = 'You have never done '..storage.name..' quest! Time to get to it.'
        elseif time - getPlayerStorageValue(cid, q) >= 0 then
            str = 'You can now do '..storage.name..' quest again!'


        elseif getPlayerStorageValue(cid, q) - time > days then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / days) ..' days to do the '..storage.name..' quest again.'
        elseif getPlayerStorageValue(cid, q) - time > hours then
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / hours) ..' hours to do the '..storage.name..' quest again.'
        else
            str = 'You must wait '.. math.ceil(((getPlayerStorageValue(cid, q)) - time) / mins) ..' minutes to do the '..storage.name..' quest again.'
        end
        final = final .. "[" .. storage.name .. "]: " .. str .. "\n\n"
    end
    doShowTextDialog(cid, 2175, final)
    return true
end

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

zexus_two = 2

zexus_quest_list = {
    -- rook
    [8000] = { name = "Sabre Rook", item = 2385, lvl = 1, time = 15 * mins},
    [8001] = { name = "Doublet Rook", item = 2485, lvl = 2, time = 30 * mins},
    [8002] = { name = "Studded Shield Rook", item = 2526, lvl = 3, time = 50 * mins},
    [8003] = { name = "Copper Shield Rook", item = 2530, lvl = 5, time = 3 * hours},
    [8004] = { name = "Legion Helmet Rook", item = 2480, lvl = 5, time = 5 * hours},
    [8005] = { name = "Katana Rook", item = 2412, lvl = 5, time = 10 * hours},
}
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(zexus_quest_list[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 = zexus_quest_list[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

it prints:
Code:
----------
60
3600
86400
-

2
----------
 
Top