HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Problem with damage detection

09-01-2006, 03:19 AM#1
gshift
So I am not exactly the best with war3 editor, but I try. I have recently been trying to detect damage dealt and then display above unit head. The JASS code I have previously found for this I could not get working, so I attempted to do it myself. It works, but after about 20 seconds war3 starts chunking really bad due to a leak I assume. Here is the GUI trigger and the JASS, maybe someone can point me in the right direction on how to fix this problem.

Any help is welcome, thanks!


Trigger:
DisplayDamage
Collapse Events
Unit - A unit Is attacked
Conditions
Collapse Actions
Trigger - Add to (This trigger) the event (Unit - (Attacked unit) Takes damage)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Damage taken) Greater than 0.00
Collapse Then - Actions
Set TempPoint1[(Player number of (Owner of (Attacked unit)))] = (Position of (Attacked unit))
Floating Text - Create floating text that reads (String((Damage taken))) at TempPoint1[(Player number of (Owner of (Attacked unit)))] with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
Custom script: call RemoveLocation( udg_TempPoint1[GetConvertedPlayerId(GetOwningPlayer(GetAttackedUnitBJ()))] )
Collapse Else - Actions
Do nothing

Collapse JASS:
function Trig_Display_Damage_Func002C takes nothing returns boolean
    if ( not ( GetEventDamage() > 0.00 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Display_Damage_Actions takes nothing returns nothing
    call TriggerRegisterUnitEvent( GetTriggeringTrigger(), GetAttackedUnitBJ(), EVENT_UNIT_DAMAGED )
    if ( Trig_Display_Damage_Func002C() ) then
        set udg_TempPoint1[GetConvertedPlayerId(GetOwningPlayer(GetAttackedUnitBJ()))] = GetUnitLoc(GetAttackedUnitBJ())
        call CreateTextTagLocBJ( R2S(GetEventDamage()), udg_TempPoint1[GetConvertedPlayerId(GetOwningPlayer(GetAttackedUnitBJ()))], 0, 10, 100, 100, 100, 0 )
        call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
        call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 5.00 )
        call SetTextTagFadepointBJ( GetLastCreatedTextTag(), 2.00 )
        call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 64, 90 )
        call RemoveLocation( udg_TempPoint1[GetConvertedPlayerId(GetOwningPlayer(GetAttackedUnitBJ()))] )
    else
        call DoNothing(  )
    endif
endfunction

//===========================================================================
function InitTrig_Display_Damage takes nothing returns nothing
    set gg_trg_Display_Damage = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Display_Damage, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_Display_Damage, function Trig_Display_Damage_Actions )
endfunction
09-01-2006, 05:11 AM#2
DotA_DR
damage detection on attack complex problem, here are one way to solve it

Collapse JASS:
function Damage takes nothing returns nothing
  local trigger t = null
  local unit attacker = null
  if GetEventDamage() > 0 then
    set t = GetTriggeringTrigger()
    set attacker = I2U(GetStoredInteger(Cache, I2S(H2I(t)), "atkr"))
    if GetEventDamageSource() == attacker then
       // Do thing
       call DisableTrigger(t)
    endif
    set attacker = null
    set t = null
  endif
endfunction

function Trig_Test_Actions takes nothing returns nothing
  local trigger t = CreateTrigger()
  local string s = I2S(H2I(t))
  call StoreInteger(Cache, s, "atkr", GetAttacker())
  call TriggerRegisterUnitEvent(t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
  call TriggerAddAction(t, function Damage )
  call PolledWait(1) // time need fit to melee/range unit
  call FlushStoredMission(Cache, s)
  call DestroyTrigger(t)
  set t = null  
endfunction

function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Test, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction
09-01-2006, 05:42 AM#3
gshift
I found some damage functions that Shadow1500 made, and got those running. So now its working very smooth. Thanks for reply tho!
09-01-2006, 07:05 AM#4
gshift
Actually I now have the issue of trying to get the floating text to spawn overhead of the unit. While some units are quite larger than others, I am trying to calculate the Z offset from the units scaling value. Like 5 x (scalling value) = Z offset, or something like that. But I cant seem to find a way to determine what a units scaling value is inside of JASS. Maybe its not possible or there is a better way?
09-01-2006, 08:33 AM#6
gshift
yes but i have very large units with 2.5 scale etc. So basically i am just trying to dynamically set the Z offset of text based on what scale the unit is at.

Im going to supplement by just keeping track of a particular units Z offset in their Food Cost value, as I dont use this value for anything any its easy to access.