How to trigger Critical Strike?

Status
Not open for further replies.
Level 4
Joined
Sep 2, 2016
Messages
48
I want a unit to Critical-Strike with a dynamic probability.
I created 2 level ability. Level 1 0%, level 2 100%. The unit starts with level 1.
I made a trigger OnAttack. If I want the unit to Critical-Strike, I "setability" to level 2.
The unit uses Critical Strike only if it is second or more time to use it. It doesn't use it when I switch it back to level 1.
Does anyone know what I am talking about?
How to control conditions of a Critical Strike?
 
Level 4
Joined
Sep 2, 2016
Messages
48
you have to order unit to stop and attack again instead
I did that.
The hero does not Critical-Strike. In addition it does not play attack animation.
As I wrote before, it Critical-Strike from the second hit in a row. But it DOESNOT Critical-Strike from the first hit in a row.
Can you make an example map, please?
 
Level 4
Joined
Sep 2, 2016
Messages
48
There is the unitevent EVENT_UNIT_TARGET_IN_RANGE
Unfortunately it is not for a generic unit, but a specific one, created with the map, not by the triggers. That is not what i need. But thanks.

I thought that, despite Critical-Strike calculations are done before UNIT_ATTACKED, I can modify damage of a unit, with a self-aura. Looks like a melee attack is in fact a missle of melee range and it's power is defined along with Critical Strike.

I am hoping that DracoL1ch will show me how to make it work with "stop" + "order to attack".https://www.hiveworkshop.com/members/dracol1ch.200261/
 
Level 21
Joined
May 16, 2012
Messages
644
i've created my own critical strike event using the new damage natives. I even make the unit play the "Attack Slam" Animation. I also created an event using a real variable to do stuff when a critical strike happen. Its pretty simple but pretty usefull.
JASS:
scope CriticalStrike initializer Init

private function Actions_onDamage takes nothing returns nothing
    local unit source = GetEventDamageSource()
    local unit target = BlzGetEventDamageTarget()
    local real damage = GetEventDamage() * udg_CriticalStrikeMultiplier[GetUnitUserData(source)]
 
    call BlzSetEventDamage(damage)
    //Critical Strike Event Units
    set udg_CSSource = source
    set udg_CSTarget = target
    set udg_CriticalStrikeEvent = 0.0
    set udg_CriticalStrikeEvent = 1.0
    set udg_CriticalStrikeEvent = 0.0

    call CreateTextOnUnit(udg_CSTarget, (I2S(R2I(damage)) + "!"), 1.5, 255, 0, 0, 255)

    set udg_CriticalBoolean[GetUnitUserData(source)] = false
 
    set source = null
    set target = null
endfunction

private function Actions_onAttack takes nothing returns nothing
    local unit source = GetAttacker()

    set udg_CriticalBoolean[GetUnitUserData(source)] = true
    call SetUnitAnimation(source, "Attack Slam")
    call QueueUnitAnimation(source, "Stand Ready")

    set source = null
endfunction

private function Conditions_OnDamage takes nothing returns boolean
    local unit source = GetEventDamageSource()
    local unit target = BlzGetEventDamageTarget()

    if(BlzGetEventDamageType() == DAMAGE_TYPE_NORMAL and UnitAlive(target) and IsUnitType(target, UNIT_TYPE_STRUCTURE) == false and udg_CriticalBoolean[GetUnitUserData(source)] == true) then
        call Actions_onDamage()
    endif

    set target = null
    set source = null
    return false
endfunction

private function Conditions_OnAttack takes nothing returns boolean
    if GetRandomInt(1,100) <= udg_CriticalStrikeChance[GetUnitUserData(GetAttacker())] then
        call Actions_onAttack()
    endif
    return false
endfunction
//===========================================================================
private function Init takes nothing returns nothing
    set gg_trg_CriticalStrike = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_CriticalStrike, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_CriticalStrike, Condition(function Conditions_OnAttack))
    call TriggerRegisterAnyUnitEventBJ(gg_trg_CriticalStrike, EVENT_PLAYER_UNIT_DAMAGED)
    call TriggerAddCondition(gg_trg_CriticalStrike, Condition(function Conditions_OnDamage))
endfunction

endscope

You also need to create a integer array called CriticalStrikeChance, one real array called CriticalStrikeMultiplier and one boolean array called CriticalBoolean, The integer and real arrays must be initialized (I initialize them using bribes Unit Event library event "OnIndex")

JASS:
function Trig_CriticalInit_Actions takes nothing returns nothing
    set udg_CriticalStrikeChance[udg_UDex] = 1.00
    set udg_CriticalStrikeMultiplier[udg_UDex] = 1.25
endfunction

//===========================================================================
function InitTrig_CriticalInit takes nothing returns nothing
    set gg_trg_CriticalInit = CreateTrigger(  )
    call TriggerRegisterVariableEvent( gg_trg_CriticalInit , "udg_UnitIndexEvent", EQUAL, 1.00 )
    call TriggerAddAction( gg_trg_CriticalInit , function Trig_CriticalInit_Actions )
endfunction

Lets say you want to give a unit critical strike, simply do:
JASS:
set udg_CriticalStrikeChance[GetUnitUserData(GetTriggerUnit())] = udg_CriticalStrikeChance[GetUnitUserData(GetTriggerUnit())] + 10
set udg_CriticalStrikeMultiplier[GetUnitUserData(GetTriggerUnit())] = udg_CriticalStrikeMultiplier[GetUnitUserData(GetTriggerUnit())] + 0.25
when your unit levels the respective ability or acquires certain item. The only problem with that is when using illusions, then you need to also set the chance and multiplyer for te illusions
 
Status
Not open for further replies.
Top