HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

I can't add Stunbuff?

03-25-2011, 08:15 AM#1
AzuhaSky
I have a System:Unitstatus(by Rising_Dusk) .It have a action code:call StunUnitTimed(u, 4.0) //Adds a timed stun to a unit!
But my trigger:
Collapse JASS:
scope MyTrig

//Creat globals------------------------------------------
globals
  private constant integer abiID           = 'A000'
  private constant string SFX              = "MDX\\Bomb.mdl"
endglobals
//End globals---------------------------------------------

private function MyTrig_Co takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

private function MyTrig_Ac takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local integer abilv = GetUnitAbilityLevel(c, abiID)
    local player p = GetOwningPlayer(c)
    local unit t = GetSpellTargetUnit()
    local real tx = GetUnitX(t)
    local real ty = GetUnitY(t)
    local Ex fx
    set fx = Ex.create(tx, ty, 0.0)
    set fx.fxpath           = "dummy.mdl"
    set fx.scale            = 0.85
    set fx.speed            = 800.0 
    set fx.z                = 90.
    set fx.expirationTime   = 1.1
    set fx.source            = c
    set fx.lvl              = abilv
    set c    = null
    set p    = null
    set t    = null
endfunction

private struct Ex extends xecollider
       unit source
       unit targ
       method onUnitHit takes unit target returns nothing
          if IsUnitEnemy(target, GetOwningPlayer(this.source)) and (this.source != target) and GetUnitAbilityLevel(target, 'Avul') == 0 then
               call DestroyEffect(AddSpecialEffectTarget(SFX, target, "origin"))
               call StunUnitTimed(target, 4.0)
               call this.terminate()
          endif
       endmethod
       
       method onDestroy takes nothing returns nothing
           set this.source = null 
           set this.targ = null
       endmethod
       
endstruct

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(trig, function MyTrig_Ac)
    call TriggerAddCondition(trig, Condition(function MyTrig_Co))
    set trig = null
endfunction
endscope

Timed buff equal 4.0 seconds,but in game,Stun on unit during 1.0 seconds!Why?
03-25-2011, 05:51 PM#2
zeroXD
I don't know. Perhaps the issue lies in the object editor? You should check the duration field of the buff itself.
03-25-2011, 06:42 PM#3
Anitarf
Perhaps you have some other code in your map that removes the stun buff from the unit prematurely. I'm not sure what else could be the problem, looking at the code the stun should last 4 seconds, not 1.
03-27-2011, 04:40 AM#4
AzuhaSky
I don't know!I edit some StunID in system(For ID stunned ability create from thunderbolt),I think StunID in system mismatch with Spell Id in Object Editor so i did it!
03-28-2011, 08:25 AM#5
Bribe
1. Move the function below the struct so it doesn't compile into a function interface when using Ex.create.

2. Combine the actions and events or, even better, use Anitarf's SpellEvent.

3. The conditions reference the rawcode when they should reference the constant directly.

4. You don't need to store tx and ty into locals as you only reference them once.

5. GetOwningPlayer(c) could be GetTriggerPlayer() because it's a playerunitevent.

6. You could just use GetSpellTargetX/Y instead of getting the target unit's x/y

7. You don't need to set the fx's z to 90 because it's already defaulted to 90.

8. You never reference player p either, so just get rid of it?
03-28-2011, 10:27 PM#6
Anitarf
I tried testing the code you posted, but it didn't even compile, so I'm not sure how you were able to test it yourself.

After fixing the compile issues, I tested the code ingame and nothing happened. It turned out the spell wasn't being initialized at all. Changing the code from the InitTrig hack to a proper initializer fixed the problem, the spell works and properly lasts 4 seconds. Here is the code I ended up with, I highlighted the changes necessary to make it work:

Collapse JASS:
scope MyTrig initializer Init

//Creat globals------------------------------------------
globals
  private constant integer abiID           = 'Aslo'
  private constant string SFX              = "MDX\\Bomb.mdl"
endglobals
//End globals---------------------------------------------

private function MyTrig_Co takes nothing returns boolean
    return GetSpellAbilityId() == 'Aslo'
endfunction

private keyword Ex
private function MyTrig_Ac takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local integer abilv = GetUnitAbilityLevel(c, abiID)
    local player p = GetOwningPlayer(c)
    local unit t = GetSpellTargetUnit()
    local real tx = GetUnitX(t)
    local real ty = GetUnitY(t)
    local Ex fx
    set fx = Ex.create(tx, ty, 0.0)
    set fx.fxpath           = "dummy.mdl"
    set fx.scale            = 0.85
    set fx.speed            = 800.0 
    set fx.z                = 90.
    set fx.expirationTime   = 1.1
    set fx.source            = c
    set fx.lvl              = abilv
    set c    = null
    set p    = null
    set t    = null
endfunction

private struct Ex extends xecollider
       unit source
       unit targ
       integer lvl
       method onUnitHit takes unit target returns nothing
          if IsUnitEnemy(target, GetOwningPlayer(this.source)) and (this.source != target) and GetUnitAbilityLevel(target, 'Avul') == 0 then
               call DestroyEffect(AddSpecialEffectTarget(SFX, target, "origin"))
               call StunUnitTimed(target, 4.0)
               call this.terminate()
          endif
       endmethod
       
       method onDestroy takes nothing returns nothing
           set this.source = null 
           set this.targ = null
       endmethod
       
endstruct

private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(trig, function MyTrig_Ac)
    call TriggerAddCondition(trig, Condition(function MyTrig_Co))
    set trig = null
endfunction
endscope

This code works, but it's far from being good. You should look into making the changes that Bribe suggested, as well as the following:

You seem to make the collider at the position of the target, so it will instantly collide and stun the unit. If that is what you want (although I suspect you wanted to create the collider at the location of the caster), why use a collider in the first place, you could just stun the unit from the MyTrig_Ac function.
04-11-2011, 07:10 AM#7
AzuhaSky
Oh!Thank you so much!I can do it!