- Joined
- Apr 12, 2018
- Messages
- 494
Well in RoC there just plain wasn't an Inventory ability; that was introduced in TFT. It's probably another thing that somehow bled into the RoC data because of compatibility reasons.
function UnitFilter takes nothing returns boolean
return GetFilterUnit() == someUnit
endfunction
...
call TriggerRegisterPlayerUnitEvent(trg, plr, EVENT_PLAYER_UNIT_DEATH, function UnitFilter)
Maybe there is no "GetFilterUnit" in that context. Try with triggering unit or some other event response unit.Unit filters don't work with player unit death events. Or has this always been the case and it's intended? Because it works fine with other events.
GetFilterUnit()
should only work when the event itself was fired, so only when the trigger action/condition runs. But not at registration.I tested with the death event, and it seems the filter function at registration isn't fired at all for me. So I couldn't do anything there. Are you sure it works for you somewhere - might you attach a demo?whereas GetFilterUnit works for at least EVENT_PLAYER_UNIT_CONSTRUCT_FINISH and EVENT_PLAYER_UNIT_SPELL_CAST.
function PeasantFilter takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'hpea'
endfunction
function PeasantDeath takes nothing returns nothing
call BJDebugMsg(GetUnitName(GetDyingUnit()))
endfunction
//===========================================================================
function InitTrig_Test_Death takes nothing returns nothing
set gg_trg_Test_Death = CreateTrigger( )
call TriggerRegisterPlayerUnitEvent(gg_trg_Test_Death, Player(0), EVENT_PLAYER_UNIT_DEATH, function PeasantFilter)
call TriggerAddAction( gg_trg_Test_Death, function PeasantDeath )
endfunction
function PriestFilter takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'hmpr'
endfunction
function PriestSpell takes nothing returns nothing
call BJDebugMsg(GetUnitName(GetSpellAbilityUnit()))
endfunction
//===========================================================================
function InitTrig_Test_Spell takes nothing returns nothing
set gg_trg_Test_Spell = CreateTrigger( )
call TriggerRegisterPlayerUnitEvent(gg_trg_Test_Spell, Player(0), EVENT_PLAYER_UNIT_SPELL_CAST, function PriestFilter)
call TriggerAddAction( gg_trg_Test_Spell, function PriestSpell )
endfunction
function Actions takes nothing returns nothing
if GetUnitTypeId(GetFilterUnit()) == 'Hpal' then
call BJDebugMsg(GetUnitName(GetFilterUnit()))
endif
endfunction
function InitTrig_Test_Spell takes nothing returns nothing
set gg_trg_Test_Spell = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(gg_trg_Test_Spell, Player(0), EVENT_PLAYER_UNIT_SPELL_CAST, function Actions)
endfunction
GetTriggerExecCount
or GetTriggerExecCount
are probably rarely used, but they would probably return not expected result.Same here, but untested AFAIK too.But I have always assumed they were faster.
Are you saying GetFilterUnit() and GetEnumUnit() are interchangeable or am I misunderstanding?![]()
Filtered events won't increase GetTriggerEvalCount.Hmm, there must be some advantage or reason to the filter functions, otherwise why are they there? Seems like they should stop execution at some earlier point than conditions or actions.
Cool, good to know. So I assume that means it's preferable to use conditions instead of actions where possible?Filtered events won't increase GetTriggerEvalCount.
The same with triggerconditions: if triggerconditions filter an successful event evalutation GetTriggerExecCount won't increase.
Cool, good to know. So I assume that means it's preferable to use conditions instead of actions where possible?
Ah, I see what you mean. No, there probably isn't an impact, since the value is probably stored in a 32-bit integer for all triggers. I doubt the value is only stored for triggers that have already exececuted and is dynamically allocated at first execution.I meant using TriggerAddCondition over TriggerAddAction so that GetTriggerExecCount doesn't increase. I've never used GetTriggerEval/ExecCount either, but I assume it has an impact on memory usage (though probably marginal) if they increase?
this trigger counters allow easy built in counters attached to triggers with that also to events, therefore without any further effort.I have never had the need to actually use those natives. If you really needed something like that, just make an integer and increase it every time the filter runs.
scope s initializer init
private function onDeathFilter nothing returns boolean
call BJDebugMsg(GetUnitName(GetFilterUnit()))
return true
endfunction
private function init takes nothing returns nothing
call TriggerRegisterPlayerUnitEvent(CreateTrigger(), Player(0), EVENT_PLAYER_UNIT_DEATH, Filter(function onDeathFilter))
endfunction
endscope
FilterUnit in Death/Attack Events refere to the killer/attacker, probably a takeover from the specific unit events. That is why one thinks it does not work; in your example: do a kill with a peasant then your trigger should execute.