Jump to content

Need help with some coding, if possible


Fantafaust

Recommended Posts

The intention is to have the script detect if the weapon has a scope, then set the mouse sensitivity to a preset amount if == 1.

Now, this does work, HOWEVER, it also returns items that do not have scopes but COULD have scopes ie the Varmint Rifle.

 

Code follows:

		if getweaponhasscope MyWeap == 1		;Check if weapon has scope
			if iscontrolpressed 6 == 1	;Check if zooming
				if SetMS == 0
					set BaseMS to getnumericinisetting "fMouseSensitivity:Controls"	;Store base mouse sensitivity
					setnumericinisetting "fMouseSensitivity:Controls" ScopeMS
					set SetMS to 1
				endif
			else
				if SetMS == 1
					setnumericinisetting "fMouseSensitivity:Controls" BaseMS
					set SetMS to 0
				endif
			endif
		endif

If anyone could let me know how I can detect if an item currently has a scope, that would be much appreciated. Edited by Fantafaust
Link to comment
Share on other sites

Well, i think i have it working, thanks again for the help man.

 

Working code follows:

		if getweaponhasscope MyWeap == 1		;Check if weapon can have scope
			set scopeMod to 0
			set modIndex to 1

			Label 1
			set modEffect to GetWeaponItemModEffect modIndex MyWeap
			if modEffect == 14
				set scopeMod to modIndex
			else
				set modIndex to modIndex + 1
				if modIndex < 4
					GoTo 1
				endif
			endif
			if scopeMod		; scope can come from a mod
				set weapFlags to Player.GetEquippedWeaponModFlags
				GoTo 2
			else		; weapon has scope built into it
				GoTo 2
			endif
		else	; scope not available for this weapon
			GoTo 3
		endif

		Label 2
		if LogicalAnd  weapFlags scopeMod		; has scope mod attached
			if iscontrolpressed 6 == 1	;Check if zooming
				if SetMS == 0
					set BaseMS to getnumericinisetting "fMouseSensitivity:Controls"	;Store base mouse sensitivity
					setnumericinisetting "fMouseSensitivity:Controls" ScopeMS
					set SetMS to 1
				endif
			else
				if SetMS == 1
					setnumericinisetting "fMouseSensitivity:Controls" BaseMS
					set SetMS to 0
				endif
			endif
		endif

		Label 3
		if ISEnabled == 1 && getweapontype MyWeap > 2 && getweapontype MyWeap < 10		;Check if weapon is a gun
			if iscontrolpressed 6 == 1	;Check if zooming
				if SetMS == 0
					set BaseMS to getnumericinisetting "fMouseSensitivity:Controls"	;Store base mouse sensitivity
					setnumericinisetting "fMouseSensitivity:Controls" ISMS
					set SetMS to 1
				endif
			else
				if SetMS == 1
					setnumericinisetting "fMouseSensitivity:Controls" BaseMS
					set SetMS to 0
				endif
			endif
		endif
Relevant mod here: http://www.nexusmods.com/newvegas/mods/47048/? Edited by Fantafaust
Link to comment
Share on other sites

  • 3 months later...

Well, i think i have it working, thanks again for the help man.

 

Working code follows:

		if getweaponhasscope MyWeap == 1		;Check if weapon can have scope
			set scopeMod to 0
			set modIndex to 1

			Label 1
			set modEffect to GetWeaponItemModEffect modIndex MyWeap
			if modEffect == 14
				set scopeMod to modIndex
			else
				set modIndex to modIndex + 1
				if modIndex < 4
					GoTo 1
				endif
			endif
			if scopeMod		; scope can come from a mod
				set weapFlags to Player.GetEquippedWeaponModFlags
				GoTo 2
			else		; weapon has scope built into it
				GoTo 2
			endif
		else	; scope not available for this weapon
			GoTo 3
		endif

		Label 2
		if LogicalAnd  weapFlags scopeMod		; has scope mod attached
			if iscontrolpressed 6 == 1	;Check if zooming
				if SetMS == 0
					set BaseMS to getnumericinisetting "fMouseSensitivity:Controls"	;Store base mouse sensitivity
					setnumericinisetting "fMouseSensitivity:Controls" ScopeMS
					set SetMS to 1
				endif
			else
				if SetMS == 1
					setnumericinisetting "fMouseSensitivity:Controls" BaseMS
					set SetMS to 0
				endif
			endif
		endif

		Label 3
		if ISEnabled == 1 && getweapontype MyWeap > 2 && getweapontype MyWeap < 10		;Check if weapon is a gun
			if iscontrolpressed 6 == 1	;Check if zooming
				if SetMS == 0
					set BaseMS to getnumericinisetting "fMouseSensitivity:Controls"	;Store base mouse sensitivity
					setnumericinisetting "fMouseSensitivity:Controls" ISMS
					set SetMS to 1
				endif
			else
				if SetMS == 1
					setnumericinisetting "fMouseSensitivity:Controls" BaseMS
					set SetMS to 0
				endif
			endif
		endif
Relevant mod here: http://www.nexusmods.com/newvegas/mods/47048/?

 

If dont bother you, can you tell me what this lines do?

 

 

if scopeMod        ; scope can come from a mod

 

Is it checking if scopeMod its different from zero?

 

And this line...i really dont understand what it means...its checking if both scopeMod and weapFlags are different from zero?

 

 

if LogicalAnd weapFlags scopeMod
Link to comment
Share on other sites

  • 7 months later...

 

 

If dont bother you, can you tell me what this lines do?

 

if scopeMod        ; scope can come from a mod

Is it checking if scopeMod its different from zero?

 

And this line...i really dont understand what it means...its checking if both scopeMod and weapFlags are different from zero?

 

if LogicalAnd weapFlags scopeMod

 

 

"if scopemod" is checking if the weapon can have a scope, ie if you can add a scope via a mod.

 

"if LogicalAnd weapFlags scopemod" is using a LogicalAnd sequence to determine if the weapon has BOTH scopemod and weapflags returning a true value for their scope checks.

ie, if scopemod returns true for scope being possible, and weapflag returns true for scope being attached, it will allow the conditions following the check.

Link to comment
Share on other sites

"if scopemod" is checking if the weapon can have a scope, ie if you can add a scope via a mod.

No, that's checking whether or not scopemod has a non-zero value.

"if LogicalAnd weapFlags scopemod" is using a LogicalAnd sequence to determine if the weapon has BOTH scopemod and weapflags returning a true value for their scope checks.

ie, if scopemod returns true for scope being possible, and weapflag returns true for scope being attached, it will allow the conditions following the check.

Also wrong. You're performing a bitwise AND operation to determine if all bits present in the value of scopemod are also present in the value of weapFlags. A simpler way to understand it in this context is, "Does the bitfield weapFlags contain the bit scopemod?"
Link to comment
Share on other sites

 

"if scopemod" is checking if the weapon can have a scope, ie if you can add a scope via a mod.

No, that's checking whether or not scopemod has a non-zero value.

You are correct. Upon re-reading, my explanation of what If Scopemod is performing is not accurate.

It is checking if a scope is attached from a mod, as set by equating it to modindex if modeffect equals 14.

 

It would only have a non-zero value if this was the case.

 

"if LogicalAnd weapFlags scopemod" is using a LogicalAnd sequence to determine if the weapon has BOTH scopemod and weapflags returning a true value for their scope checks.

ie, if scopemod returns true for scope being possible, and weapflag returns true for scope being attached, it will allow the conditions following the check.

Also wrong. You're performing a bitwise AND operation to determine if all bits present in the value of scopemod are also present in the value of weapFlags. A simpler way to understand it in this context is, "Does the bitfield weapFlags contain the bit scopemod?"

This is also correct, I explained this incorrectly. The LogicalAnd is checking that Weapflags contains 1, which is what Scopemod is set to in this context.

If they both have 1, it returns true, which enables the mouse sensitivity change.

Edited by Fantafaust
Link to comment
Share on other sites

This may or may not be of help but my NVR and JSU mods have a very similar but simpler script which detects scopes, in order to ignore or revert changes to FOV. You're free to use that and simply edit it to change mouse sensitivity when appropriate instead.

 

I'd also recommend adding the code to enable and disable the sensitivity change to a UDF and just call that instead of repeating the same lines at different points in the code. If you want the script to apply to controller users, it may be a good idea to use JIP's GetPCUsingIronSights instead of detecting the control.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...