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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top