Player Attack detection

Post » Sat May 28, 2011 6:43 am

I wish the game would tell me if the PLAYER has attacked a specific NPC.

The problem is, the NPC does not 'react' to the attack, so never goes into combat himself. So, none of the command that detect the NPC in combat will work.
And 'getUnconscious' for essential NPC's does not work either.

Anyone have any experience with detecting the player attacking a specific NPC?
User avatar
Project
 
Posts: 3490
Joined: Fri May 04, 2007 7:58 am

Post » Sat May 28, 2011 8:30 am

http://cs.elderscrolls.com/constwiki/index.php/OnHit
User avatar
Rude Gurl
 
Posts: 3425
Joined: Wed Aug 08, 2007 9:17 am

Post » Sat May 28, 2011 1:39 am

GetUnconscious only refers to the flag from SetUnconscious anyway.
User avatar
Danial Zachery
 
Posts: 3451
Joined: Fri Aug 24, 2007 5:41 am

Post » Sat May 28, 2011 6:28 am

I wish the game would tell me if the PLAYER has attacked a specific NPC.

The problem is, the NPC does not 'react' to the attack, so never goes into combat himself. So, none of the command that detect the NPC in combat will work.
And 'getUnconscious' for essential NPC's does not work either.

Anyone have any experience with detecting the player attacking a specific NPC?


It can be done through a special effect placed on the weapon... it's possible to drag the REF ID of the target from that. Take a look at the behemoth fire hydrant effect script:

scn MQ01BehemothWeaponSCRIPTref	TargetBEGIN ScriptEffectStart	set Target to GetSelf	if target != player		MQ01BehemothREF.pushActorAway Target 10	endifEND


That "player" could have been any ref in the game, not just "player", and comparisons against it would have worked.
User avatar
Cat Haines
 
Posts: 3385
Joined: Fri Oct 27, 2006 9:27 am

Post » Sat May 28, 2011 1:38 am

http://cs.elderscrolls.com/constwiki/index.php/OnHit

Thanks, I will give that a try.

GetUnconscious only refers to the flag from SetUnconscious anyway.

Really? The WIKI does not say anything about that... Well, it does not say much of anything, really.
User avatar
Krystal Wilson
 
Posts: 3450
Joined: Wed Jan 17, 2007 9:40 am

Post » Sat May 28, 2011 7:27 am

I once asked similar question to Cipscis about Me getting attacked and detect the bastard who is attacking me while Im not in combat.

(thus using GetCombatTarget is not possible since I won't be targetting anybody)

His Idea sorta worked (though It is bit complicated)


I first created an explosion with 1500-2000 radius with no force and no dmg and no visual effect.

the explosion has enchantment (enchantment with effect that is also in script that adds an item)

and by using script on NPC (my companion), he/she drops the explosion at everyframe by using PlaceAtMe function.
User avatar
m Gardner
 
Posts: 3510
Joined: Sun Jun 03, 2007 8:08 pm

Post » Sat May 28, 2011 2:33 am

I once asked similar question to Cipscis about Me getting attacked and detect the bastard who is attacking me while Im not in combat.

(thus using GetCombatTarget is not possible since I won't be targetting anybody)

His Idea sorta worked (though It is bit complicated)


I first created an explosion with 1500-2000 radius with no force and no dmg and no visual effect.

the explosion has enchantment (enchantment with effect that is also in script that adds an item)

and by using script on NPC (my companion), he/she drops the explosion at everyframe by using PlaceAtMe function.


That sounds like TalkieToaster's Bullet-Rain. ;)

Heck lets bring back the Orion Space Craft! It drops atomic bombs every X meters to propel itself forward (lol)

M
User avatar
Eduardo Rosas
 
Posts: 3381
Joined: Thu Oct 18, 2007 3:15 pm

Post » Sat May 28, 2011 7:15 am

I once asked similar question to Cipscis about Me getting attacked and detect the bastard who is attacking me while Im not in combat.

(thus using GetCombatTarget is not possible since I won't be targetting anybody)

His Idea sorta worked (though It is bit complicated)


I first created an explosion with 1500-2000 radius with no force and no dmg and no visual effect.

the explosion has enchantment (enchantment with effect that is also in script that adds an item)

and by using script on NPC (my companion), he/she drops the explosion at everyframe by using PlaceAtMe function.

Eh, I'd avoid doing that. Using fose's GetFirstRef/GetNextRef to sweep through the NPC references in the cell is a lot more efficient.
User avatar
Michael Korkia
 
Posts: 3498
Joined: Mon Jul 23, 2007 7:58 pm

Post » Sat May 28, 2011 12:12 am

I do not care who is attacking the player, I just want to know if a one of a kind scripted NPC is being 'attacked' by the player.

I have not had a chance to test this, but I think 'onHit' should work very nicely. If not, I will be back.

For example, the player attacks one of the robots or andriods in the Vault I am making. I want all the Andriods, robots and turrets to become hostile to the player.
User avatar
Amy Melissa
 
Posts: 3390
Joined: Fri Jun 23, 2006 2:35 pm

Post » Sat May 28, 2011 1:43 am

I do not care who is attacking the player, I just want to know if a one of a kind scripted NPC is being 'attacked' by the player.

I have not had a chance to test this, but I think 'onHit' should work very nicely. If not, I will be back.

For example, the player attacks one of the robots or andriods in the Vault I am making. I want all the Andriods, robots and turrets to become hostile to the player.


That NPC should attack back if the player attacks, and you can just do something like (if iscombattarget player == 1), it should live in the NPC's script.

I use this to do exactly the same thing you are needing to do pretty much. When one of my certain group is attacked (or actually certain dialogue conditions do it too), I make a faction change to turn the player into an enemy, and moddisposition -90 relative to the individuals in the group to gain an instant attack.
User avatar
Sheeva
 
Posts: 3353
Joined: Sat Nov 11, 2006 2:46 am

Post » Sat May 28, 2011 7:06 am

Then just put them all in the same faction and have the faction track crime, that ought to do it.
User avatar
koumba
 
Posts: 3394
Joined: Thu Mar 22, 2007 8:39 pm

Post » Sat May 28, 2011 3:20 am

Then just put them all in the same faction and have the faction track crime, that ought to do it.

The problem is, nobody in that faction will attack the player if the player attacks them.
They stand there taking the blows until they die and nobody in that faction could care less. Perhaps I just have the faction set up wrong.

Anyway, If I can detect the player attacking one of them, I can put them all in the hostile to the player faction. That is my goal.

EDIT:
The onhit block worked like a charm.
Thanks everyone for the replies. I don't usually ask questions, but this one was buggin' me to no end.
User avatar
Lauren Graves
 
Posts: 3343
Joined: Fri Aug 04, 2006 6:03 pm

Post » Sat May 28, 2011 2:24 am

The problem is, nobody in that faction will attack the player if the player attacks them.
They stand there taking the blows until they die and nobody in that faction could care less. Perhaps I just have the faction set up wrong.

Anyway, If I can detect the player attacking one of them, I can put them all in the hostile to the player faction. That is my goal.

EDIT:
The onhit block worked like a charm.
Thanks everyone for the replies. I don't usually ask questions, but this one was buggin' me to no end.


I am doing what you need without an onhit block, using the way I'd described, just a scripted section on the NPC to make the faction changes and lower dispositions -90 toward the player on all of the intended enemy faction members.
User avatar
Unstoppable Judge
 
Posts: 3337
Joined: Sat Jul 29, 2006 11:22 pm

Post » Sat May 28, 2011 7:57 am

I am doing what you need without an onhit block, using the way I'd described, just a scripted section on the NPC to make the faction changes and lower dispositions -90 toward the player on all of the intended enemy faction members.

They never go into combat, so using "iscombattarget player" does not work.
They don't even complain when you stand there shooting them...

I prefer the "OnHit player" block of code. It will 'only' run when the character is hit by the player. I would have to put 'iscombattarget player' in a gamemode or something similar for it to work. GameModes use system resources.
User avatar
CRuzIta LUVz grlz
 
Posts: 3388
Joined: Fri Aug 24, 2007 11:44 am

Post » Fri May 27, 2011 10:37 pm

They never go into combat, so using "iscombattarget player" does not work.
They don't even complain when you stand there shooting them...

I prefer the "OnHit player" block of code. It will 'only' run when the character is hit by the player. I would have to put 'iscombattarget player' in a gamemode or something similar for it to work. GameModes use system resources.


Aite I happen to have a script open that does it. By all means do what works best for you, but this other way does work.

Surely they do go into combat after you hit them more than like 5 times, right? Be sure to test with multiple hits...


scn PhalanxArcadiaSCRIPTbegin GAMEMODE;deal with player kills on Arcadia after befriending Quaternion (cancels the relationship, ends PQ01, yielding wont work in this case);additional code in followers2 as wellif (isCombatTarget player == 1 && PQ01.PlayerAcceptedDeal == 1 && PQ01.PlayerFriendlyToEnclave == 0)	setessential PhalanxArcadia 0	PhalanxArcadiaREF.Moddisposition player -90	setEnemy QuaternionFaction PlayerFaction	set PQ01.PlayerFriendlyToEnclave to 2	set PQ01.PlayerAcceptedDeal to 2endifEND

User avatar
Sam Parker
 
Posts: 3358
Joined: Sat May 12, 2007 3:10 am

Post » Fri May 27, 2011 6:44 pm

Actually tarrant, an onhit player block is more efficient on what you want to do (and probably, what willie wants to do).
Running things on gamemode blocks means running it every frame, unless you do other things that ought to be on a gamemode block for that npc, onhit is a better idea.
If you do have other things running on gamemode, the impact of adding 1 conditional check is minimal tho.
User avatar
Minako
 
Posts: 3379
Joined: Sun Mar 18, 2007 9:50 pm

Post » Sat May 28, 2011 8:15 am

Actually tarrant, an onhit player block is more efficient on what you want to do (and probably, what willie wants to do).
Running things on gamemode blocks means running it every frame, unless you do other things that ought to be on a gamemode block for that npc, onhit is a better idea.
If you do have other things running on gamemode, the impact of adding 1 conditional check is minimal tho.


I can't picture using onhit related code in my own application because it would bypass the safeguards that are in place to intelligently handle unintentional attacks on allies/teammates/etc.

If Arcadia and the player are both fighting an enemy that comes up (this has a significant likelihood in one of the quest directions the player can choose), and the player accidently hits arcadia, that onhit block would run I expect. That would screw my quest.

The OP must have something configured wrong in his definitions, like the NPCs are set to "help nobody" or something. He had written that there was no combat at all, and that's really just, broken. This way works and it works well, and accounts for the situation intelligently.
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Sat May 28, 2011 9:30 am

I can't picture using onhit related code in my own application because it would bypass the safeguards that are in place to intelligently handle unintentional attacks on allies/teammates/etc.

If Arcadia and the player are both fighting an enemy that comes up (this has a significant likelihood in one of the quest directions the player can choose), and the player accidently hits arcadia, that onhit block would run I expect. That would screw my quest.

The OP must have something configured wrong in his definitions, like the NPCs are set to "help nobody" or something. He had written that there was no combat at all, and that's really just, broken. This way works and it works well, and accounts for the situation intelligently.


You don't need to turn her hostile immediately with the code. Same conditionals you're using in the gamemode block can be used on an onhit block, difference being that instead of running the code every frame, it's run everytime you attack the npc.
NOTE: adding sendassaultalarm could make the npcs of that Quaternion faction to evp and attack the player, if you want to improve their turn-hostile time.
User avatar
Vickey Martinez
 
Posts: 3455
Joined: Thu Apr 19, 2007 5:58 am

Post » Sat May 28, 2011 10:28 am

You don't need to turn her hostile immediately with the code. Same conditionals you're using in the gamemode block can be used on an onhit block, difference being that instead of running the code every frame, it's run everytime you attack the npc.
NOTE: adding sendassaultalarm could make the npcs of that Quaternion faction to evp and attack the player, if you want to improve their turn-hostile time.


But it's like... all of the the proper checks to prevent undesireable combat initiation already exist within the executable, with timing accounted for, and combat situation, and everything. I'd have to account for all sorts of funky situations in my code to do as good a job. It sorta wouldn't make sense to do that when the ability is innate to the NPCs.
User avatar
Soraya Davy
 
Posts: 3377
Joined: Sat Aug 05, 2006 10:53 pm

Post » Fri May 27, 2011 10:07 pm

The only difference from running this:
if (isCombatTarget player == 1 && PQ01.PlayerAcceptedDeal == 1 && PQ01.PlayerFriendlyToEnclave == 0)	setessential PhalanxArcadia 0	PhalanxArcadiaREF.Moddisposition player -90	setEnemy QuaternionFaction PlayerFaction	set PQ01.PlayerFriendlyToEnclave to 2	set PQ01.PlayerAcceptedDeal to 2endif

In a gamemode block, and running it in an onhit player block, is that the former checks for the conditions every frame, while the later will do it whenever the player attacks it.

In other words, its this:

Frame 0000: am i hostile? -> no
frame 0001: am i hostile? -> no
frame 0002: am i hostile? -> no
frame 0003: am i hostile? -> no
...
frame 9921: am i hostile? -> yes -> run code

vs this:

Frame n: Player shoots npc for the first time -> am i hostile? -> no.
...
Frame z: Player shoots npc for the nth time -> am i hostile? -> yes -> run code.
User avatar
^~LIL B0NE5~^
 
Posts: 3449
Joined: Wed Oct 31, 2007 12:38 pm

Post » Sat May 28, 2011 1:05 am

You could add code in the OnHit to check how much time has passed since the last 'hit'. You coudl then zero out the count 'nth time'. This would be more believable to me.

There is nothing wrong with how I have my NPC's set up. I have them set up this way on purpose. I just wanted to control when they attack the player, not let the game engine decide for me.
User avatar
DeeD
 
Posts: 3439
Joined: Sat Jul 14, 2007 6:50 pm

Post » Sat May 28, 2011 6:22 am

In a gamemode block, and running it in an onhit player block, is that the former checks for the conditions every frame, while the later will do it whenever the player attacks it.

In other words, its this:

Frame 0000: am i hostile? -> no
frame 0001: am i hostile? -> no
frame 0002: am i hostile? -> no
frame 0003: am i hostile? -> no
...
frame 9921: am i hostile? -> yes -> run code

vs this:

Frame n: Player shoots npc for the first time -> am i hostile? -> no.
...
Frame z: Player shoots npc for the nth time -> am i hostile? -> yes -> run code.


It's checking every frame for iscombattarget and will drop out if its false, that's sorta like, no big deal... If I really wanted to optimize, I could put it into a startcombat player block, which I very well may do..

Bethesda's handing on deciding when to have the NPC become hostile is less error prone than what I would throw together in script code, and its all hardcoded, which means its going to be efficient and fast...

If your guy is playerteammate I believe, or has some close relationship with you to where you are fighting together (im not positive all the conditions that apply, it may be more than just playerteammate), you can make, I believe, an infinite number of accidental hits and nothing bad happens. If you are screwing around and shooting the NPC a couple of times, it lets you hit like, 5 times or something, and then it even lets you 'yield' after that, unless like in Arcadia's case I force a faction change for a specific effect.

Sorry but I don't see what you guys don't like about doing it that way. I like how well that works, and how it won't make mistakes, and how its all in the executable so its fast, and how it doesn't require attempting to rewrite all of those conditions and all of that intelligence into script code. It's all right there already, thanks to someone else's coding. If they write code to do a specific job and that code is well-weathered (I read this behavior exists in Oblivion), I'll want to want to avail myself of it when the opportunity presents itself.

Having said that, I wish they'd put my distance-based-weapon-switching-script code directly into their executable... it actually svcks to have to put script code in place that overrides code in the executable. It svcks, its conflict-prone, and is non-optimal. I only did it because it was necessary and scripting was the only tool available to me.

How someone wants to do it in their own creation is up to them obviously. I'm replying at this point to express that there are sometimes benefits to doing things the way the game's designed to handle it (this way).
User avatar
Ross
 
Posts: 3384
Joined: Thu Aug 10, 2006 7:22 pm

Post » Sat May 28, 2011 9:17 am

Don't lump me in with 'everyone' who does not like the way you are doing it. Only you know whats best for your mod, as I know whats best for mine.
For what I want, the OnHit will work better.

The Vault NPC's are in the player faction when in friendly mode. When I make them hostile, I have another faction I put them in, and I remove the friendly faction.

This all works flawlessly since they all must intially be hostile to the player until the player hacks the security terminal and reprograms them all. Then, they must all stop combat and like the player. As I said, this works.
But if the player is going to attack them, I want them to attack on sight once again. So, the OnHit works best for me. There should not be 'friendly' fire in the vault. there are no enemies. So, if the player is going to shoot somebody, even once, there needs to be repercussions to that action.
User avatar
Ross
 
Posts: 3384
Joined: Thu Aug 10, 2006 7:22 pm

Post » Fri May 27, 2011 8:48 pm

Don't lump me in with 'everyone' who does not like the way you are doing it.


Now that you mention it, it does sound like you don't like the way I'm doing it.

Only you know whats best for your mod, as I know whats best for mine.
For what I want, the OnHit will work better.

The Vault NPC's are in the player faction when in friendly mode. When I make them hostile, I have another faction I put them in, and I remove the friendly faction.

This all works flawlessly since they all must intially be hostile to the player until the player hacks the security terminal and reprograms them all. Then, they must all stop combat and like the player. As I said, this works.
But if the player is going to attack them, I want them to attack on sight once again. So, the OnHit works best for me. There should not be 'friendly' fire in the vault. there are no enemies. So, if the player is going to shoot somebody, even once, there needs to be repercussions to that action.


And when the player accidently presses the trigger button instead of his TALK key, which I have done at least twice this past week, he's [censored].

And in the event it somehow happened, I'm sure the player would be totally understanding as opposed with left wondering why every other friendly NPC in the game accepts a few accidental hits.

And he and wouldn't feel like the behavior was excessive or, even, buggy (as opposed with a deliberate feature).

Not trying to be a total ass or anything but, yeah. If you're happy with that, do it your way. Forget I said anything. Noboduy eber makes typoea or presses their mouse button by accident in-game anyway.
User avatar
Robyn Howlett
 
Posts: 3332
Joined: Wed Aug 23, 2006 9:01 pm

Post » Fri May 27, 2011 9:34 pm

...And he and wouldn't feel like the behavior was excessive...


We're talking about the same game right?. Pickpocket an npc in megaton, come on, go ahead, do it. See how the whole town will shoot you to death.
User avatar
Bitter End
 
Posts: 3418
Joined: Fri Sep 08, 2006 11:40 am

Next

Return to Fallout 3