• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Help with JASS Trigger

Status
Not open for further replies.
Level 1
Joined
May 18, 2009
Messages
4
So hi ppl. First I want to say I'm new to JASS (actually I started learning JASS yesterday). I want to make a spell, which gives a buff to the attacked unit, and lowers its armor. The spell is stackable (stacks 5 times). I actually am trying to give the attacked unit the ability, which targets Self, and lower its armor but :S little problem here.
Here's where I've come to:
JASS:
function earthborerAcid_Actions takes nothing returns nothing
local integer rand=GetRandomInt(0,100)
    call Msg("Acid_Actions has been called.")
    set udg_unit=GetAttackedUnitBJ()
    if (rand>=0) and (rand<=20) then
        call earthborerAcid_GiveSpell()
    endif
endfunction

function earthborerAcid_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetAttacker())=='h000'
endfunction

function InitTrig_earthborerAcid takes nothing returns nothing
local trigger myTrigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(myTrigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(myTrigger, Condition(function earthborerAcid_Conditions))
    call TriggerAddAction(myTrigger, function earthborerAcid_Actions)
    set myTrigger = null
endfunction
That is my main trigger. As you see the attacker (h000) has 20% chance of stacking the ability on its enemy.
JASS:
function earthborerAcid_GiveSpell takes nothing returns nothing
    call Msg("Acid GiveSpell has been called.")
    if (UnitHasBuffBJ(udg_unit, 'B000')==false) then
        call UnitAddAbility(udg_unit, 'A001')
        call Msg("-3 triggered")
        return
    endif
    if (UnitHasBuffBJ(udg_unit,'B000')==true) then
        call UnitRemoveBuffBJ('B000',udg_unit)
        call UnitRemoveAbility(udg_unit, 'A001')
        call UnitAddAbility(udg_unit, 'A002')
        call Msg("-6 triggered")
        return
    endif
    if (UnitHasBuffBJ(udg_unit,'B001')==true) then
        call UnitRemoveBuffBJ('B001',udg_unit)
        call UnitRemoveAbility(udg_unit, 'A002')
        call UnitAddAbility(udg_unit, 'A003')
        call Msg("-9 triggered")
        return
    endif
    if (UnitHasBuffBJ(udg_unit,'B002')==true) then
        call UnitRemoveBuffBJ('B002',udg_unit)
        call UnitRemoveAbility(udg_unit, 'A003')
        call UnitAddAbility(udg_unit, 'A004')
        call Msg("-12 triggered")
        return
    endif
    if (UnitHasBuffBJ(udg_unit,'B003')==true) then
        call UnitRemoveBuffBJ('B003',udg_unit)
        call UnitRemoveAbility(udg_unit, 'A004')
        call UnitAddAbility(udg_unit, 'A005')
        call Msg("-15 triggered")
        return
    endif
endfunction
So what this is supposed to do is: when the function is called it checks whether and which buff the attacked unit has (I've made 5 spells and 5 buffs) and according to that give the unit the next "level" ability.
Up to here with the theory. What this does is give the unit like -3 armor, next time -6, then instead of -9, the unit gets 2 spells/2 buffs (-3 and -6 armor) and thats it. From here the buff starts acting stupid - from -3 to -6/-9 and that's it. -12 and -15 never get triggered.
If someone can help me it'll be very nice, cause I've been banging my head for quite some time, and redone the trigger several times in several different ways. Again - I'm a newb so pls don't flame me.
P.S. I hope I'm writting it the right forum section. If not - sorry :con:
 
Level 11
Joined
Feb 22, 2006
Messages
752
Instead of checking buffs, you can check ability levels. Just make one ability and make it have 5 levels. Then:

JASS:
function earthborerAcid_GiveSpell takes unit u returns nothing
    local integer level = GetUnitAbilityLevel(u, 'A000')
    if (level == 0) then
        call UnitAddAbility(u, 'A000')
    else
        call SetUnitAbilityLevel(u, 'A000', level + 1)
    endif
endfunction

function earthborerAcid_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call Msg("Acid_Actions has been called.")
    if (GetRandomInt(0, 100)<=20) then
        call earthborerAcid_GiveSpell(u)
    endif
    set u = null
endfunction
function earthborerAcid_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetAttacker())=='h000'
endfunction
function InitTrig_earthborerAcid takes nothing returns nothing
    local trigger myTrigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(myTrigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(myTrigger, Condition(function earthborerAcid_Conditions))
    call TriggerAddAction(myTrigger, function earthborerAcid_Actions)
endfunction
 
Status
Not open for further replies.
Top