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

[vJASS] DamageDetection

Status
Not open for further replies.
Hi guys, I wonder why the DamageDetection cannot register units manually without using Units that are preplaced nor entering the map?...
JASS:
library DamageDetect

struct DamageDetect
    trigger t
    
    static method damageReg takes nothing returns boolean
        call BJDebugMsg(GetUnitName(GetTriggerUnit()))    
        call BJDebugMsg(GetUnitName(GetEventDamageSource())) 
        call BJDebugMsg("DAMAGE=="+R2S(GetEventDamage())) 
        return false
    endmethod
    
    static method create takes unit u returns thistype
        local thistype this = allocate()
        set .t = CreateTrigger()
        call TriggerRegisterUnitEvent(.t, u, EVENT_UNIT_DAMAGED)  
        call TriggerAddCondition(.t, function thistype.damageReg)
        //it registers the trigger and the condition but NOT manually
        return this
    endmethod
endstruct

endlibrary

Manually means this:
JASS:
call DamageDetect.create(UNIT1)
call DamageDetect.create(UNIT2)

But this is OK:
JASS:
    static method FilterDamageUnitEvent takes nothing returns boolean
        call DamageDetect.create(GetFilterUnit())
        return false
    endmethod 
    
    static method onInit takes nothing returns nothing
        local trigger t
        local region r
        call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, function thistype.FilterDamageUnitEvent)
        set t= CreateTrigger()
        set r = CreateRegion()
        call RegionAddRect(r, GetWorldBounds())
        call TriggerRegisterEnterRegion(t, r, function thistype.FilterDamageUnitEvent)
        set t = null
        set r = null
    endmethod
 
This should actually throw an error:
JASS:
call TriggerRegisterEnterRegion(t, r, function thistype.FilterDamageUnitEvent)

It should be Filter(function thistype.FilterDamageUnitEvent) (or Condition(func..))

You may want to try inputing "null" for the filter part of the event registration and then add an action to the trigger instead. Ex:
JASS:
static method TriggerDamageUnitEvent takes nothing returns boolean
    call DamageDetect.create(GetTriggerUnit())
    return false
endmethod

static method FilterDamageUnitEvent takes nothing returns boolean
    call DamageDetect.create(GetFilterUnit())
    return false
endmethod 

static method onInit takes nothing returns nothing
    local trigger t
    local region r
    call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, function thistype.FilterDamageUnitEvent)
    set t= CreateTrigger()
    set r = CreateRegion()
    call RegionAddRect(r, GetWorldBounds())
    call TriggerRegisterEnterRegion(t, r, null)
    call TriggerAddCondition(t, Condition(function thistype.TriggerDamageUnitEvent))
    set t = null
    set r = null
endmethod

AFAIK filters for events might not work the way you expect it to. I think it might filter which units the event considers or something like that, tbh I don't remember. But try using the code above and maybe it will work.
 
This should actually throw an error:
sorry but no it doesnt coz it's a boolexpr and thus returns a boolean, maybe it does error in old patches, but not this time...

and I think I know the problem now, coz I didnt register the one who is taking the damage (TriggerUnit), so it returns a null,
but if the TriggerUnit is giving the damage to the one who's registered, it's fine coz he will be the damage source...
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Irrelevant to the main thread but there's a reason omitting Filter/Condition works.
Code values might get implicitly casted to boolexpr in some occasions, specifically, when using them as arguments for natives/bjfunc that take boolexpr. More cases will get added when type safety gets on its way for more stuff...
It's been in JassHelper since 0.A.0.0.
This means that being lazy doesn't work with your own functions that takes boolexpr parameters.
 
Status
Not open for further replies.
Top