Detecting Hits on Actors

Post » Mon Jan 25, 2010 7:04 am

I am looking for a way to have a script constantly running that detects when the player successfully hits a NPC/Creature and then have it remove a certain extra amount of health from them using ModCurrentHealth. Is there a way to do this?

I am also wanting to have the script be able to detect whether the player used his/her fists, sword, or arrow/bolt, ect. to deal the blow with. Would there be anyway to determine this via script functions?

(MWSE functions are fine for these scripts.)

I also need to find a way to get a separate script to check when an NPC has struck the NPC with a specific weapon just like the above script.

The reason I am needing this is because I plan on implementing hand-to-hand health damage to the combat mod I'm working on as well as weapon specific bonuses that will have random percent chances of triggering special effects on the PC/NPCs when they are struck by that type of weapon.

Any help is extremely appreciated :) .
User avatar
Mashystar
 
Posts: 3460
Joined: Mon Jul 16, 2007 6:35 am

Post » Mon Jan 25, 2010 12:06 pm

You can watch for sounds playing on the player. I believe CnE does something like that to track kills/arrows fired/etc. Having it do anything on the NPC takes MWSE, but I'm not sure exactly how.
User avatar
Kevin Jay
 
Posts: 3431
Joined: Sun Apr 29, 2007 4:29 am

Post » Mon Jan 25, 2010 8:21 pm

LMAO!!! I was just about to suggest checking for the sound.


Here is an excerpt from MWSD V.9 on it:

Use sound to detect events
This to me was a very smart idea (thanks to BalorNG), so it bears mentioning again here, although it’s also described in the sound section above. You can use the GetSoundPlaying function to determine certain events in the game that would otherwise not be accessible. Just take a look at the sounds in the Gameplay/sounds menu, and it may give you some ideas: determine if someone is falling, determine whether a certain monster is near, determine a hit with a weapon etc.
Here is some more info on this (thanks Horatio):
GetSoundPlaying is a very powerful command that can be used to detect when the PC ( and I’m assuming other Actors ) is doing a certain action like casting a spell or swinging a weapon. I used it in my spellcasting mod to determine when the PC is casting a spell and what school of magic the spell is in. the format is as follows:

if ( player->GetSoundPlaying, "Sound ID" == 1 )
;do something cool here
endif

Look in the sounds menu in the TESCS to find which Sound ID corresponds to a specific action. For instance "illusion cast" corresponds to the player casting an illusion based spell. You'll probably have to experiment a little. Note: for some reason the Sound ID "drink" causes an error, so no checking if the PC is drinking a potion.

User avatar
Nauty
 
Posts: 3410
Joined: Wed Jan 24, 2007 6:58 pm

Post » Mon Jan 25, 2010 8:22 am

I was always under the impression that checking for sounds being played (especially short ones) was very unreliable. Is this not the case?

I remember trying to use sounds to check if the player was underwater once, but I couldn't get it to work (although admittedly, that may have been due to scripting ineptitude at the time).
User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Mon Jan 25, 2010 11:06 am

for specific weapons, you could try the HitOnMe function
User avatar
~Sylvia~
 
Posts: 3474
Joined: Thu Dec 28, 2006 5:19 am

Post » Mon Jan 25, 2010 5:03 am

Well the thing is, I need it to be able to read the weapon type that is being used to do the damage rather than a specific weapon. I need to be able to somehow hook the scripts on to the NPCs/Creatures as well as the PC so that it will pick up on exactly when the weapon strikes it's target everytime. Basically I'm going to try to simulate the Oblivion style damage system so that the higher the actor's skill is in a weapon the more damage it does. So how does one go about hooking a script on to several actors at a time that are capable of monitoring when a strike has landed on that actor and then deciphering the weapon type that was used to strike them?
User avatar
Alex Vincent
 
Posts: 3514
Joined: Thu Jun 28, 2007 9:31 pm

Post » Mon Jan 25, 2010 8:28 am

Hmm... it sounds to me like MWSE may be your best bet if you're ok with that - especially if you're planning to make this affect ALL NPCs - but unfortunately I can't help you with that, sorry :(
User avatar
Scott Clemmons
 
Posts: 3333
Joined: Sun Sep 16, 2007 5:35 pm


Return to III - Morrowind