HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is this trigger safe?

03-11-2011, 07:41 AM#1
DanThanh
My spells are mainly auto-cast spells. I use Dusk's Damage Detection system to do this. For a long time, everything is ok, but recently many strange things have happened (Some triggers stop running) so i am starting to doubt. I posted a thread here to ask for help.
By following Anitarf''s advice, i tried to change mostly triggers which use Damage Detection to library but some triggers still never fire.
I think maybe the reason is from my auto-cast spells, so am going to use Anitarf's DamageEvent instead but i'm not sure if it will solve my problem.
Here is the code of my spells (Simple):

Collapse JASS:
scope Example initializer Init

//***************************************************
globals
  private constant integer abiID           = 'A01G'
  private constant integer bufID           = 'B03A' 
endglobals
//****************************************************

private function con takes nothing returns boolean
  return GetTriggerDamageType() == DAMAGE_TYPE_ATTACK and GetUnitAbilityLevel(GetTriggerUnit(), bufID) > 0 and GetUnitTypeId(GetTriggerDamageSource()) == uniID
endfunction

private function act takes nothing returns nothing
  local unit c = GetTriggerDamageSource()
  local unit t = GetTriggerDamageTarget()
  local real dam = GetTriggerDamage()
  .....
  set c = null
  set t = null
  set p = null
endfunction

private function Init takes nothing returns nothing
  local trigger trg = CreateTrigger()
  call TriggerRegisterDamageEvent(trg, 1)
  call TriggerAddCondition(trg, Condition(function con))
  call TriggerAddAction(trg, function act)
endfunction
endscope

I want to ask whether this trigger safe or not. Thanks for reading and hope that i will get the help i need.

Also private function Init takes nothing returns nothing and public function InitTrig takes nothing returns nothing are both seem unreliable since they only work if i use one of them, sometimes i have to try this and that way.
03-11-2011, 09:12 AM#2
Anitarf
The code you posted seems okay. If this is meant to detect autocast spells, then it won't work if you have this in the condition: GetTriggerDamageType() == DAMAGE_TYPE_ATTACK Unless you mean autocast attack-based spells like frost arrows, not regular autocast spells like slow? We need more information.

For example, what part of the spell does not work? Try adding some debug messages to the initialization function, the condition and action to see if the trigger is created/runs at all and at which point it fails.
03-11-2011, 09:59 AM#3
DanThanh
Thank you. I use only frost arrow for my autocast spells, recently i create some more spells with the same syntax and some triggers suddenly stop working. I tried to configure the reason but there is no clue.
btw, if i use your DamageEvent&Modifier, what should the code above looks like?
03-11-2011, 02:36 PM#4
Fledermaus
If I remember correctly, Frost Arrows will only apply the buff (which is needed to make the trigger run) if the target is a ranged attacker (via Combat - Weapon Type being Missile). If you want to use an autocast on attack ability for melee units, you'll need to use Incinerate.