HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Ok, i need help detecting an attack.

05-28-2006, 04:57 AM#1
n13astra
Ive ended up learning JASS to try and do this but still no luck. How i know my code leaks but i dont care at the moment i just want it to work.

What im trying to do is this.
-Unit is attacked by a phoenix fire based ability.
-The ability adds a slowing_stars buff to the unit on attack.
-I want to detect for this buff, who cast the ability that caused the buff, and the unit the buff is on.

so here it is.


Trigger:
Detect an Attack
Collapse Events
Unit - A unit Is attacked
Conditions
Collapse Actions
Trigger - Add to Detect Damage <gen> the event (Unit - (Attacked unit) Takes damage)
Trigger - Turn on Detect Damage <gen>

Collapse JASS:
function Trig_Detect_Damage_Actions takes nothing returns nothing
    local integer i = 0
    call DisableTrigger( GetTriggeringTrigger() )
    loop
        exitwhen((UnitHasBuffBJ(GetAttackedUnitBJ(), 'X001') == true) or (i == 100))
        call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 0.10))
        set i = i + 1
    endloop
    if(i != 100) then
        call DisplayTextToForce( GetPlayersAll(), ( "I WAS DAMAGED" + I2S(GetConvertedPlayerId(GetTriggerPlayer())) ) )
        call UnitRemoveBuffBJ( 'X001', GetAttackedUnitBJ() )
        call CreateNUnitsAtLoc( 1, 'otbr', GetOwningPlayer(GetEventDamageSource()), OffsetLocation(GetUnitLoc(GetAttackedUnitBJ()), 60.00, 0), 0.00 )
        call IssueTargetOrderById( GetLastCreatedUnit(), String2OrderIdBJ("slow"), GetAttackedUnitBJ() )
    else
        call DisplayTextToForce( GetPlayersAll(), "WAITED TO LONG")
    endif
endfunction

//===========================================================================
function InitTrig_Detect_Damage takes nothing returns nothing
    set gg_trg_Detect_Damage = CreateTrigger(  )
    call DisableTrigger( gg_trg_Detect_Damage )
    call TriggerAddAction( gg_trg_Detect_Damage, function Trig_Detect_Damage_Actions )
endfunction
05-28-2006, 05:35 AM#2
Anopob
I think that you should make it work in GUI before you try to do it in JASS. There is a condition that checks if a unit has a specifics buff, so maybe you could do something like this:

Code:
Event: Every 0.01 seconds
Condition: None
Action: If (All Conditions are True) Then do (Then Actions) Else do (Else actions)
If-Conditions: Boolean Comparison -> (Specific Unit) has buff (Specific Buff) Equal to True
Then-Actions: The action you want
Else-Actions: Do nothing

Something like this should work.
05-28-2006, 08:15 AM#3
blu_da_noob
You are using the wrong event response. For the damaged unit you want GetTriggerUnit().
05-28-2006, 11:01 AM#4
n13astra
Ok, the first suggestion is no good, because checking EVERY unit every 0.01 is bound to cause lag! Also, that method does not tell me who attacked.

The second method did not work, but what i found is that if i cast the ability and the unit gets the buff, the next time the same unit is attacked, the trigger fires and works fine.

Still cant get it to work. This is the new code.

Trigger:
Detect an Attack
Collapse Events
Unit - A unit Is attacked
Conditions
Collapse Actions
Trigger - Add to Detect Damage <gen> the event (Unit - (Attacked unit) Takes damage)
Trigger - Turn on Detect Damage <gen>

Collapse JASS:
function Trig_Detect_Damage_Actions takes nothing returns nothing
    local integer i = 0
    call DisableTrigger( GetTriggeringTrigger() )
    // Create a loop which checks for the buff on triggering unit. Checks every
    // 0.1 seconds, but stops if it is not found in 10 seconds
    loop
        exitwhen((UnitHasBuffBJ(GetTriggerUnit(), 'X001') == true) or (i == 100))
        call TriggerSleepAction(0.10)
        set i = i + 1
    endloop
    // If the buff was found on the unit, then the unit attack was detected
    if(i != 100) then
        call DisplayTextToForce( GetPlayersAll(), ( "I WAS DAMAGED BY " + GetPlayerName(GetOwningPlayer(GetAttacker())) ) )
        call UnitRemoveBuffBJ( 'X001', GetTriggerUnit() )
        call CreateNUnitsAtLoc( 1, 'otbr', GetOwningPlayer(GetEventDamageSource()), OffsetLocation(GetUnitLoc(GetTriggerUnit()), 60.00, 0), 0.00 )
        call IssueTargetOrderById( GetLastCreatedUnit(), String2OrderIdBJ("slow"), GetTriggerUnit() )
    // Buff not found
    else
        call DisplayTextToForce( GetPlayersAll(), "WAITED TO LONG")
    endif
endfunction

//===========================================================================
function InitTrig_Detect_Damage takes nothing returns nothing
    set gg_trg_Detect_Damage = CreateTrigger(  )
    call DisableTrigger( gg_trg_Detect_Damage )
    call TriggerAddAction( gg_trg_Detect_Damage, function Trig_Detect_Damage_Actions )
endfunction
05-28-2006, 07:00 PM#5
StockBreak
Maybe I could be wrong, but what about creating a timer together with the first GUI trigger (for example 1/2 seconds); when it elapses, then turn off the second trigger detecting damage (because the unit was not damaged) and this trigger too; in this way you can avoid the loop.
05-29-2006, 12:34 AM#6
n13astra
bump
05-29-2006, 08:18 AM#7
Captain Griffen
GetAttacker() on line:

call DisplayTextToForce( GetPlayersAll(), ( "I WAS DAMAGED BY " + GetPlayerName(GetOwningPlayer(GetAttacker())) ) )
05-29-2006, 10:40 AM#8
Sharingan
I never liked loop scanning...
Is the target who gets the 'X001' buff "attacked" by a spell or by an "attack"?
From which I have seen, it would look like a spell to me, which would make you require the event, "Unit begins the effect of an ability".
05-29-2006, 12:26 PM#9
n13astra
Adding the GetAttacker() also did not work.

The attack is caused by a pheonix fire ability, which does not trigger to a "starts the effect of an ability". Its this ability that causes damage when it hits, and gives the attacked unit the buff.

But i cant detect this attack, and its very annoying.
05-29-2006, 12:58 PM#10
Captain Griffen
Quote:
Originally Posted by n13astra
Adding the GetAttacker() also did not work.

I was pointing out that you HAD GetAttacker() there, even though it should have been GetDamageSource().
05-29-2006, 03:20 PM#11
blu_da_noob
Does pheonix fire trigger the 'unit is attacked' event?
05-29-2006, 03:31 PM#12
The)TideHunter(
No, this has been posted before about phoenix fire, its undetectable unless you use a well-made detection system, that detects damage within 0.00 and 0.01.

To detect phoenix fire, i would just suggest using Vexs detection system..