Action TimerQuest with random rewards :D

menfes

Sociopat
Joined
Feb 7, 2009
Messages
380
Best answers
0
Reaction score
4
Location
Space
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
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
 
OP
M

menfes

Sociopat
Joined
Feb 7, 2009
Messages
380
Best answers
0
Reaction score
4
Location
Space
Anyone tried it? Post your comments :)
 

Siin

New Member
Joined
Aug 5, 2009
Messages
135
Best answers
0
Reaction score
0
put instructions :>
 

LoLaye

Active Member
Joined
Dec 23, 2008
Messages
3,774
Best answers
1
Reaction score
43
Location
Sweden
I don't understand why you made this script :/
 

Teddy

SweStream.se
Joined
Oct 2, 2008
Messages
3,798
Best answers
0
Reaction score
10
Location
Sweden 172
its like random box ?
+ how do i set so it only can take the quest 1 in 12 h
 

JDB

OtLand Veteran
Joined
Jun 1, 2009
Messages
4,145
Best answers
2
Reaction score
109
its like random box ?
+ how do i set so it only can take the quest 1 in 12 h
Example:
Lua:
local chestTime = 12 * 24 * 60 -- 12 Hours
local timeLeft = chestTime - os.time() - getPlayerStorageValue(cid, storage)
if (getPlayerStorageValue(cid, storage) > 0 + os.time()) then
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still must wait " .. timeString(timeLeft) .. ".")
	return true
end
Lua:
if (getPlayerStorageValue(cid, storage) <= 0 + os.time()) then
	setPlayerStorageValue(cid, storage, os.time() + chestTime)
	return true
end
 
Last edited:

Teddy

SweStream.se
Joined
Oct 2, 2008
Messages
3,798
Best answers
0
Reaction score
10
Location
Sweden 172
Example:
Lua:
local chestTime = 12 * 24 * 60 -- 12 Hours
local timeLeft = chestTime - os.time() - getPlayerStorageValue(cid, storage)
if (getPlayerStorageValue(cid, storage) > 0 + os.time()) then
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still must wait " .. timeString(timeLeft) .. ".")
	return true
end
Lua:
if (getPlayerStorageValue(cid, storage) <= 0 + os.time()) then
	setPlayerStorageValue(cid, storage, os.time() + chestTime)
	return true
end
Where do i put that ?
 
OP
M

menfes

Sociopat
Joined
Feb 7, 2009
Messages
380
Best answers
0
Reaction score
4
Location
Space
@up
You make a file in data/actions/scripts name it ex. example.lua
Then you open data/actions actions.xml and add
Code:
	<action actionid="xxxx" event="script" value="example.lua"/>
xxxx= number
Now you make a chest on your map with actionid xxxx, and you are done!
P.S Don't forget timeDiff, you find instructions in my first post http://otland.net/f81/timerquest-random-rewards-d-54223/#post547378 and if you want a quest like this with 1 reward and good instructions, look at this http://otland.net/f81/timerquest-quest-timer-53821/

@JDB, just so you know the timeDiff doesn't work correct, when its < 1 min left, its shows like "(space)(space)minutes and X seconds left" (x is a number :))
 
Top