• 🏆 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!

Custom Critical Strike Script Problem

Status
Not open for further replies.
Level 5
Joined
Oct 24, 2007
Messages
90
Hello everyone, please take a look at this script:

JASS:
scope CriticalStrike initializer Init
    
    globals
//--------------------------------------------------SETUP--------------------------------------------------
        private constant integer SpellID = 'A006'    //Raw code of the spell
        private constant real CritChance = 15.    //Percent chance of dealing a critical hit.
        private constant real CritChanceInc = 5.    //Increase in percent chance per level.
        private constant real DmgMultiplier = 2.    //Number by which the damage dealt is multiplied when a critical strike is dealt.
        private constant real MultiplierInc = .5    //Multiplier increment per level.
//------------------------------------------------SETUP END------------------------------------------------
        private trigger CriticalTrig = CreateTrigger()
    endglobals
    
    private function AddUnits takes nothing returns boolean
        call TriggerRegisterUnitEvent(CriticalTrig, GetFilterUnit(), EVENT_UNIT_DAMAGED)
        return false
    endfunction
    
    private function Conditions takes nothing returns boolean
        return GetUnitAbilityLevel(GetEventDamageSource(), SpellID) > 0 and GetRandomReal(0., 100.) <= CritChance + CritChanceInc * (GetUnitAbilityLevel(GetEventDamageSource(), SpellID) - 1)and IsUnitEnemy(GetTriggerUnit(), GetOwningPlayer(GetEventDamageSource()))
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit DmgSource = GetEventDamageSource()
        local integer AbiLevel = GetUnitAbilityLevel(DmgSource, SpellID)
        local real ExtraDamage = GetEventDamage() * (DmgMultiplier + MultiplierInc * (AbiLevel - 1)) - GetEventDamage()
        local texttag Text = CreateTextTag()
        call DisableTrigger(GetTriggeringTrigger())
        call UnitDamageTarget(DmgSource, GetTriggerUnit(), ExtraDamage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
        call EnableTrigger(GetTriggeringTrigger())
        call SetTextTagText(Text, I2S(R2I(GetEventDamage() + ExtraDamage))+"!", 10 * .023/10.)
        call SetTextTagPosUnit(Text, GetEventDamageSource(), 64.)
        call SetTextTagColor(Text, 255, 0, 0, 255)
        call SetTextTagVelocity(Text, 120. * 0.071/128. * Cos(90. * bj_DEGTORAD), 120. * 0.071/128. * Sin(90. * bj_DEGTORAD))
        call SetTextTagPermanent(Text, false)
        call SetTextTagLifespan(Text, 2.)
        call SetTextTagFadepoint(Text, 1.7)
        set Text = null
        set DmgSource = null
    endfunction
    
    private function Init takes nothing returns nothing
        local group Targets = CreateGroup()
        local trigger AddNewUnits = CreateTrigger()
        call TriggerAddAction(CriticalTrig, function Actions)
        call TriggerAddCondition(CriticalTrig, Condition(function Conditions))
        call GroupEnumUnitsInRect(Targets, bj_mapInitialPlayableArea, Condition(function AddUnits))
        call DestroyGroup(Targets)
    endfunction
    
endscope

Basically, this is meant to replace a critical strike ability for a triggered one in order to control critical hits from units. However, this apples to all damage that is dealt from units that have the Critical Strike ability, such as spells like Blizzard and others that the hero might have, which is highly and unfairly beneficial for the hero. Is there any way to prevent spell damage from firing the trigger, or is there another way of going about the making of this custom critical strike spell such that it is only triggered by normal damage?

Thanks
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Unit is attacked -> store a boolean as true.
Unit begins casting an ability -> store boolean as false.

If the boolean is true when applying damage, then it's from a normal attack.

Damage over time from spells will srew this logic. But if your hero has no DoT spells, all is fine.
 
Level 5
Joined
Oct 24, 2007
Messages
90
Unit is attacked -> store a boolean as true.
Unit begins casting an ability -> store boolean as false.

If the boolean is true when applying damage, then it's from a normal attack.

Damage over time from spells will srew this logic. But if your hero has no DoT spells, all is fine.

Yeah, that's what I had before I asked this question. As you said, that would be triggered by DoT spell damage and AoE effects such as Blizzard, which is why I gave that example of spell... Maybe I could use a minimum damage threshold to control activation on DoTs and such? I don't know.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
You can use dummy units for your skills, if damage source is a hero - it is an attack damage.
 
Level 11
Joined
Oct 13, 2005
Messages
233
There are a few ways to try and detect attacks:

  1. Give every unit in the game an orb ability that places some sort of debuff on the attacked enemy. Whenever a unit is damaged, check for this debuff. If it's on the damaged enemy, they were attacked. You also need to remove the debuff from the damaged unit.
    Pros:
    • Relatively easy to implement, just make sure to give each unit the orb ability either in the object editor or add it when they enter the map
    • Little change has to be done to existing spells since the specific debuff is used to detect attacks
    Cons:
    • Can't have any standard orb abilities on any unit that must be affected by this system. As a result, you would need to trigger all orb effects that will be used by the units.
  2. Trigger all spell damage. This is in the form of requiring all spell damage to be inflicted by a dummy unit or to be specially handled with triggers.
    Pros:
    • No orb ability required
    • If all spell damage is triggered, allows for increased flexibility in spell code.
    Cons:
    • All spell damage must be specially handled, creating additional effort for each spell made.
    • Depending on the map, can require a reworking of many abilities already being used.

If you want to use method #2 and plan to trigger all spell damage (as in triggering all damage instead of just having a dummy unit cast spells), I recommend taking a look at Rising_Dusk's Intuitive Damage Detection System: link Using this system, however, you must use a system specific function for all triggered damage otherwise the damage dealt will be considered an attack.

As a side note, if you plan on having many abilities require damage detection, it is helpful to have a system set aside to handle the details for you. If you don't want to make your own system this is a very simple system that does no more than simply setup all the basic damage detection for you as opposed to a much larger and complex system like Rising_Dusk's.

Whatever your choice is, good luck.
 
Last edited:
Status
Not open for further replies.
Top