• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Need help with overhead damage displays

Status
Not open for further replies.
Level 11
Joined
Feb 22, 2006
Messages
752
I'm making an RPG and i want an option where when a player hero attacks, the damage amount will be shown with TextTags above the hero. However, I can't figure out how to make the game register the amount of damage that the hero actually did. The function GetEventDamage() only works with the "specific unit takes damage" event, which wouldn't be practical to use, and every other event i've tried always fires the trigger AFTER the damage is done, so there is no way to use arithmetic to figure out the damage. If somebody could help me with this i would really appreciate it.
 
Level 5
Joined
May 22, 2006
Messages
150
That will not work as "damage taken" is linked to "takes damage" which he does not want to use.

Let us see...

You want the text to show up over the hero instead over the damaged unit...

This is a short solution. It may be enhanced:

trigger "aquireTarget":
JASS:
function Trig_showText_Actions takes nothing returns nothing
  local texttag tempText = CreateTextTag()
  call SetTextTagText(tempText,R2S(GetEventDamage()),0.023)
  call SetTextTagColor(tempText,255,127,127,0)
  call SetTextTagPosUnit(tempText, - Here your Hero must be put in - ,10)
  call DestroyTextTag(tempText)
  set tempText = null
endfunction

function Trig_aquireTarget_Actions takes nothing returns nothing
  local unit tempUnit = GetEventTargetUnit()
  local trigger trg_showText = CreateTrigger()
  call TriggerRegisterUnitEvent(trg_showText,tempUnit,EVENT_UNIT_DAMAGED)
  call TriggerAddAction(trg_showText,function Trig_showText_Actions)
  loop
    exitwhen(GetUnitState(tempUnit,UNIT_STATE_LIFE) <= 0 or tempUnit != GetEventTargetUnit())
    call TriggerSleepAction(0.05)
  endloop
  call DestroyTrigger(trg_showText)
  set trg_showText = null
endfunction

function InitTrig_aquireTarget takes nothing returns nothing
  set gg_trg_aquireTarget = CreateTrigger()
  call TriggerRegisterUnitEvent(gg_trg_aquireTarget, - Here your Hero must be put in - ,EVENT_UNIT_ACQUIRED_TARGET)
  call TriggerAddAction(gg_trg_aquireTarget,function Trig_aquireTarget_Actions)
endfunction

If the trigger does not work as appropriated or causes trouble otherways, report to me and I will try to solve the problem.
 
Status
Not open for further replies.
Top