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

Action TimerQuest or quest with timer :)

menfes

Sociopat
Joined
Feb 7, 2009
Messages
380
Reaction score
4
Location
Space
!!!TESTED ON TFS 0.3.5pl1!!!
So, i know that there is already some sort of this script, but anyway i found it some kind of buggy and i didn't really understand the example the authors gave :)
That is the reason i made my own, really easy to configue, here it comes:

First of all add this code at the end of your data/lib functions.lua
Code:
function timeString(timeDiff)
    local dateFormat = {
        {"day", timeDiff / 60 / 60 / 24},
        {"hour", timeDiff / 60 / 60 % 24},
        {"minute", timeDiff / 60 % 60},
        {"second", timeDiff % 60}
    }

    local out = {}
    for k, t in ipairs(dateFormat) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    
    return table.concat(out)
end

And here comes my script :D >>Extra explanation: Make a lua file, name it to whatever you want, put it in your data/actions/scripts, copy/paste my code, add this line into your data/actions actions.xml
Code:
	<action uniqueid="xxxx" event="script" value="NameOf YourLuaFile.lua"/>

Code:
--  Script made by Menfes
--	Credits to Darad for helping me with the simple idea about os.time() xD
--	100% credits to the one who made timeDiff >>Colandus<<(its little buggy when it comes to seconds
--	ex.onUse (tibian time) ->00:32 Please come back in  minutes and 30 seconds.
--	(Bug, its 0 minutes, but it still show "minutes")



function onUse(cid, item, fromPosition, itemEx, toPosition)
local waitTime = 5*60   	-- in minutes, if u want seconds, remove *60
local itemName = "a magic ball" -- don't forget the prefix "a" or "an"
local itemId = 7632 		-- the item ID :)
local storage = 123456		-- playerstorage number

--! Nabs don't configure !--
local queststatus = getPlayerStorageValue(cid,storage)
                if queststatus + (waitTime) <= os.time() then
	setPlayerStorageValue(cid,storage,os.time())
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found ".. itemName ..".")
                        doPlayerAddItem(cid,itemId,1)
	elseif getPlayerStorageValue(cid, storage)-os.time()+(waitTime) <= 60 then
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty, come back in ".. getPlayerStorageValue(cid, storage)-os.time()+(waitTime) .." seconds.")
	else
 	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"It is empty, come back in ".. timeString(getPlayerStorageValue(cid, storage)-os.time()+(waitTime)) ..".")
 	end
	return true
	end
 
Last edited:
Nice :) It makes me very happy to see that people are using my functions !

And I guess it was my example you was referring to ? :p
 
Sure, when i see your name I remember that it was your thread :)
Btw, about that small bug, or whatever that is, how to fix that?
So it doesn't show like "Wait minutes and xx seconds."
 
Well that's the whole purpose of it :p Or what you mean ? :S Cuz to me it seems alright ^.-
 
Well that's the whole purpose of it :p Or what you mean ? :S Cuz to me it seems alright ^.-

He means that when it is on 0 minutes instead of showing "Wait 0 minutes and XX seconds", it shows "Wait minutes and XX seconds", well I think thats what he means..

@Topic:

Well done and thanks for posting :thumbup: Been looking for something like this for a while, will learn from it! :)

Keep it up, +Reppek!

Edit: Is it possible to make it like, after you open the chest X amount of times you get the exhaustion (like a randomizer quest, you get 3 random prizes and get the waiting time "exhaustion", then you can try 3 prizes again and so on). Sorry for leeching, I actually tried but Im pretty clueless on that.
 
Last edited:
@up
You really understood my problem :). I will try to make some sort of randomiser, maybe with math.random or something. I didnt really understand what you want so here are some questions:
1) You want the player to get 1 prize/1 use?
2) You want the player to always get 3 prizes before he gets the exhaust?
3) How many prizes should the quest randomize from?
 
hmm... Well the function was supposed to write only "10 seconds" if it is 0 minutes o_O So that's odd...

As you can see in the function it check here:
Lua:
if(v > 0) then

edit: now i see the bug... I'll fix it :p
 
Last edited:
Back
Top