Damage event

substance

New Member
Reaction score
34
Im making a unit that when he attacks an ally he will damage them like normal but then instantly heal them for the same amount he damaged them x 2.

JASS:
function Trig_MedicAttack_Conditions takes nothing returns boolean
return GetUnitTypeId(GetAttacker()) == 'E00W'
endfunction

function Trig_MedicAttack_Actions takes nothing returns nothing
local unit attacker = GetAttacker()
local unit attackee = GetTriggerUnit()
local real damage = GetEventDamage()

   if IsUnitAlly(attackee,GetOwningPlayer(attacker)) then
      call SetUnitState(attackee, UNIT_STATE_LIFE, GetUnitState(attackee, UNIT_STATE_LIFE) + damage * 2)
   endif
endif 
endfunction

//===========================================================================
function InitTrig_MedicAttack takes nothing returns nothing
    set gg_trg_MedicAttack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MedicAttack, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_MedicAttack, Condition( function Trig_MedicAttack_Conditions ) )
    call TriggerAddAction( gg_trg_MedicAttack, function Trig_MedicAttack_Actions )
endfunction


My problem is 'GetEventDamage()' doesnt work with EVENT_PLAYER_UNIT_ATTACKED, not to mention 'on attack' isnt a good method anyway

So that leaves me with EVENT_UNIT_DAMAGED, but that only works for a specific unit. So what can i do?

**oh and what ability can i base a 'Heal over time' spell, I tied unholy frenzy with changing the 'damage' to a negative value but that doesnt work and 'rejuvenation' is funky.**
 
1st - The healing an ally thing. You need to register each unit with the event of Unit Takes Damage. Usually people do this when a unit enters the map (when it is spawned, it is added). Then once they are added, you can track things from there.

JASS:
function Enter takes nothing returns nothing
    local unit enterer = GetTriggerUnit()
    local trigger damage = CreateTrigger()
    local unitevent damage_event = EVENT_UNIT_DAMAGED
    call TriggerRegisterUnitEvent(damage,enterer,damage_event)
    call TriggerAddAction(damage,function damage_detect) 

endfunction

//============ Init Trig Functions ===========
function InitTrig_DetectDamage takes nothing returns nothing
    set gg_trg_DetectDamage = CreateTrigger()
    call TriggerRegisterEnterRectSimple(gg_trg_DetectDamage,GetPlayableMapRect())
    call TriggerAddAction(gg_trg_DetectDamage, function Enter)
endfunction


Then in the damage_detect, you can use GetTriggerUnit as the damaged unit. You will have some fun fixing the bugs with this though ;) It can be very tricky.


As for a heal over time, here is a template:

JASS:
globals
unit udg_HoTTarget
real udg_HoTSteps
endglobals

function HoT_Timer takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit target = GetHandleUnit(t, "target")//Global Version: local unit targetglobal = udg_HoTTarget
local real steps = GetHandleReal(t, "steps")//Global Version: local integer steps = udg_HoTSteps
local integer healvalue = GetRandomInt(50,100) //Or whatever you want your heal range to be

//Terminating Condition
if steps <=1 then
call FlushHandleLocals(t)//Not needed if using globals
call DestroyTimer(t)
set t= null
set target = null
return
endif

//Now we can do this many ways, we can set the unit state life to the value you want
//Or you can cast a dummy spell to heal the unit.  I'm going to do the unit state
call SetUnitState(target, UNIT_STATE_LIFE, GetUnitState(target, UNIT_STATE_LIFE)+healvalue)


call SetHandleReal(t, "steps", steps-1) //Globals Version: set udg_HoTSteps=steps-1
//Cleanup
set t = null
set target = null
endfunction

function HoT_Template takes nothing returns nothing
local unit target = GetSpellTargetUnit()
local timer t = CreateTimer()
local real time = 2 //This number means every 2 seconds, we will heal the target.
local integer duration = 60 //We want it to last 60 seconds

//IF YOU ARE USING HANDLES
call SetHandleHandle(t, "target", target)//Globals Version:set udg_HoTTarget = target
call SetHandleReal(t, "steps", (duration/time))//Globals Version: set udg_HoTSteps = (duration/time)

call TimerStart(t, time, true, function HoT_Timer)
set target=null
endfunction


That template is MUI only if you use handle vars. If you use the globals it will not be MUI. That template can be used on any spell you cast, it doesn't matter, you could even make it a Damage over time if you set the healvalue to a negative number.
 
yeh i thought about this, but if there's alot of units then thats alot of triggers =p. Just seems unefficient.

If there's no other option then I guess I'll do it this way.

*heh, thanks for the code.
 
I don't see what the problem with the code that Steel gave. It's the best thing you can do. If you want to add to the trigger pre-placed units as well trigger that as well, getting at elapsed time 1.00 all units in a group and then doing what Steel did. For example:

JASS:

function example takes nothing returns nothing.
    local group g = CreatedGroup()
    local unit s

    call GroupEnumUnitsInRect(g,GetWorldBounds(),null)

    loop
        set s = FirstOfGroup(g)
        exitwhen s == null
        call TriggerRegisterUnitEvent(gg_trg_MedicAttack,s,EVENT_UNIT_DAMAGED)
        call GroupRemoveUnit(g,s)
    endloop

    call DestroyGroup(g)
    set g = null
    set s = null
 
There's nothing wrong with that method I guess, it just seems extremely inefficient.

You essentially create a trigger for every unit on the map. That trigger runs a function everytime any unit in the game recieves damage. The likely hood of that event being what i need it for is too small. In fact An entire game on my map could be played without that unit attacking (so it'd be a huge waste).

I might just remove that unit's attack ability all together and replace it with a spell that essentially does the same thing.

I havent really looked into it , but there are a few 'OnAttack' systems on wc3c that might be just what I need.

And as far as the HoT goes, I made a similar function (Dot) a while ago and forgot I had it =p. I changed it so that it works with both now.

JASS:
function Trig_MedicAttack_Conditions takes nothing returns boolean
return GetUnitTypeId(GetAttacker()) == 'E00W'
endfunction

struct oTdata
unit targetunit
player caster
integer currenttime
integer maxtime
endstruct

function oT takes nothing returns nothing
local timer t = GetExpiredTimer()
local oTdata data = GetData(t)

set data.currenttime = data.currenttime + 1

if data.currenttime >= data.maxtime then
   call PauseTimer(t)
   call DestroyTimer(t)
   set t = null
   call oTdata.destroy(data)
   call UnitRemoveAbility(data.targetunit, 'B00E')
   call UnitRemoveAbility(data.targetunit, 'B00F')
endif

if IsUnitAlly(data.targetunit,data.caster) then
   if GetUnitAbilityLevel(data.targetunit, 'B00E') == 0 then
      call UnitAddAbility(data.targetunit,'B00E')
   endif
   call SetUnitState(data.targetunit, UNIT_STATE_LIFE, GetUnitState(data.targetunit, UNIT_STATE_LIFE) + 0.01 * GetUnitState(data.targetunit, UNIT_STATE_MAX_LIFE))
else
   if GetUnitAbilityLevel(data.targetunit, 'B00F') == 0 then
      call UnitAddAbility(data.targetunit,'B00F')
   endif
   call SetUnitState(data.targetunit, UNIT_STATE_LIFE, GetUnitState(data.targetunit, UNIT_STATE_LIFE) - 0.01 * GetUnitState(data.targetunit, UNIT_STATE_MAX_LIFE))
   endif
endfunction

function Trig_MedicAttack_Actions takes nothing returns nothing
local timer t = CreateTimer()
local oTdata data = oTdata.create()

set data.caster = GetOwningPlayer(GetAttacker())
set data.targetunit = GetTriggerUnit()
set data.maxtime = 12

if IsUnitType(data.targetunit,UNIT_TYPE_MECHANICAL) == false and GetUnitAbilityLevel(data.targetunit, 'B00C') == 0 then
   call SetData(t, integer(data))
   call TimerStart(t,1.00,true,function oT)
endif 
endfunction

//===========================================================================
function InitTrig_MedicAttack takes nothing returns nothing
    set gg_trg_MedicAttack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MedicAttack, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_MedicAttack, Condition( function Trig_MedicAttack_Conditions ) )
    call TriggerAddAction( gg_trg_MedicAttack, function Trig_MedicAttack_Actions )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top