V
verdehile95
Guest
Hello, I am looking for a potion code that gives the player a permanent bonus of 25 hp and mana
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...
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()
ThanksIf 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()
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.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()
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()
`storageValue local = tonumber(player:getStorageValue(storageKey))` or -1
`local storageValue = tonumber(player:getStorageValue(storageKey))` or 0
Correct.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)