• 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

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
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 whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
This appears to be an incomplete script.

expPotion[item:getId()] this refers to a table, which doesn't exist, and is probably where the "how many X exp we got after use" is located.

More then likely there is an additional part which ties into data/events/scripts/player.lua -> Player:onGainExperience
Which will check if the player has the storage value, and will then multiply/add additional experience.

So yeah, wherever you found the script, there is probably more stuff for you to install to make this work.
 
OP
OP
vexler222

vexler222

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
@Xikini okey i have problem with this potion, all work i can use but he dont give me more experience :/ Rotworm give me 7200xp with normal xp and after use potion

This is all what i found:

data/script/custom/exppotion.lua
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("You already have some experience bonus.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    if not item:remove() then
        player:sendCancelMessage("You don't have any kind of experience potions.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end


    player:sendCancelMessage("You have activated an experience bonus of +".. xpPot.exp .."% per ".. xpPot.tempo .." hour(s)".. (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("Your bonus experience time for the experience potion is over!")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end, xpPot.tempo * 60 * 60 * 1000)
    return true
end

exp:id(7443)
exp:register()


events/scripts/player.lua
Code:
    -- XP potion
    local xpPotion = 0
    if self:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        local potion = expPotion[self:getStorageValue(STORAGEVALUE_POTIONXP_ID)]
        if potion then
            xpPotion = exp * potion.exp / 100
        end
    end

lib/core/tables
Code:
tabelaExiva = {}

-- Inicio -> Exp e Loot Potions [exp em %, tempo em horas]
expPotion = {
    [7443] = {exp = 200, tempo = 1}
}

lib/core/core.lua
Code:
dofile('data/lib/core/tabelas.lua')
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
@Xikini okey i have problem with this potion, all work i can use but he dont give me more experience :/ Rotworm give me 7200xp with normal xp and after use potion

This is all what i found:

data/script/custom/exppotion.lua
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("You already have some experience bonus.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    if not item:remove() then
        player:sendCancelMessage("You don't have any kind of experience potions.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end


    player:sendCancelMessage("You have activated an experience bonus of +".. xpPot.exp .."% per ".. xpPot.tempo .." hour(s)".. (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("Your bonus experience time for the experience potion is over!")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    end, xpPot.tempo * 60 * 60 * 1000)
    return true
end

exp:id(7443)
exp:register()


events/scripts/player.lua
Code:
    -- XP potion
    local xpPotion = 0
    if self:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        local potion = expPotion[self:getStorageValue(STORAGEVALUE_POTIONXP_ID)]
        if potion then
            xpPotion = exp * potion.exp / 100
        end
    end

lib/core/tables
Code:
tabelaExiva = {}

-- Inicio -> Exp e Loot Potions [exp em %, tempo em horas]
expPotion = {
    [7443] = {exp = 200, tempo = 1}
}

lib/core/core.lua
Code:
dofile('data/lib/core/tabelas.lua')
Can you show the entire Player:onGainExperience function?
 
OP
OP
vexler222

vexler222

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
Can you show the entire Player:onGainExperience function?

Code:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    -- Soul regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())

    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end

    -- XP potion
    local xpPotion = 0
    if self:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        local potion = expPotion[self:getStorageValue(STORAGEVALUE_POTIONXP_ID)]
        if potion then
            xpPotion = exp * potion.exp / 100
        end
    end

    return exp + xpPotion
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
Code:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end

    -- Soul regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end

    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())

    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)

        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end

    -- XP potion
    local xpPotion = 0
    if self:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        local potion = expPotion[self:getStorageValue(STORAGEVALUE_POTIONXP_ID)]
        if potion then
            xpPotion = exp * potion.exp / 100
        end
    end

    return exp + xpPotion
end
Added some prints, and changed a few quick things
Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
   
    -- Soul regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end
   
    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
   
    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
   
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end
   
    print("exp before: " .. exp)
    -- XP potion
    if self:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        print("exp potion active")
        local potion = expPotion[self:getStorageValue(STORAGEVALUE_POTIONXP_ID)]
        if potion then
            print("potion found")
            exp = exp * (potion.exp / 100)
        end
    end
    print("exp after: " .. exp)
   
    return exp
end
 
OP
OP
vexler222

vexler222

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
Added some prints, and changed a few quick things
Lua:
function Player:onGainExperience(source, exp, rawExp)
    if not source or source:isPlayer() then
        return exp
    end
  
    -- Soul regeneration
    local vocation = self:getVocation()
    if self:getSoul() < vocation:getMaxSoul() and exp >= self:getLevel() then
        soulCondition:setParameter(CONDITION_PARAM_SOULTICKS, vocation:getSoulGainTicks() * 1000)
        self:addCondition(soulCondition)
    end
  
    -- Apply experience stage multiplier
    exp = exp * Game.getExperienceStage(self:getLevel())
  
    -- Stamina modifier
    if configManager.getBoolean(configKeys.STAMINA_SYSTEM) then
        useStamina(self)
  
        local staminaMinutes = self:getStamina()
        if staminaMinutes > 2400 and self:isPremium() then
            exp = exp * 1.5
        elseif staminaMinutes <= 840 then
            exp = exp * 0.5
        end
    end
  
    print("exp before: " .. exp)
    -- XP potion
    if self:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) > os.time() then
        print("exp potion active")
        local potion = expPotion[self:getStorageValue(STORAGEVALUE_POTIONXP_ID)]
        if potion then
            print("potion found")
            exp = exp * (potion.exp / 100)
        end
    end
    print("exp after: " .. exp)
  
    return exp
end

exp before: 10800
exp potion active
exp after: 10800
 

drakylucas

Well-Known Member
Joined
Dec 15, 2015
Messages
189
Solutions
4
Reaction score
83
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.
 
Solution

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
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.
I agree.
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.
With the above changes, he could just remove the reset addEvent entirely, since it's kinda pointless to reset the storages.
 
OP
OP
vexler222

vexler222

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
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.

Bro love you! <3 I checked again files from datapack where i found xp potion script, and there is a storages.lua file in lib, not all work correctly!
Post automatically merged:

@Xikini @drakylucas yep this script have bug with logout/login again but when i remove this part: player:getStorageValue(STORAGEVALUE_POTIONXP_ID) >= 1, but the message that the double experience ended is not displayed, and i don't know how to remove addEvent function? How to check when the time is up without this function?

// Edit: i can add storage remove to logout function but when player login again he lose potion bonus so its not good ;/
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
Bro love you! <3 I checked again files from datapack where i found xp potion script, and there is a storages.lua file in lib, not all work correctly!
Post automatically merged:

@Xikini @drakylucas yep this script have bug with logout/login again but when i remove this part: player:getStorageValue(STORAGEVALUE_POTIONXP_ID) >= 1, but the message that the double experience ended is not displayed, and i don't know how to remove addEvent function? How to check when the time is up without this function?

// Edit: i can add storage remove to logout function but when player login again he lose potion bonus so its not good ;/
This should restart the timer, if the player still has time left.
Lua:
local function resetExpPotion(playerId)
	local player = Player(playerId)
	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

local loginEvent = CreatureEvent("onLogin_ExpPotion")
loginEvent:type("login")

function loginEvent.onLogin(player)
	local ExpPotionTimer = player:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) - os.time()
	if ExpPotionTimer > 0 then
        print("Player " .. player:getName() .. " still has " .. ExpPotionTimer .. " seconds left of ExpPotion.")
		addEvent(resetExpPotion, ExpPotionTimer, player:getId())
    elseif player:getStorageValue(STORAGEVALUE_POTIONXP_TEMPO) ~= -1 then
        resetExpPotion(player:getId())
	end
    return true
end

loginEvent:register()
 
Last edited:

drakylucas

Well-Known Member
Joined
Dec 15, 2015
Messages
189
Solutions
4
Reaction score
83
Yep, adding above code from @Xikini and not removing the addEvent part should also work. This way, when player login again, the addEvent is added again (in case he still have some time).

You can also edit this onLogin function to add a message in case the timer expired while the player was offline.

(something like this, but sorry I'm on phone and it's hard to type code )

elseif(player:getStorageValue(STORAGEVALUE_POTIONXP_ID) ~= - 1) then
resetExpPotion(player:getId())



After addEvent (....) but before end from xikini's code
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
Yep, adding above code from @Xikini and not removing the addEvent part should also work. This way, when player login again, the addEvent is added again (in case he still have some time).

You can also edit this onLogin function to add a message in case the timer expired while the player was offline.

(something like this, but sorry I'm on phone and it's hard to type code )

elseif(player:getStorageValue(STORAGEVALUE_POTIONXP_ID) ~= - 1) then
resetExpPotion(player:getId())



After addEvent (....) but before end from xikini's code
Ah, good idea. I'll edit it into my post. xP
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,695
Solutions
407
Reaction score
3,803
@Xikini its work but still player lose bonus when he logout/login :/
If it happens everytime you logout/login, then there is probably a logout or login script that is resetting the storage value.

This is all very blind. Where did you grab this script from?

You need to learn how to use print()
print out the values of the storages when the players login, and see if they are resetting.
 
OP
OP
vexler222

vexler222

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
If it happens everytime you logout/login, then there is probably a logout or login script that is resetting the storage value.

This is all very blind. Where did you grab this script from?

You need to learn how to use print()
print out the values of the storages when the players login, and see if they are resetting.

I found this script in datapack from brazil forum, and when i logout / login i see in console your print "Player X PLAYER still has X TIME seconds left of Exp Potion." but time get reset

I see, this function is always activated after logging in if the player has 2x experience and resets it


Code:
local function resetExpPotion(playerId)
    local player = Player(playerId)
    if player then
        player:setStorageValue(STORAGEVALUE_POTIONXP_ID, -1)
        player:setStorageValue(STORAGEVALUE_POTIONXP_TEMPO, -1)
        player:sendCancelMessage("Your extra experience time for an experience potion has expired!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
end
 
Last edited:
OP
OP
vexler222

vexler222

Member
Joined
Apr 22, 2012
Messages
510
Solutions
7
Reaction score
15
@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
 
Top