• 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 EXP boost temporally

eyez

Member
Joined
Oct 11, 2016
Messages
129
Reaction score
19
Anybody could help me to finish my action item to add exp bonus temporally?

Add 50% exp bonus for 1 hour.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
  
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have 50% EXP bonus for 1 hour.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (1*20*60*60))
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end
 
[How-to] Using addEvent()

add one more storage value(endTime) with value os.time()+3600
in -- add 50% exp bonus for 1 hour
{
doPlayerSetExperienceRate(cid, 1.5) or doPlayerSetRate(cid, "SKILL__LEVEL", 1.5)
addEvent with callback set doPlayerSetExperienceRate(cid, 1)
}
and onLogin(check if storage value[which is endTime in UNIXTIMESTAMP] is >= timeNow then return true else doPlayerSetExperienceRate(cid, 1.5) or doPlayerSetRate(cid, "SKILL__LEVEL", 1.5) and addEvent with milliseconds set to ( difference of endTime and os.time() ) *1000
 
[How-to] Using addEvent()

add one more storage value(endTime) with value os.time()+3600
in -- add 50% exp bonus for 1 hour
{
doPlayerSetExperienceRate(cid, 1.5) or doPlayerSetRate(cid, "SKILL__LEVEL", 1.5)
addEvent with callback set doPlayerSetExperienceRate(cid, 1)
}
and onLogin(check if storage value[which is endTime in UNIXTIMESTAMP] is >= timeNow then return true else doPlayerSetExperienceRate(cid, 1.5) or doPlayerSetRate(cid, "SKILL__LEVEL", 1.5) and addEvent with milliseconds set to ( difference of endTime and os.time() ) *1000

But i have another types of bonus, like premium, quests, how to check to in the end of exp boost do not set 1
Just remove that %'s
 
@eyez
getPlayerRates(cid) -0.5 getplayerrates return table i think so maybe getPlayerRates(cid).level

Halp

local rates = getPlayerRates(cid).level + bonus

[0:0:08.913] [Error - Action Interface]
[0:0:08.913] data/actions/scripts/expvoucher.lua:eek:nUse
[0:0:08.913] Description:
[0:0:08.913] data/actions/scripts/expvoucher.lua:24: attempt to perform arithmetic on field 'level' (a nil value)
[0:0:08.913] stack traceback:
[0:0:08.913] data/actions/scripts/expvoucher.lua:24: in function <data/actions/scripts/expvoucher.lua:7>




local rates = getPlayerRates(cid) + bonus
[0:1:04.973] [Error - Action Interface]
[0:1:04.973] data/actions/scripts/expvoucher.lua:eek:nUse
[0:1:04.973] Description:
[0:1:04.973] data/actions/scripts/expvoucher.lua:24: attempt to perform arithmetic on a table value
[0:1:04.973] stack traceback:
[0:1:04.973] data/actions/scripts/expvoucher.lua:24: in function <data/actions/scripts/expvoucher.lua:7>



Full code:
Code:
function ExpBackNormal_EndVoucher_50(playerid, bonus)
    local rates = getPlayerRates(cid) - bonus
    doPlayerSetExperienceRate(cid, rates)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid) + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 2*1*60*60, cid, bonus)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (1*20*60*60))
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end
 
That is not getPlayerRates(cid).SKILL__LEVEL too
Somebody could help me?
Assuming 0.4?
Lua:
doPlayerSetRate(cid, SKILL__LEVEL, value)
Sorry i don't see any method for just 1 player, only for global xp rate.

Ok i see
C++:
int32_t LuaInterface::luaGetPlayerRates(lua_State* L)
{
    //getPlayerRates(cid)
    ScriptEnviroment* env = getEnv();

    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }

    lua_newtable(L);
    for(uint32_t i = SKILL_FIRST; i <= SKILL__LAST; ++i)
    {
        lua_pushnumber(L, i);
        lua_pushnumber(L, player->rates[(skills_t)i]);
        pushTable(L);
    }

    return 1;
}

You could do something like this
Lua:
getPlayerRates(cid)[SKILL__LEVEL]
or
Lua:
getPlayerRates(cid)[8]

Reference:
C++:
enum skills_t
{
    SKILL_FIRST = 0,
    SKILL_FIST = SKILL_FIRST,
    SKILL_CLUB,
    SKILL_SWORD,
    SKILL_AXE,
    SKILL_DIST,
    SKILL_SHIELD,
    SKILL_FISH,
    SKILL__MAGLEVEL,
    SKILL__LEVEL,
    SKILL_LAST = SKILL_FISH,
    SKILL__LAST = SKILL__LEVEL
};
 
Last edited:
Assuming 0.4?
Lua:
doPlayerSetRate(cid, SKILL__LEVEL, value)
Sorry i don't see any method for just 1 player, only for global xp rate.

Ok i see
C++:
int32_t LuaInterface::luaGetPlayerRates(lua_State* L)
{
    //getPlayerRates(cid)
    ScriptEnviroment* env = getEnv();

    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }

    lua_newtable(L);
    for(uint32_t i = SKILL_FIRST; i <= SKILL__LAST; ++i)
    {
        lua_pushnumber(L, i);
        lua_pushnumber(L, player->rates[(skills_t)i]);
        pushTable(L);
    }

    return 1;
}

You could do something like this
Lua:
getPlayerRates(cid)[SKILL__LEVEL]
or
Lua:
getPlayerRates(cid)[8]

Reference:
C++:
enum skills_t
{
    SKILL_FIRST = 0,
    SKILL_FIST = SKILL_FIRST,
    SKILL_CLUB,
    SKILL_SWORD,
    SKILL_AXE,
    SKILL_DIST,
    SKILL_SHIELD,
    SKILL_FISH,
    SKILL__MAGLEVEL,
    SKILL__LEVEL,
    SKILL_LAST = SKILL_FISH,
    SKILL__LAST = SKILL__LEVEL
};

Thank you so much!

----

About topic it still no work

I made this script:
Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = getPlayerRates(cid)[8] - bonus
    doPlayerSetExperienceRate(cid, rates)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid)[8] + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 2*1*60*60, cid, bonus)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (1*20*60*60))
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end

No errors, just not adding the exp bonus
 
Thank you so much!

----

About topic it still no work

I made this script:
Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = getPlayerRates(cid)[8] - bonus
    doPlayerSetExperienceRate(cid, rates)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid)[8] + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 2*1*60*60, cid, bonus)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (1*20*60*60))
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end

No errors, just not adding the exp bonus

Making new tests looks like the bonus is adding, but it's removed too fast, there is something wrong on times?
 
There is something wrong on timers?
Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = getPlayerRates(cid)[8] - bonus
    doPlayerSetExperienceRate(cid, rates)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid)[8] + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 2*1*60*60, cid, bonus)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (1*20*60*60))
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end

Because its adding exp fast, but is removing the bonus so faster!
Anybody could help me?
 
2*1*60*60
2 x 1 = 2
2 x 60 = 120
120 x 60 = 7200 in english that is 7.2 seconds

So it should be 2 hours / 24 hours?
Code:
    addEvent(ExpBackNormal_EndVoucher, 2*60*60*1000, cid, bonus) -- 2 hours
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (20*60*60*1000)) -- 24 hours
 
1000 == 1000 milliseconds or 1 second
There are 60 seconds in 1 minute, so 60 x 1000 == 1 minute.
There are 60 minutes in 1 hour, so 60 x 1000 x 60 == 1 hour.
There are 24 hours in 1 day, so 60 x 1000 x 60 x 24 == 1 day.

When doing calculations keep it simple, the formula for the calculation does not have to be in any specific order if all the mathematical symbols are the same to reach the desired sum.

If you are having trouble grasping this then a simple way to achieve the desired calculation is to use a table.
Lua:
local t = {}
    t.second = 1000
    t.minute = t.second * 60
    t.hour = t.minute * 60
    t.day = t.hour * 24
    t.week = t.day * 7
    t.month = (t.week * 4) + (t.day * 2)
    t.year = t.day * 365
And then in your code you can use
Lua:
addEvent(ExpBackNormal_EndVoucher, t.hour * 2, cid, bonus) -- 2 hours

You can even turn the table into a function.
Lua:
local t = {}
    t.second = 1000
    t.minute = t.second * 60
    t.hour = t.minute * 60
    t.day = t.hour * 24
    t.week = t.day * 7
    t.month = (t.week * 4) + (t.day + 2)
    t.year = t.day * 365

function getTime(num, time)
    return t[time] * num
end

Lua:
addEvent(ExpBackNormal_EndVoucher, getTime(2, 'hour'), cid, bonus) -- 2 hours

If you print the return value you get
Lua:
print(getTime(2, 'hour'))
-- prints in milliseconds
7200000
 
Last edited:
1000 == 1000 milliseconds or 1 second
There are 60 seconds in 1 minute, so 60 x 1000 == 1 minute.
There are 60 minutes in 1 hour, so 60 x 1000 x 60 == 1 hour.
There are 24 hours in 1 day, so 60 x 1000 x 60 x 24 == 1 day.

When doing calculations keep it simple, the formula for the calculation does not have to be in any specific order if all the mathematical symbols are the same to reach the desired sum.

If you are having trouble grasping this then a simple way to achieve the desired calculation is to use a table.
Lua:
local t = {}
    t.second = 1000
    t.minute = t.second * 60
    t.hour = t.minute * 60
    t.day = t.hour * 24
    t.week = t.day * 7
    t.month = (t.week * 4) + (t.day * 2)
    t.year = t.day * 365
And then in your code you can use
Lua:
addEvent(ExpBackNormal_EndVoucher, t.hour * 2, cid, bonus) -- 2 hours

You can even turn the table into a function.
Lua:
local t = {}
    t.second = 1000
    t.minute = t.second * 60
    t.hour = t.minute * 60
    t.day = t.hour * 24
    t.week = t.day * 7
    t.month = (t.week * 4) + (t.day + 2)
    t.year = t.day * 365

function getTime(num, time)
    return t[time] * num
end

Lua:
addEvent(ExpBackNormal_EndVoucher, getTime(2, 'hour'), cid, bonus) -- 2 hours

If you print the return value you get
Lua:
print(getTime(2, 'hour'))
-- prints in milliseconds
7200000

Thanks, now i gottcha how it works...

But there is something else wrong, because even using right numbers:
Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = getPlayerRates(cid)[8] - bonus
    doPlayerSetExperienceRate(cid, rates)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid)[8] + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 2*60*60*1000, cid, bonus) -- 2 hours
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (20*60*60*1000)) -- 24 hours
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end

The exausted to use again is working right...
But exp bonus is adding only a few seconds, if i kill 2 rotworms, on the second dont add exp...

Did u know why?
 
Back
Top