Trigger when the player hits an NPC?
From The Elder Scrolls Construction Set Wiki
[edit] Question
Is there a way to get a script to trigger when the player hits any monster or NPC?
For example, I'd like to make a ring that does fire damage when the player hits someone, regardless of what weapon is being used.
I've been looking over the description for Begin, but there doesn't seem to be a trigger that does this. The closest is "Begin OnHit <actor>", but that runs on the target being hit, and not on the actor doing the hitting. I suppose it's possible to use this, but it would involve adding a script for every creature and NPC in the game. (Rather undesirable, to say the least!) -- diablerie
[edit] Discussion
This is what enchanted weapons are for... --Kkuhlmann 10:56, 14 April 2006 (EDT)
- True. But what if I wanted to have the effect happen no matter what weapon is being used, or when fighting unarmed? -- diablerie 11:00, 14 April 2006 (EDT)
- This is one of the things you can't do.--Kkuhlmann 11:34, 14 April 2006 (EDT)
- OK, thanks. -- Diablerie 11:59, 15 April 2006 (EDT)
- If you didn't mind it being just "reasonably" accurate, you could make a good approximation of if someone is hit by casting an Area effect spell from an activator regularly and checking the status of the Actors in their ScriptEffectUpdate blocks. For instance if in the ScriptEffectStart block their IsInCombat value is 0 and in one of the updates it becomes 1, then you could check their health and who their combat target is and make an educated if not perfect guess as to whether that Actor hit them or not in the last frame. --Tegid 22:34, 16 April 2006 (EDT)
- DragoonWraith 19:40, 6 May 2006 (EDT): That doesn't work if you want to know every time the NPC is hit by the player. I think the best bet is to use the Reference Variables for Nearby Actors code and then script each of them to detect when their health has gone down. Rule out as many other possibilities of damage as you can (spells), make sure they're actually fighting the player, and pray they didn't get hurt by friendly fire, a fall, or a trap. I think that's the best you can do.
- As long as you don't mind a bit of maths, if you can add scripteffect abilities to NPCs (using scripteffect spells), you can check to see if they took health damage in the last frame, and then if the player is facing them (requires trigonometry, so get the Maths Library if you haven't already) and within a certain distance (if it's a melee attack you want) to try and filter out NPCs the player couldn't hit. If their scripteffect ability determines they took health, and were in the players "Threat zone", then run whatever effect on the player.
- No trigonometry required; getHeadingAngle does the math for you. The game doesn't technically check for collision of a weapon on an actor as far as I've seen. Instead it chooses the closest actor in the player's FOV as the target of the attack. This is my understanding of it from perusing the game settings in the CS, anyway. Scruggs 20:19, 3 July 2006 (EDT)
- As long as you don't mind a bit of maths, if you can add scripteffect abilities to NPCs (using scripteffect spells), you can check to see if they took health damage in the last frame, and then if the player is facing them (requires trigonometry, so get the Maths Library if you haven't already) and within a certain distance (if it's a melee attack you want) to try and filter out NPCs the player couldn't hit. If their scripteffect ability determines they took health, and were in the players "Threat zone", then run whatever effect on the player.
- DragoonWraith 19:40, 6 May 2006 (EDT): That doesn't work if you want to know every time the NPC is hit by the player. I think the best bet is to use the Reference Variables for Nearby Actors code and then script each of them to detect when their health has gone down. Rule out as many other possibilities of damage as you can (spells), make sure they're actually fighting the player, and pray they didn't get hurt by friendly fire, a fall, or a trap. I think that's the best you can do.

