• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Triggering via different spell levels

Status
Not open for further replies.
Level 26
Joined
Aug 18, 2009
Messages
4,097
There is the event
constant unitevent EVENT_UNIT_HERO_SKILL=ConvertUnitEvent(79)
, respectively
constant playerunitevent EVENT_PLAYER_HERO_SKILL=ConvertPlayerUnitEvent(42)
whereas
constant native GetLearnedSkill takes nothing returns integer
delivers the ability being learned and
constant native GetLearnedSkillLevel takes nothing returns integer
the new level or you ask for the current level of an ability for a unit via
native GetUnitAbilityLevel takes unit whichUnit, integer abilcode returns integer
.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Something like this:

  • Activate Triggers
    • Events
      • Unit - A unit Learns a skill
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Learned Hero Skill) Equal to [your ability]
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of [your ability] for (Triggering unit)) Equal to 1
            • Then - Actions
              • Trigger - Turn on (your trigger)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of [your ability] for (Triggering unit)) Equal to 2
            • Then - Actions
              • Trigger - Turn on (your trigger 2)
            • Else - Actions
          • -------- And so on... --------
        • Else - Actions
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
JASS:
function Trig takes nothing returns nothing
    local integer level = GetLearnedSkillLevel()

    if (level == 1) then
        //level 1 actions
    elseif (level == 2) then
        //level 2 actions
    else
        //all other levels actions
    endif
endfunction

function TrigConds takes nothing returns boolean
    return (GetLearnedSkill() == 'ABCD')
endfunction

function Init takes nothing returns nothing
    local trigger t = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(t, Condition(function TrigConds))
    call TriggerAddAction(t, function Trig)

    set t = null
endfunction

or if you want to have the current level on spelleffect event:

JASS:
function Trig takes nothing returns nothing
    local integer level = GetUnitAbilityLevel(GetSpellAbilityUnit(), 'ABCD')

    if (level == 1) then
        //level 1 actions
    elseif (level == 2) then
        //level 2 actions
    else
        //all other levels actions
    endif
endfunction

function TrigConds takes nothing returns boolean
    return (GetSpellAbilityId() == 'ABCD')
endfunction

function Init takes nothing returns nothing
    local trigger t = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function TrigConds))
    call TriggerAddAction(t, function Trig)

    set t = null
endfunction

You may also abandon the if/selection structure and directly assign/retrieve code:

JASS:
function ActionsOf1 takes nothing returns nothing
    //level 1 actions
endfunction

function ActionsOf2 takes nothing returns nothing
    //level 2 actions
endfunction

function ActionsOf3 takes nothing returns nothing
    //level 3 actions
endfunction

function Trig takes nothing returns nothing
    local integer level = GetUnitAbilityLevel(GetSpellAbilityUnit(), 'ABCD')

    call TriggerExecute(CODES[level])
endfunction

function TrigConds takes nothing returns boolean
    return (GetSpellAbilityId() == 'ABCD')
endfunction

function Init takes nothing returns nothing
    local trigger t = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function TrigConds))
    call TriggerAddAction(t, function Trig)

    set t = CreateTrigger()

    set CODES[1] = t
    call TriggerAddAction(t, function ActionsOf1)

    set t = CreateTrigger()

    set CODES[2] = t
    call TriggerAddAction(t, function ActionsOf2)

    set t = CreateTrigger()

    set CODES[3] = t
    call TriggerAddAction(t, function ActionsOf3)

    set t = null
endfunction

CODES
being a trigger array.
 
Status
Not open for further replies.
Top