View Single Post
Old 07-21-2008, 07:10 PM   #3
Evil Emoticon
moyack's Avatar

Respected User
Project Leader: PoC
Join Date: Jan 2006
Posts: 3,279

Submissions (17)

moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)moyack is a splendid one to behold (666)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack

Damage Detection only code:

Collapse DD without unit recycling:
//* Damage Detection script
//* By moyack. 2009
//* ============================================================================
//* Credits to Litany, DioD, Captain Griffen, Troll Brain and other nice guys  *
//* for their suggestions, comments and ideas.                                 *
//* ============================================================================
//* For Damage detection, you just need to use these functions:
//*  => AddDamageCondition(<Boolexpr variable>) returns nothing
//*     -------------------------------------------------------
//*     Just add a condition function which manage the damaged unit and the script
//*     will use it with all the the units in the DD.D group.
//*  => CreateDummy( player, 'Unitid', x, y, facing_Angle ) returns unit
//*     ----------------------------------------------------------------
//*     Like the CreateUnit function, but all the units created with this function
//*     won't trigger the this Damage Detection script. 
//*  => DoNonDetectableDamage(unit, widget, damage, boolean_attack, boolean_ranged, attacktype, damagetype, weapontype) returns boolean
//*     -------------------------------------------------------------------------------------------------------------------------------
//*     Like the UnitDamageTarget function, but it can be used inside condition functions.
//*     How to know if you need to use it? if you use UnitDamageTarget() inside a DD function and 
//*     it freezes the game until it kills the attacked unit(s), then you have to replace that
//*     function by this custom one.
library UnitDamage

struct DD // damage detection struct
    static group D // group of units that will have damage detection
    static group Dummies // group of units which will not be detected by the system
    static trigger T
    // Add the attacked unit to the damage detection if the unit is not in the pack
    static method AddUnit takes unit d returns nothing
        if not IsUnitInGroup(d, thistype.D) and not IsUnitInGroup(d, thistype.Dummies) then
            debug call DisplayTimedTextFromPlayer(GetLocalPlayer(), 0,0,2,"Added " + GetUnitName(d) + " to the DD")
            call TriggerRegisterUnitEvent(thistype.T, d, EVENT_UNIT_DAMAGED)
            call GroupAddUnit(thistype.D, d)
        set d = null
    private static method Attacked takes nothing returns nothing
        call thistype.AddUnit(GetTriggerUnit())
    private static method Spelled takes nothing returns nothing
        if GetSpellTargetUnit() != null then
            call thistype.AddUnit(GetSpellTargetUnit())
    private static method onInit takes nothing returns nothing
        set thistype.T = CreateTrigger()
        set thistype.D = CreateGroup()
        set thistype.Dummies = CreateGroup()
        call TriggerRegisterAnyUnitEventBJ(thistype.T, EVENT_PLAYER_UNIT_ATTACKED)
        call TriggerAddAction(thistype.T, function thistype.Attacked)
        set thistype.T = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(thistype.T, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(thistype.T, function thistype.Spelled)
        set thistype.T = CreateTrigger()

// Damage detection system functions...
function AddDamageCondition takes code func returns nothing
    call TriggerAddCondition(DD.T, Condition(func))

function CreateDummy takes player p, integer id, real x, real y, real f returns unit 
    local unit u = CreateUnit(p, id, x, y, f)
    call GroupAddUnit(DD.Dummies, u)
    return u

function DoSafeDamage takes unit u, widget t, real damage, boolean attack, boolean ranged, attacktype AT, damagetype DT, weapontype WT returns boolean
    local boolean b
    call DisableTrigger(DD.T)
    set b = UnitDamageTarget(u, t, damage, attack, ranged, AT, DT, WT)
    call EnableTrigger(DD.T)
    return b

function AddUnittoDD takes unit u returns nothing
    call DD.AddUnit(u)


DD examples with this script

Expand Triggered Critical Strike:

Expand Triggered Evasion:
moyack is offline   Reply With Quote