- Joined
- May 16, 2012
- Messages
- 644
So, i have an item trigger that increases hero stats and hp regen for each unit it kills, and it should stop increasing stats and stop regenerate hp when my unit do not have the item anymore. My initial idea was to check if my unit is in a global group and then, add that unit to that group if its not in it already. Using another trigger that fires when a unit loses an item i check if the unit has my specific item and if not, i remove it from my global group and that unit does not have hp regen anymore. The first part is working nicely, but the second part, where i remove the unit from the global group is not working, so what i should do?
JASS:
function Elemental_Stone_Conditions takes nothing returns boolean
return ( UnitHasItemOfTypeBJ(GetKillingUnit(), 'I039') == true )
endfunction
function Elemental_Stone_Hero_Filter takes nothing returns boolean
return ( IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true )
endfunction
function Elemental_Stone_Actions takes nothing returns nothing
local unit u
set u = GetKillingUnit()
if ( Elemental_Stone_Hero_Filter() ) then
set udg_ES_Integer[GetUnitPointValue(u)] = ( udg_ES_Integer[GetUnitPointValue(u)] + 10000 )
call ModifyHeroStat( bj_HEROSTAT_STR, u, bj_MODIFYMETHOD_ADD, 5000 )
call ModifyHeroStat( bj_HEROSTAT_AGI, u, bj_MODIFYMETHOD_ADD, 5000 )
call ModifyHeroStat( bj_HEROSTAT_INT, u, bj_MODIFYMETHOD_ADD, 5000 )
else
set udg_ES_Integer[GetUnitPointValue(u)] = ( udg_ES_Integer[GetUnitPointValue(u)] + 10 )
call ModifyHeroStat( bj_HEROSTAT_STR, u, bj_MODIFYMETHOD_ADD, 5 )
call ModifyHeroStat( bj_HEROSTAT_AGI, u, bj_MODIFYMETHOD_ADD, 5 )
call ModifyHeroStat( bj_HEROSTAT_INT, u, bj_MODIFYMETHOD_ADD, 5 )
endif
if(( IsUnitInGroup(u, udg_ES_Group) == false ))then
call GroupAddUnit(udg_ES_Group, u)
endif
set u = null
endfunction
//===========================================================================
function InitTrig_Elemental_Stone takes nothing returns nothing
set gg_trg_Elemental_Stone = CreateTrigger( )
call DisableTrigger(gg_trg_Elemental_Stone)
call TriggerRegisterAnyUnitEventBJ( gg_trg_Elemental_Stone, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Elemental_Stone, Condition( function Elemental_Stone_Conditions ) )
call TriggerAddAction( gg_trg_Elemental_Stone, function Elemental_Stone_Actions )
endfunction
JASS:
function Es_Removal_Conditions takes nothing returns boolean
return ( GetManipulatedItem() == GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), 'I039') )
endfunction
function Es_Removal_Actions takes nothing returns nothing
local item i
local unit u
set u = GetManipulatingUnit()
set i = GetItemOfTypeFromUnitBJ(u, 'I039')
if(i == null)then
call GroupRemoveUnit(udg_ES_Group, u)
endif
set u = null
set i = null
endfunction
//===========================================================================
function InitTrig_Es_Removal takes nothing returns nothing
set gg_trg_Es_Removal = CreateTrigger( )
call DisableTrigger(gg_trg_Es_Removal)
call TriggerRegisterAnyUnitEventBJ( gg_trg_Es_Removal, EVENT_PLAYER_UNIT_DROP_ITEM )
call TriggerAddCondition( gg_trg_Es_Removal, Condition( function Es_Removal_Conditions ) )
call TriggerAddAction( gg_trg_Es_Removal, function Es_Removal_Actions )
endfunction
JASS:
function ES_Heal takes nothing returns nothing
local unit u
set u = GetEnumUnit()
call DestroyEffect(AddSpecialEffectTargetUnitBJ( "origin", u, "war3mapImported\\PurpleSphere.mdl" ))
call SetUnitLifeBJ( u, ( GetUnitStateSwap(UNIT_STATE_LIFE, u) + I2R(udg_ES_Integer[GetUnitPointValue(u)]) ) )
set u = null
endfunction
function Es_Effect_Actions takes nothing returns nothing
call ForGroup(udg_ES_Group, function ES_Heal)
endfunction
//===========================================================================
function InitTrig_Es_Effect takes nothing returns nothing
set gg_trg_Es_Effect = CreateTrigger( )
call DisableTrigger( gg_trg_Es_Effect )
call TriggerRegisterTimerEventPeriodic( gg_trg_Es_Effect, 0.5 )
call TriggerAddAction( gg_trg_Es_Effect, function Es_Effect_Actions )
endfunction
Last edited: