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

ExpPotion tfs 1.3

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i found this script but how it work? Where is how many X exp we got after use? And how work scripts in folder "data/script/action"?

Code:
local exp = Action()

function exp.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local xpPot = expPotion[item:getId()]
    if not xpPot then
        return false
    end

    if player:getStorageValue(STORAGEVALUE_POTIONXP_ID) >= 1 or player:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        player:sendCancelMessage("Você já possui algum bônus de experiência.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    if not item:remove() then
        player:sendCancelMessage("Você não possui nenhum tipo de poção de experiência.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end


    player:sendCancelMessage("Você ativou um bônus de experiência de +".. xpPot.exp .."% por ".. xpPot.tempo .." hora".. (xpPot.tempo > 1 and "s" or "") ..".")
    player:getPosition():sendMagicEffect(31)
    player:setStorageValue(STORAGEVALUE_POTIONXP_ID, item:getId())
    player:setStorageValue(STORAGEVALUE_POTIONXP_TEMPO, os.time() + xpPot.tempo * 60 * 60)
    local idPlayer = player:getId()
    addEvent(function()
        local player = Player(idPlayer)
        if player then
            player:setStorageValue(STORAGEVALUE_POTIONXP_ID, -1)
            player:setStorageValue(STORAGEVALUE_POTIONXP_TEMPO, -1)
            player:sendCancelMessage("O seu tempo de experiência bônus pela poção de experiência acabou!")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end, xpPot.tempo * 60 * 60 * 1000)
    return true
end

exp:id(7477, 7253, 8205, 9734)
exp:register()
 
Solution
In your prints, you're not printing the ID of the potion, but the exp before/after.

As it did not print "potion found", I suppose it didn't found the potion in "expPotion" table.


Where are you defining the storage number for STORAGEVALUE_POTIONXP_ID and STORAGEVALUE_POTIONXP_TEMPO?

I didn't see it being set in any place.

This script also has a bug. If player logout and login again, the addEvent part will not work and the storage will not be removed.

You should remove this verification in action part
player:getStorageValue(STORAGEVALUE_POTIONXP_ID) >= 1

(but keep the time verification)
Otherwise some players will never be able to use another potion again.
@Xikini i know why it reset after logout/login
i change it:
Code:
addEvent(resetExpPotion, ExpPotionTimer, player:getId())

for
Code:
addEvent(resetExpPotion, ExpPotionTimer * 60 * 60 * 1000, player:getId())

But when I changed it, the message after completion doesn't show up
experience is back to normal, just no information, and I haven't changed anything else
ah, I see.

Change that line to
Lua:
addEvent(resetExpPotion, ExpPotionTimer * 1000, player:getId())

I derped and forgot that addEvent was using milliseconds.
 
Back
Top