NPC cought red handed. Punching with a tommy gun.

Cyrus

It Wandered In From the Wastes
I knew it! Those pesky NPCs; secretly pulling all kinds of shenanigans.

So... I have been writing the hit chance portion of my mod, and ran into a very peculiar crash, where my script worked for a few minutes, then stopped posting any messages. The script kept throwing warnings about attack type being out of range before stopping. Then when I quit the game, on exit I got a a crash and memory error of some kind. I checked the script but there wasn't anything particularly wrong.

So I wrote some tracing code to see whats going on.

See the image then read on...
This was a mobster estimating attack on a yakuza.

Let me explain what the text means.
"Mode" - refers to my function that determines weapon mode based on atktype.
HC - stand for hit chance hook function
raw HC - raw hit chance grabbed within HC hook.
adjusted - is the changed raw hit chance after the hook modifies the hit chance. (no change for now)

So:
1st - "Mode" is reporting that it was called for HC hook.
2nd - hit chance hook is reporting the weapon, the atktype, the determined mode, and the hit chances.
3rd - get_mode is called again from HC hook, but this time its reporting that its been supplied an atktype of 4 (punch) (which is supplied from HC hook by get_sfall_arg_at), and for safety its returning mode 1 since there is no mode for atktype of 4.
4th - HC hook is reporting that an attempt to calculate hit chances was made using weapon "Tommy Gun" and attack type 4 (punch), with mode decided as 1 hit chance is 30.


Fucking NPCs.


Jokes aside, any idea about what is going on?

If the attack type given is unpredictable, then this causes potentially serious issues when needing attack type. Now I've only encountered this from inside the tohit hook script. Is it possible that there is a problem in sfall? Though I doubt that.

I got to say I noticed that the AI tries to make multiple estimates using the different modes of the gun, so hit chance gets called several time for each NPC. It checks with both attacktype 2 and 3 and it seems once it decides which mode to use then it tries several attempts from different tiles and chooses best one. I don't understand why its trying to test with atktype 4 though.
Kept happening with tommy gun, but not with throwing knife or wakizashi. But I haven't tested enough, and don't plan to.
 

Attachments

  • scr.jpg
    scr.jpg
    120.9 KB · Views: 269
Last edited:
My mod script is very long and not all of it is gonna be related, but if you want ok. You might wanna stick only to relevant areas.

The parts that relate to this issue are:

procedure cr_tohit_hook;
procedure get_active_weapon;
procedure get_weapon_mode;
and maybe procedure start;

Also, you must have the ini file with it if you want to run it. location: \fallout 2\mods\crm.ini


I think the crashing problem may not have been related to this issue. I made a few changes and it seems to have gone away.
I'm not sure where the crash came from. It started after I added this module but that's doesn't mean much. My hook procedure names were: combatdamage_proc, tohit_proc., ...etc, and maybe the procedure naming was causing a problem. I changed the naming to cr_combatdamage_hook, cr_tohit_hook, etc. This I thought might be safer.


Anyway, just test the tohit hook and you'll see attack type of 4 being passed when critter weilding a gun and attempting to estimate hit chances. or you can even write you own short code to be sure.
 
Anyway, just test the tohit hook and you'll see attack type of 4 being passed when critter weilding a gun and attempting to estimate hit chances. or you can even write you own short code to be sure.
Well, I made a test script and didn't see any atktype of 4 when critter weilding a gun and attempting to estimate hit chances.
Does this always happen for you? or were these isolated cases?
 
My hook procedure names were: combatdamage_proc, tohit_proc., ...etc, and maybe the procedure naming was causing a problem. I changed the naming to cr_combatdamage_hook, cr_tohit_hook, etc. This I thought might be safer.
It is advisable not to change the script behavior and logs until the reason is found out.

It would be nice if you place display_msg ("TOHIT HOOK: atktype" + attack_type_arg);
at the beginning of the cr_tohit_hook procedure, for exclude any bad moments when working with the script.
 
Last edited:
Yes unfortunately I changed it and didn't keep a copy of the bad file.

If you wrote a test script please send me your copy so I test using your copy in the same situation. This was happening with mobsters around new reno using RPU v16.

When I fond time I'll do extra testing and share with you.
 
I must add, not all critters did it. And I "THINK" the reason for it is, the critter is assessing if doing an unarmed attack is feasible. And its doing it without switching item/hand. I think this might be AI scripted for specific critters, like mobster.
 
I must add, not all critters did it. And I "THINK" the reason for it is, the critter is assessing if doing an unarmed attack is feasible. And its doing it without switching item/hand. I think this might be AI scripted for specific critters, like mobster.
That's right, the NPC checks the chance to hit you with his fist, but he does not remove his weapon from the right slot. Now everything is clear, and this is a normal situation.
 
After more thought, indeed I concur. I think I understand what the problem was.

The way my code was acquiring the weapon was by checking the critter's right hand. However the critter is NOT using the right hand. It seems like the game simply uses left hand to assess unarmed attack potential for NPCs.

That's where this came from.

I've changed the function that acquired weapon. It now looks at attack type instead of hand.

I wonder if attacks for unarmed also simply happen directly from left hand while NPC still holds weapon in right hand.
 
Last edited:
After more thought, indeed I concur. I think I understand what the problem was.

The way my code was acquiring the weapon was by checking the critter's right hand. However the critter is NOT using the right hand. It seems like the game simply uses left hand to assess unarmed attack potential for NPCs.
An NPC is not a player, they don't need to clear a slot to check the chance of a punch or other weapon.
Additionally, the NPC does not have a left slot, all actions occur only in the right slot.

i. e. the point is that the NPC can apply a punch without removing the weapon from the right slot, as if hitting with the left hand.
 
Last edited:
Back
Top