HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Attack Detect Fun!

09-18-2007, 03:30 AM#1
Pheonix-IV
Roite. I'm making use of the Caster System for a number of things, but at the moment i'm after an attack detector.

Specifically, i want to pick up if a unit with a certain buff has just attacked (and damaged) something else, if so, create a special fake copy of the unit, play it's attack animation and do the same amount of damage again (basically, faking a double-attack). I've been playing around with Vex's stacking orbs, but since the actual orb code seems to lack comments, i really have no clue what they're doing.

Halp would be appreciated.
09-18-2007, 05:20 AM#2
Jazradel
Pick every unit on map init
Register them with the unit is damaged event
Pick every unit that enters the map
Register them with the unit is damaged event
Have a big triggers that runs when the event and runs all your triggers.

It's all basically a variation of that. Can you link to whatever system your currently using cause I've totally lost track of all the stuff Vex has made.
09-18-2007, 07:16 AM#3
Pheonix-IV
I know it's all basically a variation on that, but i'm still having trouble understanding this. I see a bunch of local variables that all run around and occasionally breed, making more local variables.

It's like looking at a ball of string, i know i can understand this damn thing if i can just find an end.

Anyway, system is heah:
http://www.wc3campaigns.net/showthread.php?t=78753
09-23-2007, 01:36 AM#4
Pheonix-IV
Thanks for helping -_-
09-23-2007, 06:40 AM#5
Pyrogasm
If you were using his AttackDetect2 engine, I could help you. I have no idea how the attack detection in the CasterSystem works, considering that you don't even have to import an ability and buff for it to work.
09-23-2007, 12:20 PM#6
Pheonix-IV
Vex made another attack detect engine? Whar?
09-23-2007, 04:33 PM#7
Pyrogasm
Lawls. He appears to have removed it from the resources section. I would assume this is due to the bug he found regarding destroying triggers that have TriggerActions.

If you still want it, I can upload the last version of it that I have.
09-23-2007, 04:39 PM#8
Vexorian
I don't know what attack detection thing in the caster system you are talking about
09-23-2007, 04:53 PM#9
Pyrogasm
Well the AnitOrb template from your Spell Factory works, I would assume, due to attack detection. Now, this isn't technically part of the Caster System, but it doesn't require any extra abilities either. Thus I assumed there was some sort of internal CasterSystem attack detection stuff.
09-24-2007, 01:22 AM#10
Pheonix-IV
I found Attack Detect 2 in the graveyard, it looks much simpler and i think i can use it without any help.
09-24-2007, 12:17 PM#11
emjlr3
search for the thread cohadar started in regards to this, where we shared a few ideas, and systems that do just what you want
09-24-2007, 12:28 PM#12
cohadar
I actually found out that I don't need attack detect engine,
all I needed was General onDamage engine.

That is because I needed to detect attack only for certain heroes,
and for those heroes I added orb effects manually in Object editor
and it greatly reduced complexity of the whole system.

EDIT:
It also meant that I can use orb effects (black arrow my favorite)with other heroes :D
09-24-2007, 01:06 PM#13
waaaks
can i see the onDamage engine?
09-24-2007, 01:17 PM#14
cohadar
Yep

Hidden information:

Collapse JASS:
library DamageDetection initializer Init uses PUI
// thanks to emjlr3 for showing me his OnAttack sys


globals
    //===========================================================================
    // Add only Conditions to this trigger, Actions will NOT be executed
    // Condition functions take nothing and return boolean
    // you should return false after your code
    // Do NOT use waits in Conditions
    //
    // EXAMPLE:
    // call TriggerAddCondition( GlobalOnDamageTrigger, Condition(function YourFunction) )
    //===========================================================================    
    trigger GlobalOnDamageTrigger

    private boolean array ignore // prevents requrzion
    private trigger array OnDamagePerUnit
endglobals


//===========================================================================
// GetTriggerUnit() - Damaged Unit (unit)
// GetEventDamage() - amount of damage (real)
// GetEventDamageSource() - what did the damage (unit), can be null ?

// Per Unit OnDamage events call this function,
// This function then calls global OnDamageTrigger
//===========================================================================
function OnDamage takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer index = GetUnitIndex(u)
    local integer i = 1
    
    //call BJDebugMsg("|c0000FF00" + "OnDamage")
    
    if ignore[index] then
        call BJDebugMsg("|c0000FF00" + "endless requrzion prevented")
    else
        // mutex :D
        set ignore[index] = true
        call TriggerEvaluate(GlobalOnDamageTrigger)  // faster than execute
        set ignore[index] = false
    endif

    set u = null 
    return false
endfunction 


// makes sure one and only one OnDamage trigger is created per unit
private function LinkOnDamageTrigger takes unit u returns nothing
    local integer index = GetUnitIndex(u)
    local trigger trig = OnDamagePerUnit[index]
    
    // index was recycled so we destroy trigger because 
    // it belongs to previous unit on that index
    if (trig != null) then
        call DestroyTrigger(trig)
    endif

    set trig = CreateTrigger()
    
    //call BJDebugMsg("Registering OnDamage for " + GetUnitName(u))
    call TriggerRegisterUnitEvent(trig, u, EVENT_UNIT_DAMAGED)   
    call TriggerAddCondition(trig,Condition(function OnDamage))    
    
    set trig = null
endfunction

//Add damage trigger to units who enter map
private function AddTriggers takes nothing returns boolean
    local unit u = GetTriggerUnit()
    call LinkOnDamageTrigger(u)
    set u = null
    return false
endfunction

//Add damage trigger to preplaced units
private function FirstGroup takes nothing returns nothing
    local unit u = GetEnumUnit()   
    call LinkOnDamageTrigger(u)
    set u = null
endfunction

// Init
private function Init takes nothing returns nothing
    local trigger entmap_trig
    local group g
    
    // One trigger to OnDamage them all
    set GlobalOnDamageTrigger = CreateTrigger()
    
    // register OnDamage for preplaced units
    set g = CreateGroup()
    call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea, null)
    call ForGroup(g,function FirstGroup)
    call DestroyGroup(g)
    set g = null    
   
    // create trigger that registers OnDamage for units that enter the map
    set entmap_trig = CreateTrigger()
    call TriggerRegisterEnterRectSimple(entmap_trig, bj_mapInitialPlayableArea)
    call TriggerAddCondition(entmap_trig,Condition(function AddTriggers))
    set entmap_trig = null
endfunction

endlibrary
09-24-2007, 01:26 PM#15
waaaks
if i want to detect if my unit is damaged? what function will i use?