• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Damage events

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
I am runing the GDD_Event and I'm setting DmgBlock to the damaged unit, and Temp_Health is the unit's life.

Okay I assume you don't know this or haven't done it, but you can create triggers whenever you want. You don't have to create them in those InitTrig functions (though that is where they are created for all GUI triggers).

Remember that question you had about hashtables? Storing udg_DmgBlock, then setting udg_DmgBlock = someOtherUnit, then loading the origin udg_DmgBlock from the table will not give you someOtherUnit, but instead the unit you originally stored.

Triggers (and probably every function in common.j) work exactly like this. That is just how objects are dealt with in most programming languages. You are basically creating one single trigger where if this null unit's life becomes less than 0, you do some stuff, but that will never happen.

What you need to do is create the trigger at the time you set the unit and life to be less than. It has to happen in the GDD damage event trigger that you have that sets the life and unit. This is why you also need to destroy the trigger once it's run. If you leave those hanging around, you will break things.

Yes it is safe assuming those are the only variables.

You only have to cache the index.
With the index, you can then load in all the variables assigned to that damage instance via that index.

Cool! I think I get it, then. That is a lot of stuff for me to set up, though. I didn't think damage events needed to be indexed. I can skip the indexing, but it is definitely more clean to do it that way. I will keep it in mind, for sure.
 
Level 13
Joined
Jan 2, 2016
Messages
978
Hmm, I'm not sure I understand.. from what Wietlol explained earlier - there is a damage event, and a health event. The damage event is right before the health one, so if I run this trigger in the damage event - it wouldn't work as it's intended.
And well, my variables aren't nulls. I had another trigger: when I press escape - it was showing me the value of Temp_Health and the name of DmgBlock - they weren't nulls..

I'm looking at the Damage Engine trigger, but it's way too long, and I can't really understand what it's doing.
I see it calling some functions, but the custom scripts of the map are blank, so I guess the fuctions are part of that GUI trigger, and that's really confusing.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Hmm, I'm not sure I understand.. from what Wietlol explained earlier - there is a damage event, and a health event. The damage event is right before the health one, so if I run this trigger in the damage event - it wouldn't work as it's intended.
And well, my variables aren't nulls. I had another trigger: when I press escape - it was showing me the value of Temp_Health and the name of DmgBlock - they weren't nulls..

You create the trigger, but don't run the trigger. You create it so that it fires right after the damage event resolves (the actual damage is done).

You would have to display the value of Temp_Health and DmgBlock while the map is loading because that is when your trigger is created. It doesn't attach these variables to the trigger, it just attaches the values in them. At the time that happens, they are most likely null and 0 (though you can maybe set their start values in the variable editor thing).
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
@WereElf
"Less than udg_Temp_Health"
"Set to udg_Temp_Health"

You set it to that value, not LESS than that value -_-

@SAUS
I actually think that a DDS is not fun to make.
Simply because a DDS is an improperly designed system.
It is based around something that we have that doesnt furfill our needs.

It is much more fun to make a system that is originally not supported by WC3.
And one that can have a proper design.
Like a missile system, a stat system, a spell engine, a buff system, etc.
 
Level 12
Joined
May 22, 2015
Messages
1,051
@WereElf


@SAUS
I actually think that a DDS is not fun to make.
Simply because a DDS is an improperly designed system.
It is based around something that we have that doesnt furfill our needs.

It is much more fun to make a system that is originally not supported by WC3.
And one that can have a proper design.
Like a missile system, a stat system, a spell engine, a buff system, etc.

Perhaps. I already started down the path of making the DDS quite a while ago (it was much more simple when I didn't know what was ahead lol). TBH, it started in GUI and I learned JASS and upgraded the system over time. Now it is fully JASS with a bunch of standard DDS features (at least good enough for myself) and I am still building it up. It's still a nice project for me since I haven't built a whole lot of complicated stuff yet.

I did build my own item combo system. It allows for auto-completion of items. I made it so that it would be much more simple for players (particularly new ones) play my map. It uses recursion to find out what items you have if you have any pieces and adds the cost of all the base items you would need to buy.

I haven't done much more than that in terms of complex systems, but I find it fun to work through the problems. It also lets me be more creative with my map :D
 
Level 13
Joined
Jan 2, 2016
Messages
978
@Wietlol
Well, I'm not an expert at JASS, but isn't what I'm doing: Checking when unit's life is less than Temp_Health, and setting it to Temp_Health

@SAUS
That makes sense!
So I need to create the trigger every time the GDD_Event runs, and destroy it in its end? :p
 
Level 12
Joined
May 22, 2015
Messages
1,051
@Wietlol
Well, I'm not an expert at JASS, but isn't what I'm doing: Checking when unit's life is less than Temp_Health, and setting it to Temp_Health

@SAUS
That makes sense!
So I need to create the trigger every time the GDD_Event runs, and destroy it in its end? :p

Yes :) You can add
call DestroyTrigger(GetTriggeringTrigger())
to the bottom of the function that is the trigger's action function. This will make it destroy itself automatically when it runs.
 
Level 13
Joined
Jan 2, 2016
Messages
978
Hmm... so I need to add the bottom half of the trigger (the trigger creating part) to the GDD_Event trigger, right?
But how exactly do I do it? I replace "InitTrig_Damage_Block" with "Damage_Block" and what do I replace "gg_trg_Damage_Block" with?
 
Level 12
Joined
May 22, 2015
Messages
1,051
Hmm... so I need to add the bottom half of the trigger (the trigger creating part) to the GDD_Event trigger, right?
But how exactly do I do it? I replace "InitTrig_Damage_Block" with "Damage_Block" and what do I replace "gg_trg_Damage_Block" with?

Is your GDD_Event trigger in JASS? You can't create trigger dynamically without JASS, and it is hard to add extra functions (you will need another separate function for the life event trigger to use). It will looks something like:

JASS:
// This function is the actions for each temporary trigger created by gddEventActions
function lifeEventActions takes nothing returns nothing
    // Do something here - the unit is done taking damage now.

    call DestroyTrigger(GetTriggeringTrigger())
endfunction

// This is the normal actions trigger for your GDD event
function gddEventActions takes nothing returns nothing
    // The code here should be moved into the appropriate spots in this trigger, but these are what you need
    local trigger t = CreateTrigger()
    call TriggerAddEvent(...) // Add the event for the unit's life here
    call TriggerAddAction(t, lifeEventActions)
    set t = null // This is important as you basically leak if you do not null local object variables
endfunction

// This function can't be renamed or removed and is based off the name of the trigger. It runs when the map loads.
function InitTrig_Some_GDD_Trigger takes nothing returns nothing
    gg_trg_Some_GDD_Trigger = CreateTrigger()
    ... // This will be the trigger stuff for creating your original GDD Trigger
endfunction
 
Level 13
Joined
Jan 2, 2016
Messages
978
JASS:
function Damage_Block takes nothing returns nothing
    call SetUnitLifeBJ( udg_DamUnit, udg_Temp_Health )
    call DisplayTextToForce(GetPlayersAll(),R2S(udg_Temp_Health))
    call DestroyTrigger( GetTriggeringTrigger() )
endfunction

function Make_Trigger takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterUnitLifeEvent( t, udg_DamUnit, LESS_THAN, udg_Temp_Health)
    call TriggerAddAction( t, function Damage_Block )
    set t = null
endfunction
  • Dam Detect
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • Set Temp_Health = (Life of GDD_DamagedUnit)
      • Set DamUnit = GDD_DamagedUnit
      • Custom script: call Make_Trigger()
Still doesn't work x_x

Do you think it will work if I set some local variables in "Make_Trigger" and then make Damage_Block" take them and use them instead of these Global ones?
 
Level 13
Joined
Jan 2, 2016
Messages
978
JASS:
function Block_Damage takes nothing returns nothing
    local real l = LoadReal(udg_Table, GetHandleId(GetTriggerUnit()), StringHash("Life"))
    call SetUnitLifeBJ( GetTriggerUnit(), l )
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Block_Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local real l = LoadReal(udg_Table, GetHandleId(GetTriggerUnit()), StringHash("Life"))
    call TriggerRegisterUnitLifeEvent( t, udg_Unit, LESS_THAN_OR_EQUAL, l )
    call TriggerAddAction( t, function Block_Damage )
    set t = null
endfunction
  • zxcvb
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set Unit = (Triggering unit)
      • Set Life = (Life of Unit)
      • Hashtable - Save Life as (Key Life) of (Key (Triggering unit)) in (Last created hashtable)
      • Custom script: call Block_Init()
This KIND A works... more likely: sometimes works sometimes doesn't...
 
Level 12
Joined
May 22, 2015
Messages
1,051
I am not exactly sure how the unit life event works, but the way that was suggested by Wietlol for setting it up you have to make it a lower number than their current life. The method suggested was to check when the unit's life is their current life - half the damage they will take from the damage event.

You should stick to detecting this with the DDS. Using the attack event could cause some really strange bugs. Sorry for the late reply. I was out of town all yesterday.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Okay so I went with the damage event indexing strategy. I think it is working now, however, I will need to do a lot of testing. There isn't that much that would break on my map if the damage index was off since most of the time the index changes, the damage source and victim are the same (usually it is just the unit dealing extra damage via a separate effect).

I think my old method with the timers was fine since I saved the relevant event variables into a hashtable under the timer's ID. However, it was definitely less efficient (saving and loading from the hashtable, creating and deleting the timer object) and it was also more code. The damage index way is more simple to work with and has less, and cleaner code.

I'll pop back in on this post if I have any more troubles. Thanks for all the help, everyone!
 
Status
Not open for further replies.
Top