Jump to content

Getting equipped weapon reference in quest script


teknofil

Recommended Posts

I am trying to do a perk that reduces spread for certain weapons. I made it work by attaching a script to each weapon, however this means that mod introduced weapons won't be able to benefit from this perk. I was hoping there was some way to get the reference for the equipped weapon in a quest script.
Link to comment
Share on other sites

I tried that and it doesn't seem to be working.

 

ref rWeapon

 

Begin GameMode

 

set rWeapon to player.GetEquippedObject 5

if rWeapon.GetWeaponNumProjectiles == 1

if rWeapon.GetWeaponSpread > .5

rWeapon.SetWeaponSpread .5

endif

rWeapon.SetWeaponMinSpread 0

endif

 

End

 

That was the basics of the script I tried. The goal was to minimize the spread on all firearms except the shotguns.

Link to comment
Share on other sites

You can only call reference functions on references, but if you read the documentation you'll see that FOSE's GetEquippedObject returns a base form. Because of this, you'll need to pass its return value to the other functions as a base form, rather than calling them on it directly as though it were a reference. For example:

GetWeaponSpread rWeapon

Cipscis

Link to comment
Share on other sites

Ah, thank you very much. I read the FOSE command documents but saw the base object at the front of those commands and missed the inventory object at the tail end. I do have a few questions about using the inventory object to set those variables. Will every instance of the inventory object share the improved accuracy? I wouldn't want to make the NPCs better at shooting the player with a perk for the player. Also, am I right that the following code should reset the stats of a weapon when it is unequipped? It appears to be working, I just wanted to see if I was missing something else.

 

 

 

float fIDOriginalSpread
float fIDOriginalMinSpread
ref rWeaponEquipped
ref rWeaponUnequipped

Begin GameMode

if (player.HasPerk InertialDampener)
	set rWeaponEquipped to player.GetEquippedObject 5
	if rWeaponEquipped != rWeaponUnequipped
		SetWeaponSpread fIDOriginalSpread rWeaponUnequipped
		SetWeaponMinSpread fIDOriginalMinSpread rWeaponUnequipped
		set rWeaponUnequipped to rWeaponEquipped
		set fIDOriginalSpread to GetWeaponSpread rWeaponEquipped
		set fIDOriginalMinSpread to GetWeaponMinSpread rWeaponEquipped
	endif
	if (GetWeaponNumProjectiles rWeaponEquipped == 1)
		if GetWeaponSpread rWeaponEquipped > .25
			SetWeaponSpread 0.25 rWeaponEquipped
		endif
		SetWeaponMinSpread 0 rWeaponEquipped
	endif
endif

End

Link to comment
Share on other sites

  • Recently Browsing   0 members

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