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

Double XP issue

jeffaklumpen

Member
Joined
Jan 20, 2022
Messages
76
Solutions
2
Reaction score
15
GitHub
jeffaklumpen
I have a scroll that when activated gives 2x xp for 2 hours.

Lua:
local config = {
    rate = 2,
    storage = 1000,
    expstorage = 1100,
    register = 1200,
    time = 7200,
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStorageValue(cid, config.storage) <= 0 and getStorage(3000) == -1 then
        local rates = getPlayerRates(cid)
        setPlayerStorageValue(cid, config.expstorage, rates[SKILL__LEVEL])
        setPlayerStorageValue(cid, config.register, 1)
        itemEx=itemid == 9004
        doCreatureSay(cid, "Your extra experience rate has been activated! It now is: " .. config.rate .. "x added to your former experience rate.", TALKTYPE_ORANGE_1, true, cid)
        setPlayerStorageValue(cid, config.storage, os.time()+config.time)
        doPlayerSetExperienceRate(cid, rates[SKILL__LEVEL]*config.rate)
        doRemoveItem(item.uid,1)
        registerCreatureEvent(cid, "ExpStage")
    elseif getStorage(3000) == 1 then
        doCreatureSay(cid, "You cannot activate the experience tome during a double XP event.", TALKTYPE_ORANGE_1, true, cid)
    else
        doCreatureSay(cid, "You already have a experience tome active!", TALKTYPE_ORANGE_1, true, cid)
    end
return true
end
function onThink(cid, interval)
    if getPlayerStorageValue(cid, config.register) == 1 then
        if getPlayerStorageValue(cid, config.storage) <= os.time() then
            doCreatureSay(cid, "Your extra experience rate has finished! It is now normaly experience rate.", TALKTYPE_ORANGE_1, true, cid)
            setPlayerStorageValue(cid, config.storage, 0)
            setPlayerStorageValue(cid, config.register, 0)
            local oldexp = getPlayerStorageValue(cid, config.expstorage)
            doPlayerSetExperienceRate(cid, oldexp)
            unregisterCreatureEvent(cid, "ExpStage")
        elseif getStorage(3000) == 1 then
            doCreatureSay(cid, "As the double XP event activates the effecs from the experience scroll fades.", TALKTYPE_ORANGE_1, true, cid)
            setPlayerStorageValue(cid, config.storage, 0)
            setPlayerStorageValue(cid, config.register, 0)
            local oldexp = getPlayerStorageValue(cid, config.expstorage)
            doPlayerSetExperienceRate(cid, oldexp)
            unregisterCreatureEvent(cid, "ExpStage")
        end
    end
return true
end
function onLogin(cid)
    if getPlayerStorageValue(cid, config.register) == 1 then
        registerCreatureEvent(cid, "ExpStage")
        local rates = getPlayerRates(cid)
        doCreatureSay(cid, "Your extra experience rate is still here! It is: " .. config.rate .. "x added to your former experience rate.", TALKTYPE_ORANGE_1, true, cid)
        if getPlayerStorageValue(cid, config.storage) > os.time() then
        local oldexp = getPlayerStorageValue(cid, config.expstorage)
        doPlayerSetExperienceRate(cid, oldexp+config.rate)
        end
    end 
return true
end

I also have a event that triggers once every day and lasts for 1 hour that gives 2x XP:

Code:
local cyko = {
    new_rate = 2,
    old_rate = 1
}

function onTime()
    if getStorage(3000) == -1 then
        doSetStorage(3000, 1)
        doBroadcastMessage("Double XP is now active for one hour!")
    for _, on in ipairs(getPlayersOnline()) do
        doPlayerSetRate(on, SKILL__LEVEL, cyko.new_rate)
    end
    else
        doSetStorage(3000, -1)
        doBroadcastMessage("The double XP event has ended.")
    for _, off in ipairs(getPlayersOnline()) do
        doPlayerSetRate(off, SKILL__LEVEL, cyko.old_rate)
        end
    end
    return true
end

I want the scroll to wear off once the event starts. The issue is that if a player has the scroll active before the event starts, once the event starts you only get 1x xp instead of the 2x that the event should give. I don't want the scroll to stack with the event.

Everything works fine when using them separate, the issue is when having a scroll active before the event starts.
Post automatically merged:

Also noticed that when you relog with the XP scroll active the rates increase even more
 
Last edited:
Solution
Solved it by delaying the event by 3 seconds so the functions for the scroll and event don't fire at the exact same time:

Lua:
local cyko = {
    new_rate = 2,
    old_rate = 1
}

function onTime()
    if getStorage(3000) == -1 then
        doSetStorage(3000, 1)
        doBroadcastMessage("Double XP is now active for one hour!")
        addEvent(doubleXp, 3000, cid)
    else
        doSetStorage(3000, -1)
        doBroadcastMessage("The double XP event has ended.")
    for _, off in ipairs(getPlayersOnline()) do
        doPlayerSetRate(off, SKILL__LEVEL, cyko.old_rate)
        end
    end
    return true
end

function doubleXp()
         for _, on in ipairs(getPlayersOnline()) do
        doPlayerSetRate(on, SKILL__LEVEL, cyko.new_rate)...
Solved it by delaying the event by 3 seconds so the functions for the scroll and event don't fire at the exact same time:

Lua:
local cyko = {
    new_rate = 2,
    old_rate = 1
}

function onTime()
    if getStorage(3000) == -1 then
        doSetStorage(3000, 1)
        doBroadcastMessage("Double XP is now active for one hour!")
        addEvent(doubleXp, 3000, cid)
    else
        doSetStorage(3000, -1)
        doBroadcastMessage("The double XP event has ended.")
    for _, off in ipairs(getPlayersOnline()) do
        doPlayerSetRate(off, SKILL__LEVEL, cyko.old_rate)
        end
    end
    return true
end

function doubleXp()
         for _, on in ipairs(getPlayersOnline()) do
        doPlayerSetRate(on, SKILL__LEVEL, cyko.new_rate)
        end
     return true
end

However there's a bug where the rates increases to 3x when you relog with the scroll active :/
Post automatically merged:

The rate still goes back to 1x when the event starts if a player has the scroll active before the event :/
Never mind everything is solved...

changed:
Lua:
doPlayerSetExperienceRate(cid, oldexp+config.rate)

to:
Code:
doPlayerSetExperienceRate(cid, oldexp*config.rate)
 
Last edited:
Solution

Similar threads

Replies
0
Views
364
Back
Top