HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Help] Modifying Damage

06-22-2008, 08:12 PM#1
deathdrivex
As title says, I need help on how to actually modify the damage a unit recieves.

I dont know how to do it in either JASS (still beginner) or Triggers (read around, couldnt do it the way I need it to work).

This is basically what I wanted to do:

1) A Hero is carrying "Iron Sword" with 10 charges. (With 10 as max charges)
2) When Hero attacks, charges drop when "Durability" equals a certain number when randomized. (<-- This is already done)
3) The charges is equal to 9 on Iron Sword, Hero attacks again.
4) The damage that the enemy recieves = 90% of maximum damage (<-- The part I CANNOT do)

Changing damage recieved depending on the amount of Charges on the weapon with 10 charges as max, not sure how to do it.
06-22-2008, 08:16 PM#2
tamisrah
I think that this takes quite an afford to work. You'll probably need something like bonusmod to trigger the damage bonus of your sword so you can adjust it via triggers.
06-22-2008, 08:36 PM#3
Themerion
What do you mean by 90% of maximum damage?
06-22-2008, 09:33 PM#4
the-thingy
You could add Item Attack Damage Bonus (I think that's what the ability is called) to the hero when an item is gained, and set it to the desired level when the weapon is acquired (and remove it when the item is dropped).

When durability is lost, just reduce the level of the ability.

Only problem would be the fact that the damage is shown as bonus damage (the green text) rather than normal damage.
06-22-2008, 10:04 PM#5
deathdrivex
Quote:
Originally Posted by Themerion
What do you mean by 90% of maximum damage?

The MaximumDamage = the damage done at that time WITHOUT the changes.
The 90% part is calculated to reduce the damage done. So for every charge removed, you lose 10%.

@the-thingy: Not sure about that method. I had each weapon with a Item Attack Damage Bonus of +2 already. I have a crafting system for combining weapons and etc. to make weapons with higher bonuses and extras.

Wished Blizzard just let us have a goddamned easier way to lower damage.

BTW: For reference, watch a "Monster Hunter Freedom" video for the PSP. Weapons have a sharpness system so that when you attack with it, it gets duller. And when it gets too dull, your will do little to no damage.
06-22-2008, 11:41 PM#6
Anitarf
Ok, considering how you formulated your question, I'm not exactly sure what's the problem, this...
Quote:
Changing damage recieved depending on the amount of Charges on the weapon
...or this?
Quote:
Changing damage recieved

Since figuring out the first should be fairly easy for someone who has already figured out the second, I'm going to assume it's the second that's giving you problems.

Damage prevention is tricky business. First, you need a damage detection system (this part would be just one trigger if we had a generic unit takes damage event, but since that only comes as a specific unit event it takes some more work to get this part working). Once we have damage detection working, it gets tricky. Sometimes, you can just give the unit some life back immediately when the damage detection trigger runs, however, you can only refund life this way when the amount of life refunded is less than the difference between unit's max hp and current hp, otherwise you won't be able to refund as much as you want. When this occurs, you must start a 0.0 second timer in the damage detection trigger and then refund the damage in the function that timer calls (the timer allows for the damage to actually be dealt, thus lowering the unit's actual hp below it's max hp enough that you have "room" to refund it). A new exception here would be if the damage dealt would kill the unit, in that case you would need to refund part of the damage before it's dealt, so the unit doesn't die, and refund the rest after the damage is dealt and you have room to restore the rest of it. Even this won't be enough, though, if you can deal damage higher than the unit's max hp, in that case you need to give the unit a bonus hp ability which allows the unit to survive the damage and then remove the ability and restore the unit's life after the damage is dealt.
06-23-2008, 12:10 AM#7
grim001
And then just see what kind of hell it becomes if you try to modify damage multiple times on the same unit at the same moment. That's why I created DamageMod.
06-23-2008, 12:24 AM#8
deathdrivex
I dont like the idea of refunding HP. Ill show an example of what I did which actually told me the damage I did do but it didnt do the "Reduced" damage from the charges so it did just normal.

Heres my test example I did in 10 minutes. It epicly failed, so not sure wth to do with it. Didnt throw it away cause I can maybe revise it later to work better.

EDIT: Also, I'm no good at JASS yet, I can only do memory leak fixes and creating units/items/doodads with it for now.


EDIT2: The problem I had with the following was that "ChargeCounter" is always 0. But the damage value DOES SHOW.
EDIT3: Added Image for Proof
EDIT4: Modified with a Real Variable, still no work.

Trigger:
Weapon Damage Add Unit
Collapse Events
Unit - A unit Is attacked
Collapse Conditions
(Owner of (Attacked Unit)) Equal to Neutral Hostile
Collapse Actions
Trigger - Add to Weapon Damage Set <gen> the event (Unit - (Attacked unit) Takes damage)

Trigger:
Weapon Damage Set
Events
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
If ((Item-type of (Item carried by (Attacking unit) in slot (Integer A))) Equal to Iron Sword) then do (Set Weapon = (Item carried by (Attacking unit) of type Iron Sword)) else do (Do nothing)
If ((Item-type of (Item carried by (Attacking unit) in slot (Integer A))) Equal to Wooden Bow) then do (Set Weapon = (Item carried by (Attacking unit) of type Wooden Bow)) else do (Do nothing)
If ((Item-type of (Item carried by (Attacking unit) in slot (Integer A))) Equal to Wooden Staff) then do (Set Weapon = (Item carried by (Attacking unit) of type Wooden Staff)) else do (Do nothing)
Set ChargeCounter = (Charges remaining in Weapon)
Set ChargeCounterReal = ((Real(ChargeCounter)) / 10.00)
Unit - Set life of (Attacked unit) to ((Life of (Attacked unit)) - ((Damage taken) x (Real(ChargeCounter))))
Game - Display to (All players) the text: (Damage Dealt: + (String((Damage taken))))
Game - Display to (All players) the text: (The Calculated Reduced Damage: + (String(((Damage taken) x ChargeCounterReal))))
Game - Display to (All players) the text: (ChargeCounter Value: + (String(ChargeCounter)))
Game - Display to (All players) the text: (ChargeCounterReal Value: + (String(ChargeCounterReal)))

06-23-2008, 12:54 AM#9
grim001
There is no other method to do it other than the one Anitarf described.
06-23-2008, 12:55 AM#10
deathdrivex
Darn, editor is cursed :0

Anyone can give a nice example of a working one?

EDIT: Got the charges to actually be calculated into a reduction damage via replacing Lumber (I dont use Lumber in my map for any reason). Now I'm trying to comprehend what Anitarf means by giving the life back and by how much.

EDIT 2: Heres my update on the system. It works so far, just need some help with making it nicer.
Also a question: Does the trigger edit damage upon the event "takes damage" immediately and changes it right away OR does it change it after it deals the original damage? (Sorry for bad wording, its midnight and lack of sleep)

EDIT3: Removed to protect eyes of the innocent!
06-23-2008, 08:25 AM#11
Anitarf
You're using the wrong event responses in your damage detection trigger, "attacked unit" and "attacking unit" should only be used with "unit is attacked" events. That's why your durability counters didn't work properly in the original, you didn't need to use lumber for them.

Actual damage is dealt immediately after the damage detection trigger runs, that's why I was talking about 0.0 timers in my previous post, it allows you to refund damage after it's dealt in those cases when you can't refund it earlier due to the unit being at max hp.
06-23-2008, 03:07 PM#12
deathdrivex
Thanks alot anitarf. I changed it to normal again. Had the attacked unit set to a variable and the attacking unit set to another.

I made it so it read the life of unit BEFORE the attack (which is 150) and after the "damage" (120 hp if my atk was 30). I added the 0.0 wait timer and had the following set and it works! It read the charges <<


EDIT: I got the whole system working with damage calculated and etc. This is method I used:

Trigger:
Weapon Damage Value
Collapse Events
Unit - A unit Is attacked
Collapse Conditions
(Owner of (Attacked unit)) Equal to Neutral Hostile
Collapse Actions
Set AttackingHero = (Attacking unit)
Set UnitAttacked = (Attacked unit)
Game - Display to (All players) the text: (Life Check Before: + (String((Life of UnitAttacked))))
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
If ((Item-type of (Item carried by AttackingHero in slot (Integer A))) Equal to Iron Sword) then do (Set Weapon = (Item carried by AttackingHero of type Iron Sword)) else do (Do nothing)
If ((Item-type of (Item carried by AttackingHero in slot (Integer A))) Equal to Wooden Bow) then do (Set Weapon = (Item carried by AttackingHero of type Wooden Bow)) else do (Do nothing)
If ((Item-type of (Item carried by AttackingHero in slot (Integer A))) Equal to Wooden Staff) then do (Set Weapon = (Item carried by AttackingHero of type Wooden Staff)) else do (Do nothing)
Set ChargeCounterReal = ((Real((Charges remaining in Weapon))) / 10.00)
Set LifeTest = (Life of UnitAttacked)
Trigger - Add to Weapon Damage Set <gen> the event (Unit - UnitAttacked Takes damage)

Trigger:
Weapon Damage Set
Events
Conditions
Collapse Actions
Wait 0.00 seconds
Unit - Set life of UnitAttacked to LifeTest
Set DamageTest = ((Damage taken) x ChargeCounterReal)
Unit - Set life of UnitAttacked to ((Life of UnitAttacked) - DamageTest)
Set AttackingHero = No unit
Set UnitAttacked = No unit