DI
dúvida

[Ajuda] Regeneração Por Segundo Baseado Em Porcentagem Da Vida.

Por digomaciel, 25 de jun. de 2012 em Scripts

addevent
cooldown
spell
ajuda
4
1.1k
digomacielD
25 de junho de 2012 às 15:50

Gostaria de criar uma magia que regenera-se 3% da vida do personagem por segundo. A magia so pode ser usada por Knights e Elite Knights. Duração de 30 segundos e a cada segundo piscar azul nele (CONST_ME_MAGIC_BLUE)

 

local tempo = 30 * 1000

local cooldown = 30

local cont = 0

 

local combat = createCombatObject()

setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)

setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)

setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(cid, level, maglevel)

regeneration = (185+level*15)*0.03

return regeneration

end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

 

while cont<tempo do

cont = cont + 1

local combat = createCombatObject()

setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)

setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)

setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(cid, level, maglevel)

regeneration = (185+level*15)*0.03

return regeneration

end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

end

 

function cooldownready(cid)

doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "Cooldown of Enrage Regeneration is ready.")

end

 

function onCastSpell(cid, var)

if exhaustion.check(cid, 50002) == false then

exhaustion.set(cid, 50002, cooldown)

addEvent(cooldownready, cooldown*1000, cid)

return doCombat(cid, combat, var)

else

doPlayerSendCancel(cid, "Cooldown[" ..exhaustion.get(cid, 50001).."]")

end

end

 

Grato.

Editado Junho 25 por digomaciel

VodkartV
25 de junho de 2012 às 16:04
local config = {
seconds = 30,
HpPercent = 3, -- 3%
storage = 98762,
exausted = 30
}
function doRefilSecond(cid, Hp, delay) -- function by vodka
if not isCreature(cid) then return LUA_ERROR end
doCreatureAddHealth(cid, Hp)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
if delay ~= 1 then addEvent(doRefilSecond, 1000, cid, Hp, delay -1) end
return nil end

function onCastSpell(cid, var)
if getPlayerStorageValue(cid, config.storage) >= os.time() then
doPlayerSendCancel(cid, "wait " .. getPlayerStorageValue(cid, config.storage) - os.time() .. " seconds to use this spell again.") return false
end
doRefilSecond(cid, math.ceil(((config.HpPercent*getCreatureMaxHealth(cid))/100)), config.seconds)
return setPlayerStorageValue(cid, config.storage, os.time()+config.exausted) 
end

Editado Junho 25 por Vodkart

digomacielD
25 de junho de 2012 às 16:21

Funcionou perfeitamente, muito obrigado!

VildenV
25 de junho de 2012 às 16:52

Dúvida sanada, movido.