• 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 1.3 Storage time check

Mr Noxi

Noxus Otserver
Joined
May 13, 2010
Messages
272
Solutions
3
Reaction score
94
Location
Sweden
Hey!

So i have a exp scroll that uses storage
Script below for to check how long time the +exp scroll has left.

Lua:
function onSay(cid, words, param)
    local player = Player(cid)

    local remaining = getPlayerStorageValue(cid, 9997) - os.time()
if remaining <= 0 then
        player:sendCancelMessage("You do not have any experience boosts active!")
    else
        
     doCreatureSay(cid, "You have " .. remaining .. " seconds remaining until your extra experience expires.", TALKTYPE_ORANGE_1, true, cid)
    end
    return false
end

First off i would like it to change from seconds to minutes instead since its for 1 hour.
Other then that the script works just fine. Its just showing seconds instead of minutes.



Second issue i have is that i got a global exp booster.

i tried to apply same script above to this other global exp boost also without any success.
Ofc i changed the storage to the storage used by global booster but when i use command to check if any global exp booster is active it says that there is none active.

Global exp boost script

Code:
_GLOBAL_EXP_BOOST_RATE = 0.5 --- rate 2.0 mean 2x exp
_GLOBAL_EXP_BOOST_STORAGE = 66574 --- storage
_GLOBAL_EXP_BOOST_TIME = 1 --- how many hours


local cfg = {
_useEffect = true,
effect = 28
}

function endGlobalExpRate(cid)
        setGlobalStorageValue(cid, _GLOBAL_EXP_BOOST_STORAGE, -1)
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = Player(cid)

if getGlobalStorageValue(_GLOBAL_EXP_BOOST_STORAGE) > 0 then
player:say('Global Exp boost is activated you cant use this scroll at this moment.', TALKTYPE_MONSTER_SAY)
return true
end

if getGlobalStorageValue(_GLOBAL_EXP_BOOST_STORAGE) < os.time() then
setGlobalStorageValue(_GLOBAL_EXP_BOOST_STORAGE, os.time() + _GLOBAL_EXP_BOOST_TIME * 3600)
addEvent(endGlobalExpRate, _GLOBAL_EXP_BOOST_TIME * 3600 * 1000, cid.uid)
broadcastMessage(player:getName() .. " have activated the global exp boost. You will gain + 50% exp rate for 1 hour. Happy Hunting!" , MESSAGE_STATUS_WARNING)
Item(item.uid):remove(1)
if (cfg._useEffect) then
player:getPosition():sendMagicEffect(cfg.effect)
end
end

return true
end
 
So thats fixed! Thank u!

Anyone knows how to convert the seconds to minutes?
Easily. One minute is 60 seconds.
1 minute = 60 seconds.
Lua:
Local isMinutes = remaining > 60
(isMinutes and math.floor((remaining / 60)) or remaining) .. " " .. (isMinutes and "minutes" or "seconds)
Its easy to add check also to print minute instead of minutes if there is one left. I think u will get the pointy.
 
Easily. One minute is 60 seconds.
1 minute = 60 seconds.
Lua:
Local isMinutes = remaining > 60
(isMinutes and math.floor((remaining / 60)) or remaining) .. " " .. (isMinutes and "minutes" or "seconds)
Its easy to add check also to print minute instead of minutes if there is one left. I think u will get the pointy.
how can i add this ?

Lua:
    local isMinutes = remaining > 60
    (isMinutes and math.floor((remaining / 60)) or remaining) .. " " .. (isMinutes and "minutes" or "seconds)
 
how can i add this ?

Lua:
    local isMinutes = remaining > 60
    (isMinutes and math.floor((remaining / 60)) or remaining) .. " " .. (isMinutes and "minutes" or "seconds)
Corrected
local isMinutes = remaining > 60
local timeValue = isMinutes and math.floor((remaining / 60)) or remaining
local timeUnit = isMinutes and "minutes" or "seconds"
print(timeValue .. " " .. timeUnit)
 
or even better:
Lua:
local minutes = math.floor(remaining / 60)
local timeRemaining = minutes > 0
    and ("%d minute%s"):format(minutes, (minutes ~= 1 and "s" or ""))
    or ("%d second%s"):format(remaining, (remaining ~= 1 and "s" or ""))
print(timeRemaining)

older TFS:
Lua:
local minutes = math.floor(remaining / 60)
local timeRemaining = minutes > 0
    and string.format("%d minute%s", minutes, (minutes ~= 1 and "s" or ""))
    or string.format("%d second%s", remaining, (remaining ~= 1 and "s" or ""))
print(timeRemaining)
 
Back
Top