Damage taken trigger

Emu.Man00

New Member
Reaction score
41
OK so i want to have a spell that will make you hurt yourself instead of another unit when you attack. I know the basics but i cant make him take the same damage that he would deal.

So my question would be is it possible to make a variable of how much damage a unit would deal?
And if not could you help me figure out another way to do the spell? :S
 
D

DsD)Core(

Guest
You'll need to store the damage done.
Two triggers needed, one to catch a unit and add it to your damage taking event.
The other, the damage taking event.

Unit Catch
Code:
Unit Catch
    Events
        Unit - A unit enters (Playable map area)
    Conditions
    Actions
        Trigger - Add to Dmg Catch <gen> the event (Unit - (Triggering unit) Takes damage)

Code:
Dmg Catch
Globalsys dmg catch
    Events
    Conditions
    Actions
        Set DmgDealt[(Player number of (Owner of (Damage source)))] = (DmgDealt[(Player number of (Owner of (Damage source)))] + (Damage taken))
        Unit - Set life of (Damage source) to ((Life of (Damage source)) - DmgDealt[(Player number of (Owner of (Damage source)))])
        Set DmgDealt[(Player number of (Owner of (Damage source)))] = 0

And you can add a condition to check if the damage taking unit has the ability.
 

Emu.Man00

New Member
Reaction score
41
I'm kinda confused about the first line of actions in the second trigger :S

What kind of variables should they be?
 
D

DsD)Core(

Guest
Sorry, I forgot to mention. Variables that store damage are always Real. These are Real Arrays, to make them MUI.

What it does is it says if a unit takes damage, it sets the damage done real of the damage source to the damage that was taken by the attacked unit. This variable is then substracted from the attacking unit in form of life, resulting in an exact damage return, and the variable is set to 0 again so it doesn't heap up and make it do stuff it shouldn't.

Note that this will also make it affect spells. Let me know if you'd like to avoid that or not.
 

jnZ

I
Reaction score
64
Code:
TRIG
    Events
    Conditions
    Actions
        Set DmgDealt = (Damage taken)
        Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + DmgDealt)
        Unit - Cause (Triggering unit) to damage (Damage source), dealing DmgDealt damage of attack type Spells and damage type Magic

use this one

only 1 variable needed to make it more efficient

variabletype: real
 
D

DsD)Core(

Guest
I actually used only 1 variable, I just forgot to remove _round and _total behind it since I copied it from my own map lol >.> Thanks for pointing that out.

But your trigger does cover something that I forgot about, and that is giving the life back to the attacked unit. However, the attacked unit can still die from the attack this way, if the damage done is more than their current health. We'll need to make a workaround for that.
 

Emu.Man00

New Member
Reaction score
41
ugh yeah i only need it for attack, not spells :D and a work around for the death thing would be very nice o.o
 
D

DsD)Core(

Guest
Alright, it's going to be alot of work for me to work everything out for you so I'm going to give you some pointers in the hope that they get you going.

The first thing, to make sure it's not going about a spell, is to make a condition ((damage source) equal to (event response - casting unit)) equal to false. Now it's noteworthy that you'll probably have to add every spell triggered to this trigger if unit starts the effect of an ability, which is going to be alot of work. I'm not even sure if that would work, but as I'm not a professional and you don't have your answer yet, I will tell you as much as far as I can go with what I know.

Then, next, the dying prevention thing. A cheap workaround would be to make a period event that checks if the last damage done of a unit is equal to or bigger than the current health of the targeted unit. If so, the unit is healed on the event unit is ATTACKED (not takes damage) by the last amount of damage done. Then, later, this amount should be corrected by the actual damage that was done. Another event, if the attack is cancelled, should remove the added life again, to prevent abuse to heal a unit by a-s-ing.

That would be a general picture. But someone would have to give you a more specific answer, since I honestly don't know how to do this exactly.

I hope you get it.
 

Emu.Man00

New Member
Reaction score
41
Alright thanks for all your help, ill try to work on that
+rep for you :D

also, can i put all the actions into an if statement, making it
Code:
If ((damage source) equal to (event response - attacking unit))
Then [actions]
Else do nothing
Would that work?
 
D

DsD)Core(

Guest
I think that would be a valid solution, yes. Note that you do need to add the unit attacks event somewhere and add it as an event or condition to this trigger. That event response won't come from nowhere.
 

Emu.Man00

New Member
Reaction score
41
so i add that as an action in the first trigger? like this?
Code:
Trigger - Add to Backfire <gen> the event (Unit - A unit Is attacked)

And another thing came up while testing, i want it to start when i cast a spell so i did this
Code:
Trigger - Add to Backfire <gen> the event (Unit - (Target unit of ability being cast) Takes damage)
and that didnt work, so is that the problem, or is it in the other trigger when it refers to "triggering unit"?
 
D

DsD)Core(

Guest
The problem is, if you add the unit is attacked event, it wont count as a condition for the damage taken being physical, it just makes two events instead of one for which the damage catcher can trigger. That's not what we want in this case. Maybe it would be an idea to put an attacking unit into a variable and then you can actually add a condition to the damage catcher that the unit must be in the unit group that you've put the attacking unit in. Make sure they're always removed afterwards, so the attacking unit cannot attack first and then cast a spell because it is already in the group anyway.

Does that make sense?
 

Emu.Man00

New Member
Reaction score
41
another thing came up while testing, i want it to start when i cast a spell so i did this
Code:
event-unit finishes casting an ability
condition-ability being cast equal to backfire equal to true
actions-trigger - add to backfire <gen> the event (unit - (target unit of ability being cast) takes damage)
and that didnt work, so is that the problem, or is it in the other trigger when it refers to "triggering unit"?
:d
 
D

DsD)Core(

Guest
The target unit of ability being cast is an event response and will be reset after a short amount of time. You'll see to use a unit variable and add it to that. Then the data won't be lost and you trigger might just work.
 

THE_X

New Member
Reaction score
49
You'll need to store the damage done.
Two triggers needed, one to catch a unit and add it to your damage taking event.
The other, the damage taking event.

Unit Catch
Code:
Unit Catch
    Events
        Unit - A unit enters (Playable map area)
    Conditions
    Actions
        Trigger - Add to Dmg Catch <gen> the event (Unit - (Triggering unit) Takes damage)

Code:
Dmg Catch
Globalsys dmg catch
    Events
    Conditions
    Actions
        Set DmgDealt[(Player number of (Owner of (Damage source)))] = (DmgDealt[(Player number of (Owner of (Damage source)))] + (Damage taken))
        Unit - Set life of (Damage source) to ((Life of (Damage source)) - DmgDealt[(Player number of (Owner of (Damage source)))])
        Set DmgDealt[(Player number of (Owner of (Damage source)))] = 0

And you can add a condition to check if the damage taking unit has the ability.

not MUI :( is MPI tho
 
D

DsD)Core(

Guest
I assumed you'd only have one hero per player. To make it MUI, you'll need to add a unit array elsewhere and systemize it a little differently so that it properly catches per unit. Meh.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top