• 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] GUI Based Critical Strike

Status
Not open for further replies.
Level 3
Joined
Jul 7, 2007
Messages
22
I am making a critical strike which is based on agility, it's chance and damage.
Currently this is what I have:
JASS:
function Trig_Critical_Strike_Chance_Func006C takes nothing returns boolean
    if ( not ( udg_Temp_Integer[4] < 15 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Critical_Strike_Chance_Func007C takes nothing returns boolean
    if ( not ( udg_Temp_Integer[4] >= 75 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Critical_Strike_Chance_Func013C takes nothing returns boolean
    if ( not ( udg_Temp_Integer[1] <= udg_Temp_Integer[4] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Critical_Strike_Chance_Actions takes nothing returns nothing
    set udg_Temp_Integer[1] = GetRandomInt(1, 100)
    set udg_Temp_Integer[2] = GetHeroStatBJ(bj_HEROSTAT_AGI, GetAttacker(), true)
    set udg_Temp_Integer[3] = 10
    // Divider
    set udg_Temp_Integer[4] = ( udg_Temp_Integer[2] / udg_Temp_Integer[3] )
    if ( Trig_Critical_Strike_Chance_Func006C() ) then
        set udg_Temp_Integer[4] = 15
    else
    endif
    if ( Trig_Critical_Strike_Chance_Func007C() ) then
        set udg_Temp_Integer[4] = 75
    else
    endif
    // Divider
    set udg_Temp_Real[1] = ( I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, GetAttacker(), true)) + I2R(GetHeroStatBJ(bj_HEROSTAT_STR, GetAttacker(), true)) )
    set udg_Temp_Real[2] = 1.50
    set udg_Temp_Real[3] = ( udg_Temp_Real[1] * udg_Temp_Real[2] )
    set udg_Temp_Real[3] = I2R(R2I(udg_Temp_Real[3]))
    if ( Trig_Critical_Strike_Chance_Func013C() ) then
        call UnitDamageTargetBJ( GetAttacker(), GetAttackedUnitBJ(), udg_Temp_Real[3], ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
        set udg_Temp_Point[1] = GetUnitLoc(GetAttacker())
        // Divider
        call CreateTextTagLocBJ( ( udg_PlayerColor[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))] + ( R2S(udg_Temp_Real[3]) + "!" ) ), udg_Temp_Point[1], 0, 9.00, 100, 100, 100, 0 )
        call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 64, 90 )
        call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
        call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 4.00 )
        call SetTextTagFadepointBJ( GetLastCreatedTextTag(), 3.00 )
        // Divider
        call RemoveLocation( udg_Temp_Point[1] )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Critical_Strike_Chance takes nothing returns nothing
    set gg_trg_Critical_Strike_Chance = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Critical_Strike_Chance, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_Critical_Strike_Chance, function Trig_Critical_Strike_Chance_Actions )
endfunction

(Converted to custom text with Edit...Convert to Custom Text)

Everything works fine, damage, chance etc. But it is easily exploited because if you just spam your hero to attack one person during combat (constantly press S and right click your enemy) it will just constantly fire this trigger. If anyone knows away around this, such as a condition to check if your hero is attacking or not, please post.
 
Level 11
Joined
Feb 22, 2006
Messages
752
What you need is a damage detection system. Basically you need to use the EVENT_UNIT_DAMAGED event rather than EVENT_PLAYER_UNIT_ATTACKED so the trigger only runs when a unit is damaged rather than when a unit initiates an attack. Just search around for damage detection systems and you should find lots of them. Warning: they all require scripting in JASS.
 
Level 3
Joined
Jul 7, 2007
Messages
22
What you need is a damage detection system. Basically you need to use the EVENT_UNIT_DAMAGED event rather than EVENT_PLAYER_UNIT_ATTACKED so the trigger only runs when a unit is damaged rather than when a unit initiates an attack. Just search around for damage detection systems and you should find lots of them. Warning: they all require scripting in JASS.



I could do that, but then spell damage and other sources could cause a critical strike.
 
Level 11
Joined
Nov 15, 2007
Messages
800
Simple workaround is making sure any hero with a damage detection ability has all of his other damage sources triggered. For example, just replace storm bolt or whatever with a 0 damage skill that simultaneously creates a dummy to cast the spell.
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Simple workaround is making sure any hero with a damage detection ability has all of his other damage sources triggered. For example, just replace storm bolt or whatever with a 0 damage skill that simultaneously creates a dummy to cast the spell.

This is simillar to what I have done in my map with DDS, I just use Turn off+trigger damage+turn on. Either way it's lot of extra work, but then you can claim that you have every single ability triggered :grin:
 
Level 3
Joined
Jul 7, 2007
Messages
22
I decided to just give my critical strikes a 1.00 second cooldown by making a dummy spell with a debuff that lasts 1 second, then changing the conditions on critical strike to Unit has buff of type CritCooldown equal to false
 
Status
Not open for further replies.
Top