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

Lua Double EXP ITEM tfs 0.3.6

Vitich

Member
Joined
Nov 28, 2012
Messages
266
Reaction score
11
Hi, I got this script, but got a problem. When player logout or die, double exp disabled and can't use more items to get double exp.

Lua:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getPlayerStorageValue(cid, config.storage) < 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end


19:26 You still have extra experience time left. (it never disabled if i logout/die util double exp is active)

How can I fix that?

Thank you all!
 
Solution
I tested it.

Use scroll = double exp, correctly.
Logout, Login = double exp, working.
after 1 hour = double exp end working.

But.... 02:39 You still have extra experience time left.

try this one

Code:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, config.storage) < os.time() then...
This is a terrible use of addEvent
Lua:
addEvent(endExpRate, config.time * 3600 * 1000, cid)
You're better off using an onThink creature script to check for the config.storage time left.
 
This is what you do. open up idle.lua in data/creaturescripts/scripts and replace it with this
Lua:
local config = {
    idleWarning = getConfigValue('idleWarningTime'),
    idleKick = getConfigValue('idleKickTime'),
  expStorage = 20014
}

local function endExpRate(cid)
    if isPlayer(cid) then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.expStorage, 0)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end

function onThink(cid, interval)
    if(getTileInfo(getCreaturePosition(cid)).nologout or getCreatureNoMove(cid) or
        getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_ALLOWIDLE)) then
        return true
    end

  -- this will do the work of resetting the double experience
  local xpTime = getPlayerStorageValue(config.expStorage)
  if xpTime ~= 0 and xpTime <= os.time() then
      endExpRate(cid)
  end

    local idleTime = getPlayerIdleTime(cid) + interval
    doPlayerSetIdleTime(cid, idleTime)
    if(config.idleKick > 0 and idleTime > config.idleKick) then
        doRemoveCreature(cid)
    elseif(config.idleWarning > 0 and idleTime == config.idleWarning) then
        local message = "You have been idle for " .. math.ceil(config.idleWarning / 60000) .. " minutes"
        if(config.idleKick > 0) then
            message = message .. ", you will be disconnected in "
            local diff = math.ceil((config.idleWarning - config.idleKick) / 60000)
            if(diff > 1) then
                message = message .. diff .. " minutes"
            else
                message = message .. "one minute"
            end

            message = message .. " if you are still idle"
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, message .. ".")
    end
    return true
end

idle.lua runs all the time making it a more suitable timer than running an addEvent
Then change your script to this
Lua:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getPlayerStorageValue(cid, config.storage) <= 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return true
end
 
in login add
Code:
    if (getPlayerStorageValue(cid,20014) > os.time()) then

        doPlayerSetRate(cid, SKILL__LEVEL, 2)

    else

        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)

    end

now when he die or relog double exp not disabled and when os.time end he will get normal exp
 
in login add
Code:
    if (getPlayerStorageValue(cid,20014) > os.time()) then

        doPlayerSetRate(cid, SKILL__LEVEL, 2)

    else

        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)

    end

now when he die or relog double exp not disabled and when os.time end he will get normal exp
What if he never dies?
 
his script will end the os.time and back exp for normal
Code:
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
 
his script will end the os.time and back exp for normal
Code:
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
I don't see any reason to run an addEvent for this long.
As a matter of fact with a small change to this script can increase the duration of the double experience.
Using idle.lua instead of an addEvent is more beneficial and isn't limited to the restrictions of addEvent.
 
in login add
Code:
    if (getPlayerStorageValue(cid,20014) > os.time()) then

        doPlayerSetRate(cid, SKILL__LEVEL, 2)

    else

        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)

    end

now when he die or relog double exp not disabled and when os.time end he will get normal exp
It not working.... 01:29 You still have extra experience time left. after 1.5H after used.
 
It not working.... 01:29 You still have extra experience time left. after 1.5H after used.
bro if u used this player can't use other double exp items for 1 hour
but player will have double exp for one hour if die or relog player don't losse his double exp

but if u want player die or relog losse his doubble exp and he can use other items use this in login
Code:
    if (getPlayerStorageValue(cid,20014) > os.time()) then
setPlayerStorageValue(cid, 20014, 0)

end
 
Last edited:
bro if u used this player can't use other double exp items for 1 hour
but player will have double exp for one hour if die or relog player don't losse his double exp

but if u want player die or relog losse his doubble exp and he can use other items use this in login
Code:
    if (getPlayerStorageValue(cid,20014) > os.time()) then
setPlayerStorageValue(cid, 20014, 0)

end

The problem is that if player die, do not lose double exp, but after 1h the storage didn't remove....
 
This is what you do. open up idle.lua in data/creaturescripts/scripts and replace it with this
Lua:
local config = {
    idleWarning = getConfigValue('idleWarningTime'),
    idleKick = getConfigValue('idleKickTime'),
  expStorage = 20014
}

local function endExpRate(cid)
    if isPlayer(cid) then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.expStorage, 0)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end

function onThink(cid, interval)
    if(getTileInfo(getCreaturePosition(cid)).nologout or getCreatureNoMove(cid) or
        getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_ALLOWIDLE)) then
        return true
    end

  -- this will do the work of resetting the double experience
  local xpTime = getPlayerStorageValue(config.expStorage)
  if xpTime ~= 0 and xpTime <= os.time() then
      endExpRate(cid)
  end

    local idleTime = getPlayerIdleTime(cid) + interval
    doPlayerSetIdleTime(cid, idleTime)
    if(config.idleKick > 0 and idleTime > config.idleKick) then
        doRemoveCreature(cid)
    elseif(config.idleWarning > 0 and idleTime == config.idleWarning) then
        local message = "You have been idle for " .. math.ceil(config.idleWarning / 60000) .. " minutes"
        if(config.idleKick > 0) then
            message = message .. ", you will be disconnected in "
            local diff = math.ceil((config.idleWarning - config.idleKick) / 60000)
            if(diff > 1) then
                message = message .. diff .. " minutes"
            else
                message = message .. "one minute"
            end

            message = message .. " if you are still idle"
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, message .. ".")
    end
    return true
end

idle.lua runs all the time making it a more suitable timer than running an addEvent
Then change your script to this
Lua:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getPlayerStorageValue(cid, config.storage) <= 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return true
end
It not working :/
 
look bro this must work if u use
Code:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getPlayerStorageValue(cid, config.storage) < 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end

in creaturescript login add this

Code:
last = math.ceil((getPlayerStorageValue(cid, 20014) - os.time())/60)
  if (getPlayerStorageValue(cid, 20014) > os.time()) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Extra experience rate is now: 2.0x than normal. It will last for ".. last .." minutes.")
        doPlayerSetRate(cid, SKILL__LEVEL, 2.0)
    else
        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)
    end

how its work ?
if player die or relog he will have dabble exp for 1 hour and than he can use other items ..
i should work 100%
 
look bro this must work if u use
Code:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getPlayerStorageValue(cid, config.storage) < 0) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end

in creaturescript login add this

Code:
last = math.ceil((getPlayerStorageValue(cid, 20014) - os.time())/60)
  if (getPlayerStorageValue(cid, 20014) > os.time()) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Extra experience rate is now: 2.0x than normal. It will last for ".. last .." minutes.")
        doPlayerSetRate(cid, SKILL__LEVEL, 2.0)
    else
        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)
    end

how its work ?
if player die or relog he will have dabble exp for 1 hour and than he can use other items ..
i should work 100%
I tested it.

Use scroll = double exp, correctly.
Logout, Login = double exp, working.
after 1 hour = double exp end working.

But.... 02:39 You still have extra experience time left.
 
I tested it.

Use scroll = double exp, correctly.
Logout, Login = double exp, working.
after 1 hour = double exp end working.

But.... 02:39 You still have extra experience time left.

try this one

Code:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, config.storage) < os.time() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end
 
Solution
try this one

Code:
local config = {
    rate = 2,
    time = 1, -- Hours of Exp Time
    storage = 20014
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, config.storage) < os.time() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end

Now it working! finally.

Thank you very much :)
 
@heba hey i tested this script in my server tfs 0.3.6 and i have a problem, when player log out and log in, script doesnt reset exp stage, so player still have a boost, but if he relog after more than 1 min, exp stage back to the normal (for tested i set 1min boost) Can you help me with it?

@edit


I try to do so that after logging out time stops for boost, and after logging in so that the player has as much time as he has left
 
Last edited:
Back
Top