• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

permanent bonus

  • Thread starter Thread starter verdehile95
  • Start date Start date
V

verdehile95

Guest
Hello, I am looking for a potion code that gives the player a permanent bonus of 25 hp and mana
 
Solution
If the bonus is permanent, simply increase its maximum life/mana and that's it.

This could be a simple option for TFS 1.x+
LUA:
local POTION_ID = 0000
local storageKey = 00000

local extraHP = 25
local extraMP = 25

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local storageValue = tonumber(player:getStorageValue(storageKey)) or -1
    if storageValue ~= -1 then
        player:sendCancelMessage("You have already used this potion.")
        return true
    end

    player:setStorageValue(storageKey, 1)
    player:setMaxHealth(player:getMaxHealth() + extraHP)
    player:setMaxMana(player:getMaxMana() + extraMP)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(
        "You...
If the bonus is permanent, simply increase its maximum life/mana and that's it.

This could be a simple option for TFS 1.x+
LUA:
local POTION_ID = 0000
local storageKey = 00000

local extraHP = 25
local extraMP = 25

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local storageValue = tonumber(player:getStorageValue(storageKey)) or -1
    if storageValue ~= -1 then
        player:sendCancelMessage("You have already used this potion.")
        return true
    end

    player:setStorageValue(storageKey, 1)
    player:setMaxHealth(player:getMaxHealth() + extraHP)
    player:setMaxMana(player:getMaxMana() + extraMP)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(
        "You have used a potion and gained %d extra HP and %d extra MP.",
        extraHP, extraMP))
    item:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

action:id(POTION_ID)
action:register()
 
Solution
If the bonus is permanent, simply increase its maximum life/mana and that's it.

This could be a simple option for TFS 1.x+
LUA:
local POTION_ID = 0000
local storageKey = 00000

local extraHP = 25
local extraMP = 25

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local storageValue = tonumber(player:getStorageValue(storageKey)) or -1
    if storageValue ~= -1 then
        player:sendCancelMessage("You have already used this potion.")
        return true
    end

    player:setStorageValue(storageKey, 1)
    player:setMaxHealth(player:getMaxHealth() + extraHP)
    player:setMaxMana(player:getMaxMana() + extraMP)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(
        "You have used a potion and gained %d extra HP and %d extra MP.",
        extraHP, extraMP))
    item:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

action:id(POTION_ID)
action:register()
Thanks
 
Se o bônus for permanente, basta aumentar sua vida/mana máxima e imediatamente.

Esta pode ser uma opção simples para o TFS 1.x+
LUA:
POTION_ID local = 0000
chave de armazenamento local = 00000

HP extra local = 25
MP extra local = 25

ação local = Ação()

função action.onUse(jogador, item, fromPos, alvo, toPos, isHotkey)
    valor de armazenamento local = tonumber(player:getStorageValue(storageKey)) ou -1
    se storageValue ~= -1 então
        player:sendCancelMessage("Você já usou essa poção.")
        retornar verdadeiro
    fim

    jogador:setStorageValue(chave de armazenamento, 1)
    jogador:setMaxHealth(jogador:getMaxHealth() + extraHP)
    jogador:setMaxMana(jogador:getMaxMana() + extraMP)
    jogador:sendTextMessage(MESSAGE_INFO_DESCR, string.format(
        "Você usou uma poção e ganhou %d HP e %d MP extras.",
        HP extra, MP extra))
    item:removedor(1)
    jogador:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    retornar verdadeiro
fim

ação:id(POTION_ID)
ação:registrar()
E É possível ter um script com 2 poções, onde uma aumenta o dano em 50% e a outra reduz o dano recebido em 50%? Only during the effect of the potions, which in this case would be 10 minutes.
 
If the bonus is permanent, simply increase its maximum life/mana and that's it.

This could be a simple option for TFS 1.x+
LUA:
local POTION_ID = 0000
local storageKey = 00000

local extraHP = 25
local extraMP = 25

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local storageValue = tonumber(player:getStorageValue(storageKey)) or -1
    if storageValue ~= -1 then
        player:sendCancelMessage("You have already used this potion.")
        return true
    end

    player:setStorageValue(storageKey, 1)
    player:setMaxHealth(player:getMaxHealth() + extraHP)
    player:setMaxMana(player:getMaxMana() + extraMP)
    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(
        "You have used a potion and gained %d extra HP and %d extra MP.",
        extraHP, extraMP))
    item:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

action:id(POTION_ID)
action:register()


In the new scripts, it's necessary to check the storage values because they return null, correct?

LUA:
`storageValue local = tonumber(player:getStorageValue(storageKey))` or -1

or

Code:
`local storageValue = tonumber(player:getStorageValue(storageKey))` or 0
 
In the new scripts, it's necessary to check the storage values because they return null, correct?

LUA:
`storageValue local = tonumber(player:getStorageValue(storageKey))` or -1

or

Code:
`local storageValue = tonumber(player:getStorageValue(storageKey))` or 0
Correct.

Creature::getStorageValue() uses std:: optional for it's return value.
forgottenserver/src/creature.h at b94b30227785a03c548ef6d978880f6b15f9e822 · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/b94b30227785a03c548ef6d978880f6b15f9e822/src/creature.h#L379)

So if the key doesn't exist it will return nil.
forgottenserver/src/luascript.cpp at b94b30227785a03c548ef6d978880f6b15f9e822 · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/b94b30227785a03c548ef6d978880f6b15f9e822/src/luascript.cpp#L8956)
 
Last edited:

Thanks for replying, I was migrating some Lua scripts and kept getting this error, so I did some research and realized that the way the getStorageValue method returns has changed.

So I'm trying to change almost all the comparisons that were previously done directly, such as:

if player:getStorageValue(storageKey) < -1 then

player:sendCancelMessage("You have already used this potion.")

return true
end
 

Similar threads

Back
Top