I also included two Conditions that you can apply, Wounded and Sapped, that will prevent health and mana regen respectively.
Constants
var
const
REGEN_HEALTH_PERCENT = 1
REGEN_MANA_PERCENT = 2
REGEN_TICK_LENGTH = 10
// Regen only on players, or monsters too?
REGEN_ONLY_PLAYERS = 1
world
New()
..()
spawn() tick_regen()
proc
tick_regen()
spawn(Constants.REGEN_TICK_LENGTH)
tick_regen()
var/regen
for(var/mob/M in world)
if(Constants.REGEN_ONLY_PLAYERS && !M.key)
continue
regen = max(1, round(M.max_health * Constants.REGEN_HEALTH_PERCENT / 100))
if(M.has_condition(/Condition/Wounded))
regen = 0
M.gain_health(regen)
regen = max(1, round(M.max_mana * Constants.REGEN_MANA_PERCENT / 100))
if(M.has_condition(/Condition/Sapped))
regen = 0
M.gain_mana(regen)
Condition
Wounded
tick_count = 4
tick_rate = 40
icon_state = "wounded"
tick()
target.effect("wounded")
Sapped
tick_count = 4
tick_rate = 40
icon_state = "sapped"
tick()
target.effect("sapped")
There are a few things I'd change here. I don't like the idea of checking for a condition by type because you might want to have other conditions that also apply the effect. I'm not sure what the best way to handle this is but for now I'd probably make it work like the "slowed" condition. I'd also call the regen from the mob's movement() or action() proc - those procs are automatically called every tick for every active mob. That way you're using a loop that already exists and you're not bothering to check the regen for mobs on maps that aren't being used.