| 02-03-2003, 08:05 PM | #1 |
Hi Folks I guess you all noticed that the "gets damage" event is only available for a single already placed unit. This suxx badly... I've done a workaround which is exactly like A unit owned by player X gets damage get demomap here: http://www.wc3sear.ch/damagetaken.zip The trigger works like this: Everytime a new unit or building is produced it installs a "unit - unit xxx gets damage" trigger at runtime. So if you produce 1000 units you have 1000 new triggers which handles what you wrote into the "Trig_damaged" funtion. I've tested it on my comp... after 1500 installed triggers still not slower or something. Build some units and buildings and hit em... you then see the unit type of the unit getting the damage and the abount of damage Greetings Darky26 Code:
//=============================================
// Trigger: unit - a unit owned by player x takes damage
// Script Author: Darky26
// Info: Workaround for the missing event...
//=============================================
[b]function Trig_damaged takes nothing returns nothin
// Here's The trigger you need. GetTriggerUnit is the unit and GetEventDamage the damage dealt
call DisplayTextToForce( GetPlayersAll(), R2S(GetEventDamage()) )
call DisplayTextToForce( GetPlayersAll(), UnitId2StringBJ(GetUnitTypeId(GetTriggerUnit())) )
endfunction[/b]
function Trig_Damage_Actions takes nothing returns nothing
local unit createdunit
set udg_TriggersPars = ( udg_TriggersPars + 1 )
if ( IsUnitType(GetConstructedStructure(), UNIT_TYPE_STRUCTURE) == true ) then
set createdunit = GetConstructedStructure()
else
set createdunit = GetTrainedUnit()
endif
set udg_Triggers[udg_TriggersPars] = CreateTrigger( )
call TriggerRegisterUnitEvent( udg_Triggers[udg_TriggersPars], createdunit, EVENT_UNIT_DAMAGED )
call TriggerAddAction( udg_Triggers[udg_TriggersPars], function Trig_damaged )
endfunction
//=============================================
function InitTrig_Damage takes nothing returns nothing
local trigger temp
set gg_trg_Damage = CreateTrigger( )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Damage, Player(0), EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Damage, Player(0), EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddAction( gg_trg_Damage, function Trig_Damage_Actions )
[b]// Here create the trigger for all existing units[/b]
set temp = CreateTrigger( )
call TriggerRegisterUnitEvent( temp, gg_unit_hpea_0001, EVENT_UNIT_DAMAGED )
call TriggerAddAction( temp, function Trig_damaged )
endfunction |
| 02-03-2003, 08:14 PM | #2 |
Good job darky :D |
| 02-09-2003, 11:30 AM | #3 |
Guest | Man, I can think of a ton of uses for this. this is great! Only problem, I tried to modify it for a few conditions, and being new to the custom text thing, I don't know why the conditional isn't working. I changed it so it only checks player 2, and that works fine, but when I add to see if attacking unit is a specific unit (Jaina or Hjai_0005), it won't fire. Here's the update. My mods are in orange. Please help! // ========================== // Trigger: unit - a unit owned by player x takes damage // Script Author: Darky26 // Info: Workaround for the missing event... // ========================== function Trig_damaged_Conditions takes nothing returns boolean if ( not ( GetUnitTypeId(GetAttacker()) == GetUnitTypeId(gg_unit_Hjai_0005) ) ) then return false endif return true endfunction function Trig_damaged takes nothing returns nothing call DisplayTextToForce( GetPlayersAll(), R2S(GetEventDamage()) ) call DisplayTextToForce( GetPlayersAll(), UnitId2StringBJ(GetUnitTypeId(GetTriggerUnit())) ) endfunction function Trig_Damage_Init takes nothing returns nothing call TriggerRegisterUnitEvent( udg_Trigger, GetEnumUnit() , EVENT_UNIT_DAMAGED ) endfunction function Trig_Damage_Actions takes nothing returns nothing local unit createdunit if ( IsUnitType(GetConstructedStructure(), UNIT_TYPE_STRUCTURE) == true ) then set createdunit = GetConstructedStructure() elseif ( IsUnitType(GetSummonedUnit(), UNIT_TYPE_SUMMONED) == true ) then set createdunit = GetSummonedUnit() else set createdunit = GetTrainedUnit() endif call TriggerRegisterUnitEvent( udg_Trigger, createdunit , EVENT_UNIT_DAMAGED ) endfunction // ========================= function InitTrig_Damage takes nothing returns nothing set gg_trg_Damage = CreateTrigger( ) call TriggerRegisterPlayerUnitEventSimple( gg_trg_Damage, Player(1), EVENT_PLAYER_UNIT_TRAIN_FINISH ) call TriggerRegisterPlayerUnitEventSimple( gg_trg_Damage, Player(1), EVENT_PLAYER_UNIT_CONSTRUCT_FINISH ) call TriggerRegisterPlayerUnitEventSimple( gg_trg_Damage, Player(1), EVENT_PLAYER_UNIT_SUMMON ) call TriggerAddAction( gg_trg_Damage, function Trig_Damage_Actions ) set udg_Trigger = CreateTrigger( ) call ForGroup( GetUnitsOfPlayerAll(Player(1)), function Trig_Damage_Init ) call TriggerAddCondition( udg_Trigger, Condition( function Trig_damaged_Conditions ) ) call TriggerAddAction( udg_Trigger, function Trig_damaged ) endfunction Please, also, if you have more of these post em. This and your generic spell one are really great, and will help a whole lot in battling issues with the editor. Great work! |
| 02-10-2003, 10:13 AM | #4 |
@Dazed+Konfuzed You made almost everything correct. There's just 1 problem you have: "GetAttacker()" wont work because in the "unit gets damage" event the attacker is not passed. So you only know the amount of damage taken but not who delivered the damage. You need to setup a trigger which checks for the attacker. and yes there are tons of possibilities with this now :-) Mana Leech for example ;-) |
| 02-10-2003, 02:27 PM | #5 |
Guest | Thx, Darky26. Being new to this custom text, it's a bit strange. Great thing also, is that by knowing when a unit takes damage, ranged attacks can be enhanced with all sorts of possibilites, and there won't be an issue with timing of special effects that have to be synchronized with a unit getting hit :) |
