Triggered Critical Strike

WolfieeifloW

WEHZ Helper
Reaction score
372
I need this for my critical strike trigger.
I need to get the life of the attacked unit before he gets hit by the 'normal' attack
Then get the attacked units life after he gets hit.
I need these two values so that I can multiply this number by the damage multiplier;
Therefore making a "critical strike" skill.

Thanks in advance TH.net!
 
Reaction score
341
The normal event that detects when a unit us attacked (not damaged) is usually triggered before the unit us actually, attacked.

And to get his life after an attack, you can use the event "unit is damaged", and using GetWidgetLife should give you his hp after an attack.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
How would I do that sorry :( ?
Could you help me fix it up in this code (and add comments so i can understand/learn :eek: ?)
JASS:
scope LastResort initializer Init

globals
    private constant integer ability_LRid = 'A000'
    private constant integer ability_LRBid = 'A001'
    private constant integer buff_LRBid = 'B000'
    private constant integer unit_DUMMYid = 'n000'
    private constant integer baseCrit = 5
    private constant integer pcPlus = 2
    private constant integer hpMiss = 350
    private constant integer pcCap = 10
    private constant integer hpMissPL = 50
    private constant string lrBuff = "innerfire"
endglobals

private function LRLConditions takes nothing returns boolean
    return GetLearnedSkill() == ability_LRid
endfunction

private function LRLActions takes nothing returns nothing
    local unit luLR = GetTriggerUnit()
    local real luX = GetUnitX(luLR)
    local real luY = GetUnitY(luLR)
    local unit dBU = CreateUnit(GetOwningPlayer(luLR), unit_DUMMYid, luX, luY, GetUnitFacing(luLR))
    call IssueTargetOrder(dBU, lrBuff, luLR)
    call UnitApplyTimedLife(dBU, 'BTLF', 1.00)
endfunction

private function LRConditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), ability_LRid) > 0
endfunction

private function LRActions takes nothing returns nothing
    local real array atkLife
    local integer array atdLife
    local unit atkUnit = GetAttacker()
    local integer critChance
    
    set atkLife[0] = GetUnitState(atkUnit, UNIT_STATE_MAX_LIFE) - GetUnitState(atkUnit, UNIT_STATE_LIFE)   // Get xax life / current life    
    set atkLife[1] = atkLife[0] / (hpMiss - (GetUnitAbilityLevel(atkUnit, ability_LRid) * hpMissPL))       // Get above / missing HP    
    set critChance = baseCrit + (pcPlus * R2I(atkLife[1]))                                                 // Set critChance    
    if critChance > baseCrit + (GetUnitAbilityLevel(atkUnit, ability_LRid) * pcCap) then                   // If critChance is too high
        set critChance = baseCrit + (GetUnitAbilityLevel(atkUnit, ability_LRid) * pcCap)                   // Sets it to max
    endif
endfunction

private function CLEARActions takes nothing returns nothing
    call ClearTextMessages()
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger LRtrig = CreateTrigger()
    local trigger LRLtrig = CreateTrigger()
    
    local trigger CLEARt = CreateTrigger()
    
    call TriggerRegisterPlayerChatEvent(CLEARt, Player(0), "-clear", true)
    call TriggerAddAction(CLEARt, function CLEARActions)
    
    call TriggerRegisterAnyUnitEventBJ(LRtrig, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(LRtrig, Condition(function LRConditions))
    call TriggerAddAction(LRtrig, function LRActions)
    
    call TriggerRegisterAnyUnitEventBJ(LRLtrig, EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(LRLtrig, Condition(function LRLConditions))
    call TriggerAddAction(LRLtrig, function LRLActions)
endfunction

endscope
 
Reaction score
341
um.

Event
Unit attacked
Actions
Set HP = Get Unit Life

Event
Unit Takes Damage
Actions
Set New_HP = GetUnitLife
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I don't understand though..
Does the first trigger run the second one?
If not how do I carry the unit over?

I'm still new to JASS;
Sorry if this is noob stuff :eek: .
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Can I do this:
Declare the unit in function1, add the event of the unit takes damage to function2, run function2 from function1, then do the damage?
If so, what's the command to run another function?
And how do I declare a unit globally to carry over to that function?
I've thus far only worked with local units.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Just out of curiousity, do you just need the before and after life so you can make the crit do what the texttag reads without factoring the damage twice? or are you using those for something else?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
What do you mean texttag or whatever?
I need it so that I can apply the damage by whatever damage multiplier the current level provides.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
The texttag shows up above the unit when you crit with the blizzard crit. You know the red thing that says 106! or something like that. I'm asking why you want to get the life before and after the damage, is it because you don't want the attack damage dealt twice? I'll explain.

A unit does 20-20 damage with a 50% chance to do 3x damage (60 damage). If it crits, a red 60! should pop up, but if you trigger it off the attack to do 3x damage, it will do 20 + 60. Hence you need to account for the damage from the triggering attack. If this is the only reason you need those two values, I have some simple solutions...
 

WolfieeifloW

WEHZ Helper
Reaction score
372
The whole spell is triggered.
The only thing the actual ability does it give the icon+tooltip.
Reason it has to be triggered is because...Well, here's the tooltip:
This Hero has a chance to deal more damage on an attack. The lower the Heroes health, the more chance it has to deal a critical strike.

Level 1 - 5% chance, +2% for every 300 health missing, 1.4 times normal damage, cap of 15% chance.
Level 2 - 10% chance, +2% for every 250 health missing, 1.8 times normal damage, cap of 20% chance.
Level 3 - 15% chance, +2% for every 200 health missing, 2.2 times normal damage, cap of 25% chance.
Level 4 - 20% chance, +2% for every 150 health missing, 2.6 times normal damage, cap of 30% chance.
I was going to just use the damage multiplier on the skill, but the skill's chance is triggered so it wouldn't have worked.
 

saw792

Is known to say things. That is all.
Reaction score
280
Basically a damage detection system is needed. You don't need to get the life before and after the damage to multiply it as the only way you could get that information is by using the unit takes damage event. Which is useless anyway because you can then use GetEventDamage().

If you don't want to use a damage detection system just make four separate critical strike abilities with the correct multipler and base chance, then add multiple levels for each increase in chance (i.e. for Level 1, make an ability that has 5% at level 1, 7% at level 2, 9% at level 3, 11% at level 4, 13% at level 5 and 15% at level 6). Then just increment the abilities level based on your conditions.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Do you have a link to a damage detection system?
Are they easy to use/setup?
I'd rather not have to have four different abilities with 6 levels on each :( .

EDIT: Is there an easy way to set up my own detection system?
 

saw792

Is known to say things. That is all.
Reaction score
280
Damage detection systems are always bulky and either leak events or use dynamic triggers. I think it would be much easier for you to use the four abilities. You only need to do one, then copy-paste it a few times and edit some values.

Check wc3c for damage detection systems, the ones on TH aren't much chop.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Try this. There may be some compile errors as it was freehand. You have to fill in the SPELL_ID. This is only the condition for the chance. Do whatever you want in the actions. Be sure to put this in a scope or library.

JASS:
globals
    private constant integer SPELL_ID = 
endglobals
    
    
private function Chance takes nothing returns integer
local unit u = GetAttacker()
local integer level = GetUnitAbilityLevel(u,SPELL_ID)
local integer lifeperchance = 350 - level * 50 //300 at level 1, 250 at 2...
local real missingLife = GetUnitState(u,UNIT_STATE_MAX_LIFE) - GetUnitState(u,UNIT_STATE_LIFE)
local integer extraChance = 0

    loop
        if missingLife < lifeperchance then
            exitwhen true
        endif
        set extraChance = extraChance + 2
        set missingLife = missingLife - lifeperchance
        exitwhen extraChance >= 10
    endloop
    
    set u = null
    
    return extraChance
endfunction
    
    

private function cond takes nothing returns boolean
    return GetRandomInt(1,100) <= (GetUnitAbilityLevel(GetAttacker(), SPELL_ID) * 5) + Chance()
endfunction
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I've already got the chance part ;) :
JASS:
globals
    private constant integer ability_LRid = 'A000'
    private constant integer ability_LRBid = 'A001'
    private constant integer buff_LRBid = 'B000'
    private constant integer unit_DUMMYid = 'n000'
    private constant integer baseCrit = 5
    private constant integer pcPlus = 2
    private constant integer hpMiss = 350
    private constant integer pcCap = 10
    private constant integer hpMissPL = 50
    private constant string lrBuff = "innerfire"
endglobals

private function LRConditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), ability_LRid) > 0
endfunction

private function LRActions takes nothing returns nothing
    local real array atkLife
    local integer array atdLife
    local unit atkUnit = GetAttacker()
    local integer critChance
    
    set atkLife[0] = GetUnitState(atkUnit, UNIT_STATE_MAX_LIFE) - GetUnitState(atkUnit, UNIT_STATE_LIFE)   // Get max life / current life    
    set atkLife[1] = atkLife[0] / (hpMiss - (GetUnitAbilityLevel(atkUnit, ability_LRid) * hpMissPL))       // Get above / missing HP
    set critChance = baseCrit + (pcPlus * R2I(atkLife[1]))                                                 // Set critChance
    if critChance > baseCrit + (GetUnitAbilityLevel(atkUnit, ability_LRid) * pcCap) then                   // If critChance is too high
        set critChance = baseCrit + (GetUnitAbilityLevel(atkUnit, ability_LRid) * pcCap)                   // Sets it to max
    endif
endfunction
 

--Thanatos--

New Member
Reaction score
33
I'm sure with Event UnitTakesDamage, we can get this result:

GetWidgetLife(x()) = HP before damaged
GetDamageTaken() = Damage going to be taken
GetWidgetLife(GetTriggerUnit()) - GetDamageTaken() = Remaining HP after taking damage

I think..? :D
 

saw792

Is known to say things. That is all.
Reaction score
280
It's GetEventDamage(), and I already mentioned it. Read the thread please.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top