local config = {
option = 1, -- Try using option 1, if it fails, try using option 2
time = 5000, -- The character's life will be regenerated every 5 seconds
percentage = 5, -- The character's health will be healed by 5 percent
printTest = true,
}
function regenPercentageHealthOverTime(target)
if isPlayer(target) then
local player = Player(target)
if player:isPlayer() then
if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
if config.printTest then
print("Regen is active.")
end
local currentHealth = player:getHealth()
local maxHealth = player:getMaxHealth()
if currentHealth < maxHealth then
local percentHealth = (maxHealth / 100) * config.percentage
if currentHealth + percentHealth > maxHealth then
percentHealth = maxHealth - currentHealth
end
player:addHealth(healthChange)
if config.printTest then
print("Player recovered " .. percentHealth .. " health.")
end
else
if config.printTest then
print("Player is at max health. No healing provided.")
end
end
else
if config.printTest then
print("Regen is in-active due to combat.")
end
end
addEvent(regenPercentageHealthOverTime, config.time, player:getId())
end
end
end
local creatureEvent = CreatureEvent("creatureEventName")
function creatureEvent.onLogin(player)
if config.option == 1 then
regenPercentageHealthOverTime(player:getId())
elseif config.option == 2 then
regenPercentageHealthOverTime(player)
else
print("Choose between option 1 or option 2.")
end
return true
end
creatureEvent:register()