• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Request] 2 scripts in need :p

furstwin

Member
Joined
Aug 9, 2007
Messages
511
Reaction score
15
Location
Sweden
Heya all OtLanders :P

As the title says, I need 2 script's for my server..

Script 1:
I saw this in yalahar at real tibia under the warlocks, a player can only open a chest once every hour, and he get's some random items. eg. health pot, mana pot, RoH etc. I'd appericate that script alot ;)

Script 2:
A player will walk in a teleport and get teleported where a BK is, and he need to kill the bk then 3 walls will remove, and he can exit the quest, quite simple I guess :P

Thanks alot,
Furstwin.
 
Last edited:
lib/functions.lua
Code:
-- Time functions: By Far Carder and by Colandus.

function doConvertSeconds(s)
	hours = math.floor(s/60/60)
	minutes = math.floor(s/60) - (60*hours)
	seconds = s - 60 * (minutes + (60*hours))
	return hours, minutes, seconds
end

function getTimeDifference(initialTime, timeNow)
	if (initialTime >= timeNow) then
		return 0, 0, 0
	end
	return doConvertSeconds(os.difftime(timeNow, initialTime))
end

function doConvertTime(hours, minutes, seconds)
	return ((hours or 0)*60*60) + ((minutes or 0)*60) + (seconds or 0)
end

do
	local function getPlural(check)
		return (check ~= 1 and 's') or ''
	end
	
	function getTimeString(hours, minutes, seconds)
		local msg_hours, msg_minutes, msg_seconds
		if ((hours or 0) > 0) then
			msg_hours = hours .. " hour" .. getPlural(hours)
		end
		if ((minutes or 0) > 0) then
			msg_minutes = minutes .. " minute" .. getPlural(minutes)
		end
		if ((seconds or 0) > 0) then
			msg_seconds = seconds .. " second" .. getPlural(seconds)
		end
		if (msg_minutes and msg_hours) then
			if (msg_seconds) then
				msg_minutes = ", " .. msg_minutes
			else
				msg_minutes = " and " .. msg_minutes
			end
		end
		if (msg_seconds and (msg_hours or msg_minutes)) then
			msg_seconds = " and " .. msg_seconds
		end
		return (msg_hours or '') .. (msg_minutes or '') .. (msg_seconds or '')
	end
end

Code:
local items = {
    {itemid, count},
    {itemid, count},
    {itemid, count},
    {itemid, count}
}

local storageValue = 34234
local delay = 1 * 24 * 60 * 60 -- 1 hour

function onUse(cid)
    local lastVisit = getPlayerStorageValue(cid, storageValue)
    if lastVisit == -1 then
        lastVisit = os.time()
    end

    if lastVisit > (os.time() - delay) then
        local randomItem = items[math.random(1, #items)]
        doPlayerAddItem(cid, unpack(randomItem))
    
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You found " .. getItemName(items[1]) .. "!")

        setPlayerStorageValue(cid, storageValue, os.time())
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You can take this quest again in " .. getTimeString(getTimeDifference(lastVisit, os.time())) .. ".")
    end

    return TRUE
end

Though, the time string only works for hours, minutes and seconds :p
 
Last edited:
Back
Top