• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

EVENT_UNIT_DAMAGING not working ?

Status
Not open for further replies.
Level 12
Joined
Jan 30, 2020
Messages
875
Hello again everyone,

In my current TD project, I have made "Wealth Towers".
They give their owner 1 gold everytime they damage the creeps - Balls in this case.

These Balls do resize when they take damage (the size scales with the HP remaining).

So every Ball has its own trigger from a trigger array, with the event EVENT_UNIT_DAMAGED.

I was taking advantage of this trigger, and when a Ball was taking damage, if the damage source was a Wealth Tower, I was crediting its owner 1 gold.

This worked perfectly.

As EVENT_UNIT_DAMAGED is quite intensive , especially in a mazing TD, I made a hosting player chat command "resize on/off" to enable/disable these triggers on demand . Of course the problem is this also disables the income from Wealth Towers .

As players usually don't build many Wealth Towers, I though it would be nice to give Wealth Towers their own trigger, rewarding their owner with 1 gold when they are damaging a Ball. This trigger would fire much less often because of the limited number of Wealth Towers.

So I made a global trigger array, and everytime a Wealth Tower is built, i increase the number of wealth towers called WealthNb and i create the trigger WealthIncome[WealthNb], and register the EVENT_UNIT_DAMAGING to the Wealth Tower. The number (index) of the Wealth Tower is stored in its User Data.

When the Wealth Tower is sold, I destroy the trigger WealthIncome[number of the Wealth Tower] and decrease WealthNb.

But it does not work.

With Debug Messages, I can check that the WealthNb is properly increased on building or decreased on sell, but the trigger with EVENT_UNIT_DAMAGING never fires.

Here is the part where i create the trigger for the Wealth Tower (theUnit is the built tower)

JASS:
        if (theUnitID==WealthID) then // We increase the total number of Wealth Towers and initialize the Wealth Tower income trigger
            set WealthNb=WealthNb+1
            call SetUnitUserData(theUnit, WealthNb) // Wealth Tower has its index stored in its User Data
            set WealthIncome[WealthNb]=CreateTrigger()
            call TriggerRegisterUnitEvent(WealthIncome[WealthNb], theUnit, EVENT_UNIT_DAMAGING)
            call TriggerAddCondition(WealthIncome[WealthNb], function WealthIncomeActions)
            call BJDebugMsg("WealthNb="+I2S(WealthNb)) // properly displays the expected value
        endif

here is the Actions added to the conditions (as usual, returning false) :

JASS:
function WealthIncomeActions takes nothing returns boolean
    local unit theWealth=GetTriggerUnit()
    local player owner=GetOwningPlayer(theWealth)
    local integer oldGold=GetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD)

    call BJDebugMsg("Unit="+GetUnitName(theWealth)) // does not display anything
    call SetPlayerState(owner, PLAYER_STATE_RESOURCE_GOLD, oldGold+WealthGain)
    set theWealth=null
    set owner=null
    return false
endfunction

WealthGain is a global integer and its value is 1 (I made this in case I wanted to change the amount of gold gained).

Is there any reason the trigger never fires when Wealth Towers do damage to the Balls ?

Is EVENT_UNIT_DAMAGING faulty ? Am I condemned to use EVENT_UNIT_DAMAGED as I was doing before ?

So far, this problem makes no sense to me...

Thanks for any help,
Take care.
 
Level 12
Joined
Jan 30, 2020
Messages
875
OK, thanks for this information, the name is indeed misleading.

Is there any alternative to detect when the attacker deals damage rather than UNIT_EVENT_DAMAGED on the target ?

If not It seems I will have to revert back and notify the players that the Wealth Towers will be disabled with the Resize Ball trigger...
 
Status
Not open for further replies.
Top