• 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.

[Trigger] GUI Friendly Damage Detection Help

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

I would like to make a system that is like Critical Strike, but deals the damage to an area around the attacked unit. I have a thread here where I got the system right, except:

The event triggers for any damage done by GDD_DamageSource. For example, it will trigger when the unit casts a spell, but I only want it to run when the unit attacks.

How can I do this?

JASS:
function Thief_Skills_Actions takes nothing returns nothing
    call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodRifleman.mdl", GetEnumUnit(), "chest"))
    call DisableTrigger(gg_trg_Thief_Skills)
    if IsUnit(GetEnumUnit(), udg_GDD_DamagedUnit) then
        call UnitDamageTarget(udg_GDD_DamageSource, GetEnumUnit(), (((udg_Temp_Real / udg_GDD_Damage) - 1) * udg_GDD_Damage), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
    else
        call UnitDamageTarget(udg_GDD_DamageSource, GetEnumUnit(), udg_Temp_Real, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
    endif
    call EnableTrigger(gg_trg_Thief_Skills)
endfunction

function Thief_Skills_Conditions takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(udg_GDD_DamageSource)) == true
endfunction

function Thief_Skills takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer i = GetRandomInt(1, 5)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local texttag t = CreateTextTag()
    if (GetUnitTypeId(udg_GDD_DamageSource) == 'H004') and (GetUnitAbilityLevel(udg_GDD_DamageSource, 'A007') > 0) then
        if (i == 1) then
            set udg_Temp_Real = ((0.25 * (GetUnitAbilityLevel(udg_GDD_DamageSource, 'A007')) + 1) * udg_GDD_Damage)
            call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, 200, Condition(function Thief_Skills_Conditions))
            call ForGroup(bj_lastCreatedGroup, function Thief_Skills_Actions)
            call SetTextTagText(t, "|cffFF0000" + I2S(R2I(udg_Temp_Real)) + "!|r", 0.023)
            call SetTextTagPosUnit(t, udg_GDD_DamageSource, 50)
            call SetTextTagVelocity(t, 0, 64 * 0.071 / 128)
            call SetTextTagPermanent(t, false)
            call SetTextTagLifespan(t, 2)
            call SetTextTagFadepoint(t, 1)
            call SetTextTagVisibility(t, true)
        endif
    endif
    set t = null
    set u = null
    return false
endfunction

function InitTrig_Thief_Skills takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_GDD_Event", EQUAL, 0)
    call TriggerAddCondition(t, Condition(function Thief_Skills))
    set t = null
endfunction

Explanation
The Thief (hero) has a 20% chance per attack to deal 1.25/1.5/1.75/2.0/2.25x normal damage to all enemies within 200 range of the attacked unit.
Thanks!
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
When I cast an ability I set "Magic = True" into the unit data... And then = False. I require Magic = False to do the attack triggered effects :)
 
Level 6
Joined
Jun 20, 2011
Messages
249
He means the unit's index or custom value, here in the Hive you can find UnitIndexer for this purpose.
However, it's not accurate at all, if the ability causes damage to more than 1 unit the other units wont receive the "magic" damage bonus, therefore AdvDamage is required, my damage library would do the same as well (separates damage from attacks (melee/ranged), magic and done through coding)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Save "true" as 0 of (key(Casting Unit)) in MagicHash

Physical Attacks Trigger condition = load 0 of key(casting unit) = false.

This may work for most channeling abilities and instant magics with no effect over time. Works like charm for any ability dummy unit uses, since it's the only action the dummy will do, and it's independant of what your hero does.

You just add a "Clear al child data of Key(Casting Unit) from MagicHash" to prevent storing useless data.

I'm aware that there are more advanced systems... but this is "simple enough".
 
GDD is enough, filter the "GetUnitCurrentOrder" of the attacker by this event...
JASS:
call TriggerRegisterVariableEvent(t, "udg_GDD_Event", EQUAL, 0)

like this...
JASS:
if GetUnitCurrentOrder(udg_GDD_DamageSource)==851983 and GetUnitAbilityLevel(udg_GDD_DamageSource, 'ABILITY') > 0 then
     //actions
endif

851983 = attack order, so the damage event will not happen unless the
condition is met, idk if there are bugs for this coz I've used this method
before...

also, you should separate the condition & action for this coz every time the
event is executed, this will happen...
JASS:
local unit u = GetTriggerUnit()
    local integer i = GetRandomInt(1, 5)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local texttag t = CreateTextTag()
 
Level 11
Joined
May 31, 2008
Messages
698
cant you just do something like

unit is attacked
if attacking unit has critical strike
set dmg = true

and at the end of the system set dmg = false
and make the system only run when dmg = true

I think this should work, because the target takes damage a fraction of a second after it actually attacks, or longer if the attacker is ranged, of course.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Actually, it depends on the Combat - Animation damage point. The attack begins at 0, ussually Damage is dealt at 0.5 or 0.3.
 
Level 11
Joined
May 31, 2008
Messages
698
Well yeah, but the only thing that matters here is that you can detect that a unit is attacking another unit before the attacked unit actually takes damage.

And if you decide to use my method, one bug i just realized is if the unit attacks, but is ordered to stop before it is able to damage the target, then dmg would be set to true, but wouldnt be reset to false because no damage was given and your system wouldnt run. So you could just make another trigger that sets dmg = false when the unit casts a spell to prevent any kind of spell from causing the system to run.
 
Status
Not open for further replies.
Top