Warcraft III resources & community, 2003–2006 · archived

please help a noob

6 posts
#1

please help a noob

ok i cant seem to get this trigger to work
function HSC takes nothing returns boolean
    return GetAttacker() == 'Huth'
endfunction

function HSA takes nothing returns nothing
    if ( udg_I < 10 ) then
        set udg_I = (udg_I + 1)
        else
        call AddSpecialEffectLocBJ( GetUnitLoc(GetAttackedUnitBJ()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )
        call AddSpecialEffectLocBJ( GetUnitLoc(GetAttackedUnitBJ()), "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl" )
        call UnitDamageTargetBJ( GetAttacker(), GetAttackedUnitBJ(), ( I2R(GetHeroStatBJ(bj_HEROSTAT_INT, GetAttacker(), true)) * 0.08 ), ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL )
        set udg_I = 0
    endif
endfunction

function HSE takes nothing returns nothing
    local trigger t
    set udg_I = 0
    set t= CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ (t, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(t, Condition(function HSC))
    call TriggerAddAction(t, function HSA)
endfunction


basically, on every tenth attack the hero makes, he would deal bonus damage. but i cant seem to get it to work! :oops:
#2
You don't use GetAttacker(). You should use GetDamageSource() (I think... look in the JASS Editor). That's the right event-response for the Unit Is Damaged event.

~Daelin
#3



function Trig_HeroAttackCounter_Conditions takes nothing returns boolean
    return  GetUnitTypeId( GetAttacker() ) == 'Huth'
endfunction

function Trig_HeroAttackCounter_Actions takes nothing returns nothing
    set udg_HeroattackCounter = udg_HeroattackCounter + 1
    
    if udg_HeroattackCounter == 10 then
        set udg_HeroattackCounter = 0
    endif
    
endfunction // this is a trigger which counts the heros attacks

//==== Init Trigger HeroAttackCounter ====
function InitTrig_HeroAttackCounter takes nothing returns nothing
    set gg_trg_HeroAttackCounter = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ (gg_trg_HeroAttackCounter, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_HeroAttackCounter, Condition(function Trig_HeroAttackCounter_Conditions))
    call TriggerAddAction(gg_trg_HeroAttackCounter, function Trig_HeroAttackCounter_Actions)
endfunction





function HSC takes nothing returns boolean
    return GetUnitTypeId( GetAttacker() ) == 'Huth' and udg_HeroattackCounter == 10
endfunction

function HSA takes nothing returns nothing
    local real x = GetUnitX ( GetTriggerUnit ( ) )
    local real y = GetUnitY ( GetTriggerUnit ( ) )

    call DestroyEffect ( AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" , x , y ) )
    call DestroyEffect ( AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl" , x , y ) )
    call UnitDamageTarget ( GetAttacker ( ) , GetTriggerUnit ( ) , GetHeroStr ( GetAttacker ( ) , false ) * 0.08 , true , false , ATTACK_TYPE_HERO , DAMAGE_TYPE_NORMAL , WEAPON_TYPE_WHOKNOWS )
        
endfunction

function HSE takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ (t, EVENT_PLAYER_UNIT_ATTACKED) // EVENT_UNIT_DAMAGED wont work,that is a unitevent while this function takes a playerunitevent,there is some difference.
                                                                       // actually there is a way to make the unit takes damage generic . . .
    call TriggerAddCondition(t, Condition(function HSC))
    call TriggerAddAction(t, function HSA)
    set t = null
endfunction



your previous trigger leaked so much. this will be okay.


EDIT :

@Daelin : as i said

TriggerRegisterAnyUnitEventBJ takes a playerunitevent as an argument,while unit takes damage is a unitevent , so it wont work with it.
#4
thanks guys. ill try and improve :oops:

PS: if i use EVENT_PLAYER_UNIT_ATTACKED, would it be like the "a unit is attacked" trigger in GUI? because then it can be abused.
#5
Nantuko_Husk@Daelin : as i said

TriggerRegisterAnyUnitEventBJ takes a playerunitevent as an argument,while unit takes damage is a unitevent , so it wont work with it.


Heh, I didn't notice that it was TriggerRegisterAnyUnitEvent. I know that EVENT_UNIT_DAMAGED doesn't work for any unit. ;)

~Daelin
#6
but wouldnt that trigger be abused with the delay when the unit STARTS to attack the enemy and when the damage is atually APPLIED?