How to detect crouched main character?

Post » Sat May 28, 2011 11:00 am

Hello, I'm trying to create a script that will add / remove a perk only when the player is crouched and aiming down the iron sights of a weapon. Is there a way to check for the player being crouched, even if they might not be hidden? I've found the function "http://geck.gamesas.com/index.php/IsSneaking" but I can't tell if that just returns a 1 if the player is actually hidden, or in the crouched state. If it works for any crouched state, will it work correctly in combat?

Also, I've read that the function IsPlayerActionActive for detecting iron sights doesn't work in combat. Is there a reliable way to check for it? I want to create a script that will dynamically add / remove a perk that will make a crouched character's gun wobble in iron sights mode.
User avatar
xx_Jess_xx
 
Posts: 3371
Joined: Thu Nov 30, 2006 12:01 pm

Post » Sat May 28, 2011 8:55 am

Take a peek at how the Chinese Stealth Suit works- it applies a stealth field when one is sneaking. The script you want is most likely in that.

I'm not sure if it's been included in FO:NV, so you may need to look it up in the FO3 GECK if you have Operation: Anchorage.
User avatar
Nathan Maughan
 
Posts: 3405
Joined: Sun Jun 10, 2007 11:24 pm

Post » Sat May 28, 2011 2:07 pm

IsSneaking returns the crouched state.
IsActorDetected returns the general detection state (i.e. does anyone see me?).
GetDetected returns whether a specific actor (e.g. player) was noticed by the calling actor.
GetDetectionLevel returns the detection-level of the calling actor vs. a specified actor. (Hidden / Caution / Noticed / Seen)

The detection functions, especially the last two, can cause quite a bit of CPU-load when used in a script that runs often enough to add/remove a perk without noticeable delay.


Instead of adding/removing a perk depending on whether the player is sneaking or not, why not simply add a perk that only works while sneaking (IsSneaking==1 in the conditions)? Would be more obvious for the player and cause less cpu-load.

Detecting aiming via "IsPlayerActionActive 9" (you could also use this in the perk conditions) doesn't work properly in combat, but if your idea is a sniper-type perk I don't think that's much of a problem, it actually adds to the game when you need to change positions or tactics when your target's buddys hunt you after a perk-boosted one-shot kill.

If you really need to detect aiming during combat, you need to use FNVSE and use "IsControlPressed 6" to check whether the player presses the block/aim button.
User avatar
Jennie Skeletons
 
Posts: 3452
Joined: Wed Jun 21, 2006 8:21 am

Post » Sat May 28, 2011 5:18 pm

Thanks JOG, now my XFO iron sight wobble works 100%. I'm using a quest script, firing every 1/5 a second and I think I coded it so that this won't continue to go off when it doesn't need to. The perk it applies checks for the sneaking condition, and all this code does is check for first person and iron sights (via RMB).

int bIsRMBPressedint bRemoveOncebegine gamemode	if bIsRMBPressed != IsKeyPressed 257		set bIsRMBPressed to IsKeyPressed 257		if bIsRMBPressed			if (IsPC1stPerson * player.IsWeaponOut)				player.addperk aaIronSightsFix				set bRemoveOnce to 1				printc "perk added"			elseif bRemoveOnce * (IsPC1stPerson != player.IsWeaponOut)				player.removeperk aaIronSightsFix				set bRemoveOnce to 0				printc "perk removed"			endif		elseif bRemoveOnce > bIsRMBPressed		       player.removeperk aaIronSightsFix		       set bRemoveOnce to 0		       printc "perk removed 2"		endif	endifend


Now, two things I've noticed. First, if I switch from 1st to 3rd person while aiming, the function IsPC1stPerson doesn't pick it up (meaning the subroutine that prints "perk removed" never fires) and only releasing the RMB removes the perk. Second, this perk will be applied to melee weapons.

How do I check for ranged vs. melee weapons? Also, is there a way to check for energy weapons vs. guns? The XFO aaIronSightsFix is only for guns but since I use WMX, I should create a energy weapons version and apply it when the PC is using them.

Edit: Damn, answered my own question. player.IsWeaponSkillType is apparently what I'm looking for.
User avatar
Chase McAbee
 
Posts: 3315
Joined: Sat Sep 08, 2007 5:59 am

Post » Sat May 28, 2011 11:34 pm

Thanks JOG, now my XFO iron sight wobble works 100%. I'm using a quest script, firing every 1/5 a second and I think I coded it so that this won't continue to go off when it doesn't need to. The perk it applies checks for the sneaking condition, and all this code does is check for first person and iron sights (via RMB).

i'd use http://geck.gamesas.com/index.php/IsControlPressed instead, even if you make the mod only for yourself, you might one day decide to use another key for aiming. Here, aiming is on button 4 (thumb) while the right mouse button is "activate".


How do I check for ranged vs. melee weapons?

http://geck.gamesas.com/index.php/GetWeaponAnimType

Also, is there a way to check for energy weapons vs. guns? The XFO aaIronSightsFix is only for guns but since I use WMX, I should create a energy weapons version and apply it when the PC is using them.

I'd try either http://geck.gamesas.com/index.php/IsWeaponInList (though it wouldn't work with weapons from other mods) or play with http://geck.gamesas.com/index.php/IsWeaponSkillType (currently undocumented on the geck-wiki, if you find out how it works please update the wiki)
User avatar
Tinkerbells
 
Posts: 3432
Joined: Sat Jun 24, 2006 10:22 pm

Post » Sat May 28, 2011 2:49 pm

player.IsWeaponSkillType doesn't seem to work in a script form. But perhaps the fault lies in the "player." part. I was able to get it to work in a Perk Entry / Conditions / Weapon, but not in the "Perk Owner" tab, so I'm thinking my player.XXX reference is wrong. How do I dynamically refer to an equipped weapon in the form of PlayerEquippedWeapon.IsWeaponSkillType ?
User avatar
m Gardner
 
Posts: 3510
Joined: Sun Jun 03, 2007 8:08 pm

Post » Sat May 28, 2011 9:59 pm

I've tried isWeaponSkillType on other actors besides the player and it doesn't work either - the script just halts.

Since perks only work on the player, do you really need the condition to work in the 'perk owner' tab?
User avatar
Monika Krzyzak
 
Posts: 3471
Joined: Fri Oct 13, 2006 11:29 pm

Post » Sat May 28, 2011 9:49 pm

No, but I would like to use it in a script. Since it works in the "Weapon" tab of Perk conditionals, does that mean that IsWeaponSkillType should act not on the player but a weapon?

EDIT: This test didn't work, nothing printed. I'm at a loss.

ref rWeaponEquippedbegin GameMode	if rWeaponEquipped != player.GetEquippedObject 5		set rWeaponEquipped to player.GetEquippedObject 5		if rWeaponEquipped.IsWeaponSkillType Guns			printc "guns"		elseif rWeaponEquipped.IsWeaponSkillType EnergyWeapons			printc "EnergyWeapons"		elseif rWeaponEquipped.IsWeaponSkillType Explosives			printc "Explosives"		endif	endifend

User avatar
Nathan Maughan
 
Posts: 3405
Joined: Sun Jun 10, 2007 11:24 pm

Post » Sat May 28, 2011 2:22 pm

If you use FNVSE anyway, you can use this:

short type ;// 3=pistol, 4=energy pistol, 5+6=rifle, 7=energy rifle, 10=grenaderef PlayerWeaponset PlayerWeapon to Player.GetEquippedObject 5set type to PlayerWeapon.GetWeaponType


or

short type ;// 34 = energy, 35 = explosives, 41=guns ref PlayerWeaponset PlayerWeapon to Player.GetEquippedObject 5set type to PlayerWeapon.GetWeaponSkill

User avatar
sarah
 
Posts: 3430
Joined: Wed Jul 05, 2006 1:53 pm

Post » Sat May 28, 2011 12:21 pm

GetEquippedObject returns a base form, so you need to call the functions by base form

set rCurrentWeaponREF to RHKBrisaREF.GetEquippedObject 5set iCurrentWeaponType to GetWeaponType rCurrentWeaponREFset iSkillRequired to GetWeaponSkill rCurrentWeaponREF

User avatar
Jinx Sykes
 
Posts: 3501
Joined: Sat Jan 20, 2007 11:12 pm


Return to Fallout: New Vegas