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

(0.4) Exp Scroll - Configuration

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,402
Solutions
17
Reaction score
150
Location
Brazil
Hi, i have this code below, i want players to have an exp buff for two hours, but when I use another scroll, it appears that there are 4 hours left, how can I fix it? Attached a print


Lua:
local config = {
    rate = 2.0, -- Rate que vai ficar o Scroll.
    time = 2, -- Tempo dado pelo Scroll. 
    storage = 20011
} 

local function endExpRate(cid)
    if not isPlayer(cid) then
        return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft > os.time() then
        local timeTable = os.date('*t', timeLeft - (os.time() + 3600))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.format("You still have %d %s %d %s %d %s left of extra experience.", timeTable.hour, timeTable.hour > 1 and "hours" or "hour", timeTable.min, timeTable.min > 1 and "minutes" or "minute", timeTable.sec, timeTable.sec > 1 and "seconds" or "second"))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
    setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
    addEvent(endExpRate, config.time * 3600 * 1000, cid)
    doRemoveItem(item.uid, 1)
    return true
end
 

Attachments

Hey there,

Your script had another problem it was getting the wrong time, os.time function already returns time in seconds so there's no need to calculate (*1000) and it was causing a longer buff than you expected.
Lua:
local config = {
    rate = 2, -- Rate que vai ficar o Scroll.
    time = 2, -- Tempo dado pelo Scroll.
    storage = 20011
}

local function doTransformTime(s)
   local h = math.floor(s/3600)
   local m = math.floor((s - h * 3600) / 60)
   return h, m, (s - h * 3600) - m * 60
end

local function endExpRate(cid)
    if not isPlayer(cid) then
         return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, config.storage)
    if timeLeft > os.time() then
        local hour, minute, second = doTransformTime(timeLeft - os.time())
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ("You still have " .. hour .. " hour(s), " .. minute .. " minute(s) e " .. second .. " second(s) left of extra experience."))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
    setPlayerStorageValue(cid, config.storage, os.time() + (config.time * 60 * 60))
    addEvent(endExpRate, (config.time * 60 * 60 * 1000), cid)
    doRemoveItem(item.uid, 1)
    return true
end
 
Hey there,

Your script had another problem it was getting the wrong time, os.time function already returns time in seconds so there's no need to calculate (*1000) and it was causing a longer buff than you expected.
Lua:
local config = {
    rate = 2, -- Rate que vai ficar o Scroll.
    time = 2, -- Tempo dado pelo Scroll.
    storage = 20011
}

local function doTransformTime(s)
   local h = math.floor(s/3600)
   local m = math.floor((s - h * 3600) / 60)
   return h, m, (s - h * 3600) - m * 60
end

local function endExpRate(cid)
    if not isPlayer(cid) then
         return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, config.storage)
    if timeLeft > os.time() then
        local hour, minute, second = doTransformTime(timeLeft - os.time())
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ("You still have " .. hour .. " hour(s), " .. minute .. " minute(s) e " .. second .. " second(s) left of extra experience."))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
    setPlayerStorageValue(cid, config.storage, os.time() + (config.time * 60 * 60))
    addEvent(endExpRate, (config.time * 60 * 60 * 1000), cid)
    doRemoveItem(item.uid, 1)
    return true
end
got error in console:

[1/2/2021 18:48:37] >>> Loading expscroll.xml ...[Error - Event::checkScript] Event onThink not found (mods/scripts/expstagescroll.lua)
[1/2/2021 18:48:37] [Error - Event::checkScript] Event onLogin not found (mods/scripts/expstagescroll.lua)
[1/2/2021 18:48:37] (done).
 
Back
Top