HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple Damage Display System For Heroes

08-02-2008, 10:15 PM#1
TKF
A simple trigger how to make a damage display system which shows how much hit points you lose. Made for hero/rpg maps there you only control 1 unit/hero.


Pros:

- Does not leak (as far as I know)
- Shows the hp lost on heroes
- Cowork indirectly with armor, reductions and regeneration ( in that 1 sec)
- Shows damage done by damage over time abilities (such as poison)
- Easy to use

Cons:

- Only based to be displayed on single units
- Can be misinforming if the target has very high regeneration
- Doesn't show up as damage if targets regen was higher than the damage dealt
- It's a periodically trigger
- The text is visible beneath fog of war
- GUI

__________________________________

Variables:
PlayerHero (Unit) 16 arrays
Triggers:
2
__________________________________


This system display how much damage the enemy hero loses in hp every second. It uses unit custom value to determine damage. When it's doesn't take damage, no numbers will occur.

Damage is shown as floating text in red numbers.
Trigger:
Damage Display System
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
For each (Integer A) from 1 to 12, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(PlayerHero[(Integer A)] is alive) Equal to True
PlayerHero[(Integer A)] Not equal to No unit
(Custom value of PlayerHero[(Integer A)]) Greater than (Integer((Life of PlayerHero[(Integer A)])))
Then - Actions
Set Damage = ((Custom value of PlayerHero[(Integer A)]) - (Integer((Life of PlayerHero[(Integer A)]))))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Damage Greater than 2000
Then - Actions
Floating Text - Create floating text that reads (- + (String(Damage))) above PlayerHero[(Integer A)] with Z offset 0.00, using font size 14.00, color (100.00%, 8.00%, 8.00%), and 0.00% transparency
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Damage Greater than 600
Then - Actions
Floating Text - Create floating text that reads (- + (String(Damage))) above PlayerHero[(Integer A)] with Z offset 0.00, using font size 12.00, color (100.00%, 8.00%, 8.00%), and 0.00% transparency
Else - Actions
Floating Text - Create floating text that reads (- + (String(Damage))) above PlayerHero[(Integer A)] with Z offset 0.00, using font size 9.00, color (100.00%, 8.00%, 8.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 48.00 towards 270.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the fading age of (Last created floating text) to 1.30 seconds
Floating Text - Change the lifespan of (Last created floating text) to 1.60 seconds
Unit - Set the custom value of PlayerHero[(Integer A)] to (Integer((Life of PlayerHero[(Integer A)])))
Set Damage = 0
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(PlayerHero[(Integer A)] is alive) Equal to True
PlayerHero[(Integer A)] Not equal to No unit
(Custom value of PlayerHero[(Integer A)]) Less than (Integer((Life of PlayerHero[(Integer A)])))
Then - Actions
Unit - Set the custom value of PlayerHero[(Integer A)] to (Integer((Life of PlayerHero[(Integer A)])))
Else - Actions

GUI code

Collapse JASS:
function Trig_Damage_System_Func001Func001Func003C takes nothing returns boolean
    if ( not ( IsUnitAliveBJ(udg_PlayerHero[GetForLoopIndexA()]) == true ) ) then
        return false
    endif
    if ( not ( udg_PlayerHero[GetForLoopIndexA()] != null ) ) then
        return false
    endif
    if ( not ( GetUnitUserData(udg_PlayerHero[GetForLoopIndexA()]) < R2I(GetUnitStateSwap(UNIT_STATE_LIFE, udg_PlayerHero[GetForLoopIndexA()])) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Damage_System_Func001Func001Func005Func001C takes nothing returns boolean
    if ( not ( udg_Damage > 600 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Damage_System_Func001Func001Func005C takes nothing returns boolean
    if ( not ( udg_Damage > 2000 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Damage_System_Func001Func001C takes nothing returns boolean
    if ( not ( IsUnitAliveBJ(udg_PlayerHero[GetForLoopIndexA()]) == true ) ) then
        return false
    endif
    if ( not ( udg_PlayerHero[GetForLoopIndexA()] != null ) ) then
        return false
    endif
    if ( not ( GetUnitUserData(udg_PlayerHero[GetForLoopIndexA()]) > R2I(GetUnitStateSwap(UNIT_STATE_LIFE, udg_PlayerHero[GetForLoopIndexA()])) ) ) then
        return false
    endif
    return true
endfunction

function Trig_Damage_System_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Damage_System_Func001Func001C() ) then
            set udg_Damage = ( GetUnitUserData(udg_PlayerHero[GetForLoopIndexA()]) - R2I(GetUnitStateSwap(UNIT_STATE_LIFE, udg_PlayerHero[GetForLoopIndexA()])) )
            if ( Trig_Damage_System_Func001Func001Func005C() ) then
                call CreateTextTagUnitBJ( ( "-" + I2S(udg_Damage) ), udg_PlayerHero[GetForLoopIndexA()], 0, 14.00, 100.00, 8.00, 8.00, 0 )
            else
                if ( Trig_Damage_System_Func001Func001Func005Func001C() ) then
                    call CreateTextTagUnitBJ( ( "-" + I2S(udg_Damage) ), udg_PlayerHero[GetForLoopIndexA()], 0, 12.00, 100.00, 8.00, 8.00, 0 )
                else
                    call CreateTextTagUnitBJ( ( "-" + I2S(udg_Damage) ), udg_PlayerHero[GetForLoopIndexA()], 0, 9.00, 100.00, 8.00, 8.00, 0 )
                endif
            endif
            call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 48.00, 270.00 )
            call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
            call SetTextTagFadepointBJ( GetLastCreatedTextTag(), 1.30 )
            call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 1.60 )
            call SetUnitUserData( udg_PlayerHero[GetForLoopIndexA()], R2I(GetUnitStateSwap(UNIT_STATE_LIFE, udg_PlayerHero[GetForLoopIndexA()])) )
            set udg_Damage = 0
        else
            if ( Trig_Damage_System_Func001Func001Func003C() ) then
                call SetUnitUserData( udg_PlayerHero[GetForLoopIndexA()], R2I(GetUnitStateSwap(UNIT_STATE_LIFE, udg_PlayerHero[GetForLoopIndexA()])) )
            else
            endif
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Damage_System takes nothing returns nothing
    set gg_trg_Damage_System = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Damage_System, 1.00 )
    call TriggerAddAction( gg_trg_Damage_System, function Trig_Damage_System_Actions )
endfunction


(My computer seems to hate spaces, so it becomes erased upon paste, a mod with no such autocorrection addin in his webbrowser should fix my trigger tag problem)



Description:
This system checks damage loss every second and displays the hit points lost in red numbers in floating text. This system do only work on alive heroes and is only made to be based on single hero maps (like dota, battleships, AoS, RPGs and so on...)

The code uses unit custom value which checks the units hit points. For every second, if the hit points is lower than the unit custom value, the difference will be displayed in a floating text which also shows the hp lost.

Also if the hit points is higher than the custom value, the custom value will be set = current hp.

Unfortunately the system isn't designed to be show damage on creeps, only single heroes.


Also the code doesn't provide killing blow damage, so it must be put in a seperate death trigger (see below)





Implemention:
Make sure you make a unit variable called "PlayerHero" (16 arrays) if you don't have one. (16 arrays, cuz of neutral hostile...)


Also be sure to include these triggers in a unit death trigger if you wanna show killing blow damage.

Trigger:
Event - Generic unit Dies

Condition - Triggering unit is a hero Equal to True

Floating Text - Create floating text that reads (- + (String((Custom value of (Triggering unit))))) above PlayerHero[(Player number of (Owner of (Triggering unit)))] with Z offset 0.00, using font size 13.00, color (100.00%, 8.00%, 8.00%), and 0.00% transparency
Floating Text - Set the velocity of (Last created floating text) to 30.00 towards 270.00 degrees
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the fading age of (Last created floating text) to 1.30 seconds
Floating Text - Change the lifespan of (Last created floating text) to 2.20 seconds
Unit - Set the custom value of (Triggering unit) to 0

Be aware that the degrees is set to 270, it will go downwards instead of up. If you want the damage to go up, set it to 90 degrees in both death trigger and in the code.

(This is my first attempt for submitting a system. I kinda got problems with the trigger tags, I dunno what I did wrong...)
08-05-2008, 05:54 AM#2
Pyrogasm
You can't just put up some code and say "use it". You're going to need to explain the code.
08-05-2008, 07:28 AM#3
The Elite
dont put it in [code] tags, put it in [jass] tags
08-05-2008, 01:17 PM#4
TKF
Good enough now? I did put a brief description of what the code does.
08-05-2008, 10:26 PM#5
Pyrogasm
Remind me again why this code has to be JASS? Couldn't it just be GUI code?
08-05-2008, 11:14 PM#6
Rising_Dusk
This doesn't seem like a tutorial in the least. There are whole damage detection and rendering systems with more thorough explanations than this 'tutorial' has and are more all-around useful to look at for advice on the topic.
08-06-2008, 02:43 AM#7
darkwulfv
Plus the code is literally GUI -> JASS. I'm not seeing any attempt at optimization.
08-06-2008, 09:41 AM#8
TKF
I don't know how to make a tutorial, what is missing???
08-06-2008, 02:12 PM#9
darkwulfv
You made a system, not a tutorial.

Tutorials are step-by-step instructions on doing things, not "Here's a system I made, go use it". I would put this in resource submission since it's a system, not a tutorial.
08-06-2008, 02:30 PM#10
TKF
okey, can a mod move this to a different section doesn't fit in here? Also fix my trigger tags cuz it's doesn't work properly for me (or make it look better!).
08-06-2008, 04:26 PM#11
Rising_Dusk
I'm going to move this to the T&S forums for it to get some WIP help. The system as you have it is nowhere near ready for the database, nor is it a tutorial.
08-06-2008, 04:33 PM#12
chobibo
I think it's better to use this alongside a damage detection engine rather than using a periodic event, just my opinion though.
08-06-2008, 08:51 PM#13
TKF
Quote:
Originally Posted by chobibo
I think it's better to use this alongside a damage detection engine rather than using a periodic event, just my opinion though.
It sounds to hard...

Since I'm a editor noob, I don't know how... periodic is soooo much simpler...
08-06-2008, 10:16 PM#14
d07.RiV
Do you realise that its impossible to copy-paste your system? At the very least you should convert it to JASS using WE's mechanism and put it in [ hiddenjass ] tag (in addition to your normal triggers).

On what I could read, it has no hint of using damage event so its a waste. It wouldn't show the floating text immediately etc, and it can be done MUCH easier with "unit damaged" event: create a trigger with no events/conditions and make it create a texttag that shows "Event Response - Damage being dealt" or something like that, over "Triggering unit". Then for every hero use "Trigger - add '<hero> receives damage' event to <the previous trigger>". Simple as that.
08-06-2008, 10:34 PM#15
TKF
Quote:
Originally Posted by d07.RiV
Do you realise that its impossible to copy-paste your system? At the very least you should convert it to JASS using WE's mechanism and put it in [ hiddenjass ] tag (in addition to your normal triggers).
Done! It's raw so you have to do the optimization yourself.

Also make one trigger which responds to when a hero die or so, otherwise you don't get death blow damage as the system only works on alive heroes. That's why you need 2 triggers.

Currently a large red text appear when the damage is above 600, you can adjust that yourself...