HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Showing Damage Done

03-17-2007, 02:52 AM#1
Zyrixion
I've been trying to create a trigger to show the damage done by an attack or spell to a unit over a unit, but have been as of yet completely unsuccessful.

My code is:
Collapse JASS:
function Trig_Show_Damage_Done_Actions takes nothing returns nothing
    call CreateTextTagUnitBJ( R2S(GetEventDamage()), udg_P1Hero, 140, 10, 100, 100, 100, 0 )

endfunction

//===========================================================================
function InitTrig_Show_Damage_Done takes nothing returns nothing
    set gg_trg_Show_Damage_Done = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Show_Damage_Done, udg_P1Hero, EVENT_UNIT_DAMAGED )
    call TriggerAddAction( gg_trg_Show_Damage_Done, function Trig_Show_Damage_Done_Actions )
endfunction
03-17-2007, 03:00 AM#2
wantok
Is the udg_P1Hero variable initialized? Make sure it is pointing to the hero.
03-17-2007, 03:06 AM#3
Zyrixion
yes, udg_P1Hero has a value, and it is a unit var. It is automatically set when I select my hero on the map.
03-17-2007, 03:15 AM#4
Ammorth
You have to call the TriggerRegisterUnitEvent when the unit is stored to the variable.
03-17-2007, 03:22 AM#5
Zyrixion
clarify...how does one call a event func when the unit is stored, if the var is set when i buy my unit from tavern? Better yet, is there a better way of doing this?
03-17-2007, 03:28 AM#6
wantok
When you set the variable do this as well:

Collapse JASS:
//add this above the function where you set the variable
function Trig_Show_Damage_Done_Actions takes nothing returns nothing
    call CreateTextTagUnitBJ( R2S(GetEventDamage()), udg_P1Hero, 140, 10, 100, 100, 100, 0 )
endfunction

//add these lines to the function where you set the variable
local trigger t = CreateTrigger()
call TriggerRegisterUnitEvent( t, udg_P1Hero, EVENT_UNIT_DAMAGED )
call TriggerAddAction( t, function Trig_Show_Damage_Done_Actions )
set t = null
03-17-2007, 05:51 AM#7
Zyrixion
ok, my question: why is it even necessary to put this in the trigger where i define udg_P1Hero? It isn't a local variable, it should be able to be called without problem. Why is this necessary....I just want to be able to understand why.
03-17-2007, 07:24 AM#8
Earth-Fury
Collapse JASS:
function InitTrig_Show_Damage_Done takes nothing returns nothing

Delete this function and world editor will complain at you.
This is because these functions are called before most other functions in a maps script as a whole to register triggers. Which means this function is actually called before most other things in a map happen. Which means that your hero variable is not initialized, because nothing has happend yet! the maps still kinda loading when that function is called.

the method wantok posted creates a new trigger for the hero, adds the event to it with your variable that is now set, then makes it excecute the function with floating text on that event. (a trigger, in JASS terms, is esentally a way to call a function when an event happens.)

Also: Tried critical strike without a damage bonus?
03-17-2007, 08:01 AM#9
Chocobo
Quote:
Originally Posted by Zyrixion
ok, my question: why is it even necessary to put this in the trigger where i define udg_P1Hero? It isn't a local variable, it should be able to be called without problem. Why is this necessary....I just want to be able to understand why.

A event is pre-defined you can't modify it. If you give it one value, register the event, it works. If you give it one value, without registering, it doesn't work.


Critical Strike : 100% shows ever almost the message and not the exact damage.


Trigger:
Register PrePlaced Units
Collapse Events
Game - Time Elasped 0.00 seconds of game-time
Conditions
Collapse Actions
Custom Script : set bj_wantDestroyGroup = true
Collapse Unit Group - Pick every units in (Units in (Playable map area)) and do actions
Collapse Loop - Actions
Trigger - Add to Show Damages <gen> the event (Unit - (Picked unit) takes damage)

Trigger:
Detect Unit
Collapse Events
Unit - A unit enters (Playable map area)
Conditions
Collapse Actions
Trigger - Add to Show Damages <gen> the event (Unit - (Triggering unit) Takes damage)

Trigger:
Show Damages
Events
Conditions
Collapse Actions
Set loc = (Position of (Triggering unit))
Floating Text - Create floating text that reads ((String((Integer((Damage taken))))) + !) at loc 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 - Set the velocity of (Last created floating text) to 15.00 towards 90.00 degrees
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
03-17-2007, 05:50 PM#10
wantok
Your udg_P1Hero variable is just a pointer to the unit. When you add the event, you create the event not for the variable but for the unit it points to. If the variable has no value when you add the event, it points to null. This makes the trigger fire when null takes damage. Obviously this can't happen so the trigger won't work.
03-17-2007, 07:40 PM#11
botanic
the only way I have been able todo this is to set a variable to the original Hp of the attacked unit then wait a sec or so then display the difference however that I im shure not the most effective way... also it can screw up at times showing some strange values...
03-19-2007, 03:52 AM#12
Zyrixion
thanks a lot everyone for the info and explanations behind this, and thanks chocobo for the code, noted in map credits :)

CTF map entering the home stretch....for beta....maybe....lol
03-19-2007, 04:10 AM#13
Dil999
You have alot of work on your hands if you plan to beat out ET as the best CTF game
03-19-2007, 10:38 PM#14
Zyrixion
ET? Didn't even know there was even a quasi-popular CTF for wc3.....never see it played on bnet :o

But meh. it'll be pretty good, i should think (but then again, biased opinion :P ).


EDIT: Found it. Elimination Tournament, and on that note it'll come nowheres close. At least for now. For now it's fairly simple, it was partly meant to be a way for me to start on and improve JASS skills, but I've taken a particular liking to it now lol. Although I have not played ET yet, i will say that my map will be different. The beta will have 9 selectable heros (sorry, it's only a beta, will add lots more after some testing), full CTF system, lvl 100 max for heros, and a save/load. To counteract the potential imbalance of loading a lvl 100 aganst lvl 1 opponents, you do gain exp for getting a capture, as well as purchasable exp tomes, so it makes levelling easier. But other than those, only way to level is killing (which gets you gold). Because of permanent stat improvements, it is theorhetically possible to make an uberchar, but stats cap at 400, and you can get +1 to one stat for getting a capture, and no other way, so it'd take 'effin forever :)
At any rate, it should be fun, so look for it when i beta it on bnet. no working name yet, though, so i'll post on it. (there is even cooler stuff than this, but that's for the people who play beta to find out)