I made this script because Guitar Freak requested it, you can look at this thread http://otland.net/f81/timerquest-quest-timer-53821/ to find out the basics of this TimerQuest script. Anyway, this script allows the player to take 3 random prizes before he gets to wait.
First of all you will need Colandus great function, put this code at the end of your data/lib functions.lua
And here is my script name it to ex. randomtimerquest.lua and put it in your data/actions/scripts folder
First of all you will need Colandus great function, put 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 is my script name it to ex. randomtimerquest.lua and put it in your data/actions/scripts folder
Code:
-- Script made by Menfes
-- Credits to Colandus for the timeDiff function
function onUse(cid, item, fromPosition, itemEx, toPosition)
local itemID = {2127, 2173, 2160} -- IDs of the items, can be how many u want :)
local waitTime = 140 -- Time you have to wait before re-doing the quest in seconds
local storage = xxxxxx -- StorageKey, should be a number
local cancelMessage = {"It is empty, come back in ".. getPlayerStorageValue(cid, storage)-os.time()+(waitTime) .." seconds.",
"It is empty, come back in ".. timeString(getPlayerStorageValue(cid, storage)-os.time()+(waitTime)) .."."
}
local count = 1
local randomChance = math.random(1, #itemID)
if(randomChance == 1) then
count = 1
elseif(randomChance == 2) then
count = 1
end
queststatus = getPlayerStorageValue(cid,storage)
if queststatus == -1 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found " ..getItemDescriptionsById(itemID[randomChance]).article .." "..getItemDescriptionsById(itemID[randomChance]).name.. ".")
doPlayerAddItem(cid, itemID[randomChance], count)
setPlayerStorageValue(cid,storage,1)
elseif queststatus == 1 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found " ..getItemDescriptionsById(itemID[randomChance]).article .." "..getItemDescriptionsById(itemID[randomChance]).name.. ".")
doPlayerAddItem(cid, itemID[randomChance], count)
setPlayerStorageValue(cid,storage,os.time())
end
if queststatus + (waitTime) <= os.time() and queststatus >= 10000 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have found " ..getItemDescriptionsById(itemID[randomChance]).article .." "..getItemDescriptionsById(itemID[randomChance]).name.. ".")
doPlayerAddItem(cid, itemID[randomChance], count)
setPlayerStorageValue(cid,storage,-1)
elseif queststatus >= 10000 and getPlayerStorageValue(cid, storage)-os.time()+(waitTime) <= 60 then
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,cancelMessage[1])
elseif queststatus >= 10000 then
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,cancelMessage[2])
end
end