| 03-17-2007, 02:52 AM | #1 |
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: 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 |
Is the udg_P1Hero variable initialized? Make sure it is pointing to the hero. |
| 03-17-2007, 03:06 AM | #3 |
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 |
You have to call the TriggerRegisterUnitEvent when the unit is stored to the variable. |
| 03-17-2007, 03:22 AM | #5 |
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 |
When you set the variable do this as well: 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 |
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 |
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, 05:50 PM | #10 |
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 |
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 |
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 |
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 |
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) |
