Getting the damage of an attack

Post » Wed Jun 20, 2012 1:30 pm

I want to get it in an OnHit event... obviously there's no argument for this.

I could make a huge list of all weapons and their damage ratings in an array and loop through it until I get to the one that was used, and then calculate based on the attacker's actor values, but this has to be fast (something like... 100 ms or less) and I don't want to take the time to define that array by hand without knowing that it's going to be fast enough. I don't think it would work for user-enchanted weapons either, and making that list by hand would be really annoying in itself.

Is there another way to do it?
User avatar
Kira! :)))
 
Posts: 3496
Joined: Fri Mar 02, 2007 1:07 pm

Post » Wed Jun 20, 2012 10:17 pm

Right off the top of my head (I haven't researched it), you could store the player's Health in a float (say, OnInit()), and when the OnHit event occurs, you could do a diff between their old Health and their current Health. The delta would be the damage.
User avatar
Jesus Duran
 
Posts: 3444
Joined: Wed Aug 15, 2007 12:16 am

Post » Wed Jun 20, 2012 7:00 pm

Right off the top of my head (I haven't researched it), you could store the player's Health in a float (say, OnInit()), and when the OnHit event occurs, you could do a diff between their old Health and their current Health. The delta would be the damage.

Yes, that would work, but it could become messed up easily if the actor takes damage or uses healing magic between the time that the health is stored and when the hit happens.
I.e. if the health is stored when the player's health is 90, and then he heals to 100 with a healing spell, then the damage is going to return as 10 less than it really is... unless onhit captures literally -everything-, but I don't think it captures potion usage or automatic health regen.

I'll think about it more though,.. it would be great if I could somehow store it just before the attack happens; if there's some event that I can capture when someone starts attacking, that would be a great time to update.

Obviously I could just update it several times per second between attacks, but that's messy and could have bad performance if I run it on more than one actor at a time. I might test it out anyway because it's easy enough to make.
User avatar
Wayne W
 
Posts: 3482
Joined: Sun Jun 17, 2007 5:49 am

Post » Wed Jun 20, 2012 11:40 pm

I've found that the OnHit event captures healing spells, so presumably it should capture potion usage as well. If not, you could use the OnMagicEffectApply event, since all potions come with magic effects.

No idea on what to do about health regen though, other than extremely frequent updates.
User avatar
Hayley O'Gara
 
Posts: 3465
Joined: Wed Nov 22, 2006 2:53 am

Post » Wed Jun 20, 2012 7:49 pm

I've found that the OnHit event captures healing spells, so presumably it should capture potion usage as well. If not, you could use the OnMagicEffectApply event, since all potions come with magic effects.

No idea on what to do about health regen though, other than extremely frequent updates.

Well, I'm thinking of getting rid of health regen for my mod anyway. I'm making a script that does the frequent updates right now and I'll see how it goes. I'll test with a ridiculous amount of actors using it (50 in a cell?) and if it goes poorly, I'll try it that way and just get rid of health regen over time and do it manually when the player sleeps/waits... Thanks for telling me about OnMagicEffectApply, I didn't know about it. :)
User avatar
emily grieve
 
Posts: 3408
Joined: Thu Jun 22, 2006 11:55 pm

Post » Thu Jun 21, 2012 1:13 am

I've found that the OnHit event captures healing spells, so presumably it should capture potion usage as well. If not, you could use the OnMagicEffectApply event, since all potions come with magic effects.

No idea on what to do about health regen though, other than extremely frequent updates.

If there is some way to find or calculate the rate of regeneration, perhaps you could factor it in by multiplying It times the delta of the current time and the time of the last hit event, then adding it to whatever number you get from the method above. That should be fairly accurate it you take into account all Perks and whatn
User avatar
Tamara Dost
 
Posts: 3445
Joined: Mon Mar 12, 2007 12:20 pm

Post » Wed Jun 20, 2012 2:20 pm

If there is some way to find or calculate the rate of regeneration, perhaps you could factor it in by multiplying It times the delta of the current time and the time of the last hit event, then adding it to whatever number you get from the method above. That should be fairly accurate it you take into account all Perks and whatn

Right; It's an actor value, "healrate". Good idea.
User avatar
sara OMAR
 
Posts: 3451
Joined: Wed Jul 05, 2006 11:18 pm

Post » Wed Jun 20, 2012 12:24 pm

I've found that the OnHit event captures healing spells, so presumably it should capture potion usage as well. If not, you could use the OnMagicEffectApply event, since all potions come with magic effects.

No idea on what to do about health regen though, other than extremely frequent updates.

If there is some way to find or calculate the rate of regeneration, perhaps you could factor it in by multiplying It times the delta of the current time and the time of the last hit event, then adding it to whatever number you get from the method above. That should be fairly accurate it you take into account all Perks and whatnot that modify healing rate and also in combat and out of combat rates, assuming there are oncombatstart and oncombatstop events
User avatar
katie TWAVA
 
Posts: 3452
Joined: Tue Jul 04, 2006 3:32 am

Post » Wed Jun 20, 2012 7:24 pm

If there is some way to find or calculate the rate of regeneration, perhaps you could factor it in by multiplying It times the delta of the current time and the time of the last hit event, then adding it to whatever number you get from the method above. That should be fairly accurate it you take into account all Perks and whatnot that modify healing rate and also in combat and out of combat rates, assuming there are oncombatstart and oncombatstop events

That gave me a good idea for the "check 10 times per second" method... I only need to do that if the actor is in combat, so I could unregister them in an oncombatstop event to make it more efficient if there aren't a lot of actors fighting. Still not done testing it though, it might be fine like this.
User avatar
James Rhead
 
Posts: 3474
Joined: Sat Jul 14, 2007 7:32 am

Post » Wed Jun 20, 2012 8:58 pm

Well, this works perfectly when just tested on the player:

Scriptname _DamageCalcNew extends Actor  int cHealth					;Self current health, gets updated at set intervalsint aHealth					;Self health after the attackfloat chUpdate = 0.25		;Self current health update interval in secondsint DTaken					;Self damage taken from the attackEvent OnInit()	;Register for current health update	;Debug.Notification("Registering "+self)	RegisterForUpdate(chUpdate)EndeventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	;Test health	;debug.messagebox("Pre-attack health = "+cHealth)	;utility.wait(0.01)	;debug.messagebox("Post-attack health = "+GetAv("Health"))		aHealth = GetAV("Health") as int	DTaken = cHealth - aHealth	;Damage taken.			EndeventEvent OnUnLoad()	;Unloaded, stop updating	;Debug.Notification("Unregistering "+self)	UnregisterForUpdate()EndeventEvent OnUpdate()	;Updating health	cHealth = GetAV("Health") as int	;debug.messagebox("Updated cHealth to "+cHealth)Endevent

The only problem is that it activates on any type of attack. I want to ignore non-melee attacks (magic, potions, etc.).
User avatar
SaVino GοΜ
 
Posts: 3360
Joined: Mon Sep 17, 2007 8:00 pm

Post » Thu Jun 21, 2012 12:36 am

Well, I guess I'll just check the source for keywords and hope the weapon being used has them. It's a total conversion though, so it should be fine.
User avatar
Guy Pearce
 
Posts: 3499
Joined: Sun May 20, 2007 3:08 pm

Post » Wed Jun 20, 2012 9:14 pm

I also need to identify the damage done in attacks for my scripts, and I liked the idea of using OnUpdate to keep health information updated. I don't think it can hinder performance that much.

To make sure OnHit fires only for melee attacks, I think you can use something like this:

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, ......)  if (akSource as Weapon)    aHealth = GetAV("Health") as int    DTaken = cHealth - aHealth	  ;Damage taken.  endifEndEvent
User avatar
D LOpez
 
Posts: 3434
Joined: Sat Aug 25, 2007 12:30 pm

Post » Wed Jun 20, 2012 4:05 pm

I also need to identify the damage done in attacks for my scripts, and I liked the idea of using OnUpdate to keep health information updated. I don't think it can hinder performance that much.

Yeah, it's just one line 4 times per second. That's probably a drop in an ocean compared to what else the game is doing in that time.

4 times per second works quite well by the way... you might only need to increase it to 10 times per second if you're getting attacked by something like... 20 enemies at once. I'm not sure if 20 enemies can be in combat at once though.
User avatar
teeny
 
Posts: 3423
Joined: Sun Feb 25, 2007 1:51 am

Post » Wed Jun 20, 2012 10:05 pm

I also need to identify the damage done in attacks for my scripts, and I liked the idea of using OnUpdate to keep health information updated. I don't think it can hinder performance that much.

To make sure OnHit fires only for melee attacks, I think you can use something like this:

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, ......)  if (akSource as Weapon)	aHealth = GetAV("Health") as int	DTaken = cHealth - aHealth	  ;Damage taken.  endifEndEvent

I know this might be getting a little complicated, but can you think of any way to separate the melee damage from enchantment damage when hit with an enchanted weapon?
User avatar
Rebecca Clare Smith
 
Posts: 3508
Joined: Fri Aug 04, 2006 4:13 pm


Return to V - Skyrim