• 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 0.X [7.72] EXP Scroll dont end

potinho

Active Member
Joined
Oct 11, 2009
Messages
538
Solutions
14
Reaction score
44
Location
Brazil
Hello guys, I have this script which is an exp scroll, it gives twice the experience for two hours, but if the char does not log out, the bonus experience continues, and only ends as soon as the char logs out. Can you help me fix the script?

Lua:
local config = {
    rate = 2,
    time = 2, -- 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


in login.lua i've got:

Lua:
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
 
Solution
sure

Lua:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}



function onLogin(cid)

registerCreatureEvent(cid, "RushCombat")
registerCreatureEvent(cid, "RushAttack")
registerCreatureEvent(cid, "RushDead")
registerCreatureEvent(cid, "RushOutfit")

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...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,682
Solutions
406
Reaction score
3,792
I see no issue with the script.

The scenario you are talking about would only happen if a god character was using /reload on a live server.
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
538
Solutions
14
Reaction score
44
Location
Brazil
I see no issue with the script.

The scenario you are talking about would only happen if a god character was using /reload on a live server.
There is a problem, if the char doesn't die or log out, the exp scroll will last forever (or all day). When the two hours pass, if the char does not log out, the double exp continues.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,682
Solutions
406
Reaction score
3,792
There is a problem, if the char doesn't die or log out, the exp scroll will last forever (or all day). When the two hours pass, if the char does not log out, the double exp continues.
Fine, let's do a test.

This modification will make the double experience last 10 seconds.

Tell me if it ends.
Lua:
local config = {
    rate = 2,
    time = 10,
    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)
        addEvent(endExpRate, config.time * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
538
Solutions
14
Reaction score
44
Location
Brazil
Fine, let's do a test.

This modification will make the double experience last 10 seconds.

Tell me if it ends.
Lua:
local config = {
    rate = 2,
    time = 10,
    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)
        addEvent(endExpRate, config.time * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end
Worked, what is wrong? If you are not going to abuse it, can you help me with the message when using the scroll, if there is still time left, show the time remaining, as in login? On this line:

Lua:
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,682
Solutions
406
Reaction score
3,792
Worked, what is wrong? If you are not going to abuse it, can you help me with the message when using the scroll, if there is still time left, show the time remaining, as in login? On this line:

Lua:
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")

Use date-time functions to show that.
Lua:
os.date('!%T', seconds)
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have " .. (os.date('!%T', os.time() - getPlayerStorageValue(cid, config.storage))) .. " extra experience time left.")

But.. Evil Puncker is right, and there should be a better trigger implemented to remove the extra experience.
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
538
Solutions
14
Reaction score
44
Location
Brazil
Use date-time functions to show that.
Lua:
os.date('!%T', seconds)
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have " .. (os.date('!%T', os.time() - getPlayerStorageValue(cid, config.storage))) .. " extra experience time left.")

But.. Evil Puncker is right, and there should be a better trigger implemented to remove the extra experience.
When i used
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have " .. (os.date('!%T', os.time() - getPlayerStorageValue(cid, config.storage))) .. " extra experience time left.")
, my server crashed :eek: haha
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,682
Solutions
406
Reaction score
3,792
When i used
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have " .. (os.date('!%T', os.time() - getPlayerStorageValue(cid, config.storage))) .. " extra experience time left.")
, my server crashed :eek: haha
Wth? lol

I guess you're using some outdated Lua.. umm Try the old way then.

Lua:
os.date('!%H:%M:%S', seconds)
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have " .. (os.date('!%H:%M:%S', os.time() - getPlayerStorageValue(cid, config.storage))) .. " extra experience time left.")
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
538
Solutions
14
Reaction score
44
Location
Brazil
Fine, let's do a test.

This modification will make the double experience last 10 seconds.

Tell me if it ends.
Lua:
local config = {
    rate = 2,
    time = 10,
    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)
        addEvent(endExpRate, config.time * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
    end
    return TRUE
end
i was wrong Xikini, now when time over, exp back to normal rate, but if i log (or die) i lose all 2 hours of exp bonus.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,682
Solutions
406
Reaction score
3,792
i was wrong Xikini, now when time over, exp back to normal rate, but if i log (or die) i lose all 2 hours of exp bonus.
Well, I didn't change anything in your script. xD
Just how much time to give to the player.

So your login.lua is the issue, I guess.

Can you post it, please?
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
538
Solutions
14
Reaction score
44
Location
Brazil
Well, I didn't change anything in your script. xD
Just how much time to give to the player.

So your login.lua is the issue, I guess.

Can you post it, please?
sure

Lua:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}



function onLogin(cid)

registerCreatureEvent(cid, "RushCombat")
registerCreatureEvent(cid, "RushAttack")
registerCreatureEvent(cid, "RushDead")
registerCreatureEvent(cid, "RushOutfit")

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
    
    if(getBooleanFromString(getConfigValue('accountManager')) == false) then
        if (getCreatureName(cid) == "Account Manager") then
            return doRemoveCreature(cid, true)
        end
    end
    
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
    
 

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, it appears that your character has been locked for name violating rules, what new name would you like to have?", TALKTYPE_PRIVATE_NP, true, cid)
    elseif(accountManager == MANAGER_ACCOUNT) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to manage your account. If you would like to start over, type 'cancel' anywhere.", TALKTYPE_PRIVATE, true, cid)
    else
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to create an account or 'recover' to recover an account.", TALKTYPE_PRIVATE, true, cid)
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "Idle")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "ReportBug")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "GuildEvents")
    registerCreatureEvent(cid, "AdvanceSave")
    registerCreatureEvent(cid, "mori")

    return true
    
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,682
Solutions
406
Reaction score
3,792
sure

Lua:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}



function onLogin(cid)

registerCreatureEvent(cid, "RushCombat")
registerCreatureEvent(cid, "RushAttack")
registerCreatureEvent(cid, "RushDead")
registerCreatureEvent(cid, "RushOutfit")

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
 
    if(getBooleanFromString(getConfigValue('accountManager')) == false) then
        if (getCreatureName(cid) == "Account Manager") then
            return doRemoveCreature(cid, true)
        end
    end
 
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
 


    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, it appears that your character has been locked for name violating rules, what new name would you like to have?", TALKTYPE_PRIVATE_NP, true, cid)
    elseif(accountManager == MANAGER_ACCOUNT) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to manage your account. If you would like to start over, type 'cancel' anywhere.", TALKTYPE_PRIVATE, true, cid)
    else
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to create an account or 'recover' to recover an account.", TALKTYPE_PRIVATE, true, cid)
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "Idle")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "ReportBug")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "GuildEvents")
    registerCreatureEvent(cid, "AdvanceSave")
    registerCreatureEvent(cid, "mori")

    return true
 
end

Lua:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}


function onLogin(cid)
  
    if(getBooleanFromString(getConfigValue('accountManager')) == false) then
        if (getCreatureName(cid) == "Account Manager") then
            return doRemoveCreature(cid, true)
        end
    end
  
    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end
  
    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end
  
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, it appears that your character has been locked for name violating rules, what new name would you like to have?", TALKTYPE_PRIVATE_NP, true, cid)
    elseif(accountManager == MANAGER_ACCOUNT) then
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to manage your account. If you would like to start over, type 'cancel' anywhere.", TALKTYPE_PRIVATE, true, cid)
    else
        addEvent(valid(doCreatureSay), 500, cid, "Hello, type 'account' to create an account or 'recover' to recover an account.", TALKTYPE_PRIVATE, true, cid)
    end
  
    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end
  
    registerCreatureEvent(cid, "Idle")
    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "ReportBug")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end
  
    registerCreatureEvent(cid, "GuildEvents")
    registerCreatureEvent(cid, "AdvanceSave")
    registerCreatureEvent(cid, "mori")
  
    registerCreatureEvent(cid, "RushCombat")
    registerCreatureEvent(cid, "RushAttack")
    registerCreatureEvent(cid, "RushDead")
    registerCreatureEvent(cid, "RushOutfit")
  
    registerCreatureEvent(cid, "extraExperienceScroll")
  
    return true
end
XML:
<creatureevent type="login" name="extraExperienceScroll" event="script" value="extraExperienceScroll.lua"/>
Lua:
local storage = 20014

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

function onLogin(cid)
    local storageValue = getPlayerStorageValue(cid, storage)
    local timeLeft = storageValue - os.time()
    if storageValue > os.time() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Extra experience rate is now: 2.0x than normal. It will last for " .. (math.ceil(timeLeft/60)) .. " minutes.")
        doPlayerSetRate(cid, SKILL__LEVEL, 2.0)
        addEvent(endExpRate, timeLeft * 1000, cid)
    else
        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)
    end
    return true
end
Lua:
local config = {
    rate = 2,
    time = 2 * 60 * 60, -- (2 hours) in seconds
    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 / 3600) .." hours.")
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.storage, os.time() + config.time)
        addEvent(endExpRate, config.time * 1000, cid)
        doRemoveItem(item.uid, 1)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have " .. (os.date('!%H:%M:%S', getPlayerStorageValue(cid, config.storage) - os.time())) .. " extra experience time left.")
    end
    return true
end
 
Solution
Top