function AddHPMP takes boolean HP, integer v, unit u returns nothing
local integer a
local integer s
local integer i
local integer l
local integer cv
local integer mv
if HP then
set a = udg_Abilities2[1]
else
set a = udg_Abilities2[2]
endif
if ( v >= 0 ) then
set s = 1
set cv = v
else
set s = 5
set cv = v * - 1
endif
set mv = cv - ( cv / 1000 ) * 1000
set l = cv / 1000
set i = 1
loop
exitwhen i > l
call UnitAddAbility( u, a )
call SetUnitAbilityLevel( u, a, ( 4 + s ) )
call UnitRemoveAbility( u, a )
set i = i + 1
endloop
set cv = mv
set mv = cv - ( cv / 100 ) * 100
set l = cv / 100
set cv = mv
set i = 1
loop
exitwhen i > l
call UnitAddAbility( u, a )
call SetUnitAbilityLevel( u, a, ( 3 + s ) )
call UnitRemoveAbility( u, a )
set i = i + 1
endloop
set mv = cv - ( cv / 10 ) * 10
set l = cv / 10
set cv = mv
set i = 1
loop
exitwhen i > l
call UnitAddAbility( u, a )
call SetUnitAbilityLevel( u, a, ( 2 + s ) )
call UnitRemoveAbility( u, a )
set i = i + 1
endloop
set i = 1
loop
exitwhen i > cv
call UnitAddAbility( u , a )
call SetUnitAbilityLevel( u, a, ( 1 + s ) )
call UnitRemoveAbility( u, a )
set i = i + 1
endloop
set u = null
endfunction