• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

JASS Passive Ability Help Request

Status
Not open for further replies.
Level 7
Joined
Jul 9, 2008
Messages
253
Hello everybody, so I was wondering if there is a way to make like a passive ability that does for instance 50 bonus damage on every 4th attack. I use JASS ( not vJASS ) and was wondering if this is possible with a trigger, maybe with a hashtable or so to count the attacks? I don't mind the "unit is attacked" start so no damage detection required.

Help would be nice.

Thanks in advance, Quetzalcotl
 
Well, since you want it inefficient, I will provide it :)

It uses A unit is attacked as an event, starting from A unit learns a skill; once you learn the skill, then your trigger will begin counting.

  • Two
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hashtable = (Last created hashtable)
JASS:
function Trig_One_Conditions takes nothing returns boolean
    return GetLearnedSkillBJ() == 'A000' //Replace 'A000' with the rawcode of your ability; press Ctrl + D to view your ability names into rawcodes.
endfunction

function Attacks takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local integer id = GetHandleId (t)
    local integer i = LoadInteger (udg_Hashtable, id, StringHash("number"))
    local unit u = GetAttacker()
    local unit u1
    local unit u2 = GetTriggerUnit()
    if i == 0 then
        set u1 = LoadUnitHandle (udg_Hashtable, id, StringHash("caster"))
        if u == u1 then
            call UnitDamageTarget (u, u2, 50, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        endif
        call SaveInteger (udg_Hashtable, id, StringHash("number"), 4)
    else
        call SaveInteger (udg_Hashtable, id, StringHash("number"), i - 1)
    endif
    set u = null
    set u1 = null
    set u2 = null
endfunction

function Trig_One_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local trigger t = CreateTrigger()
    local integer id = GetHandleId (t)
    local integer i = 4 //Number of attacks
    call TriggerRegisterAnyUnitEventBJ (t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddAction (t, function Attacks)
    call SaveInteger (udg_Hashtable, id, StringHash("number"), i)
    call SaveUnitHandle (udg_Hashtable, id, StringHash("caster"), u)
    set u = null
endfunction

//===========================================================================
function InitTrig_One takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition( t, Condition( function Trig_One_Conditions ) )
    call TriggerAddAction( t, function Trig_One_Actions )
endfunction

Test map:

View attachment Jass Bonus 50 damage.w3x
 
Level 7
Joined
Jul 9, 2008
Messages
253
Okey it works, is there a way to make it more efficient? :p

P.S. It does bonus damage on the 5th attack but that's not a problem ;)
 
Status
Not open for further replies.
Top