- Joined
- Feb 26, 2005
- Messages
- 210
I want Heroes in my map to deal extra damage depending on how much hit points they have left. For every 10% of they deal 1 additional damage. How I got this to work is I gave every hero an ability based on the item damage bonus; made that ability have eleven levels which at level one adds 10 damage and at level eleven adds 0 damage; then I made the following trigger and it works. The code also moves the hero to the player's base for unrelated reasons.
However; I do not know if this trigger is going to cause problems in multiplayer due to leaks or bad coding on my part. What ways can I improve this code?
JASS:
function Trig_Hero_Conditions takes nothing returns boolean
if ( not ( IsUnitType(GetSoldUnit(), UNIT_TYPE_HERO) == true ) ) then
return false
endif
return true
endfunction
function Trig_Hero_Actions takes nothing returns nothing
local unit u = GetSoldUnit()
local integer i = 1
local location l
local location l2
set l = GetUnitLoc(udg_PlayerBase[GetConvertedPlayerId(GetOwningPlayer(u))])
set l2 = GetRectCenter(gg_rct_Battlefield)
set l = PolarProjectionBJ(l, 275.00, AngleBetweenPoints(l, l2))
call SetUnitPositionLoc( u, l )
call SetUnitFacingToFaceLocTimed( u, l2, 0 )
call RemoveLocation (l)
call RemoveLocation (l2)
loop
call TriggerSleepAction( 0.05 )
set i = 11 - (R2I(GetUnitLifePercent(u)) / 10)
if GetUnitAbilityLevelSwapped('A001', u) != i then
call SetUnitAbilityLevelSwapped( 'A001', u, i )
endif
endloop
set u = null
endfunction
//===========================================================================
function InitTrig_Hero_Damage_Bonus takes nothing returns nothing
set gg_trg_Hero_Damage_Bonus = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Damage_Bonus, EVENT_PLAYER_UNIT_SELL )
call TriggerAddCondition( gg_trg_Hero_Damage_Bonus, Condition( function Trig_Hero_Conditions ) )
call TriggerAddAction( gg_trg_Hero_Damage_Bonus, function Trig_Hero_Actions )
endfunction
However; I do not know if this trigger is going to cause problems in multiplayer due to leaks or bad coding on my part. What ways can I improve this code?