Jump to content

Attach Suppressor On Sneak


WolfmanMODS

Recommended Posts

Trying to create a mod that attaches a suppressor for the current weapon whenever the player enters sneak, if they have the needed mod in inventory. Here is my test script for the 10mm pistol, but while the debug notification fires, the mod, which I have in inventory, does not attach. What am I doing not right?

Weapon Property Type10mmPistol Auto
ObjectMod Property Mod10mmSup Auto Const

Event OnEnterSneaking()
    Actor PlayerRef = Game.GetPlayer()
    Weapon weaponCurrent = PlayerRef.GetEquippedWeapon()


    If (weaponCurrent == Type10mmPistol as Form)
        PlayerRef.AttachModToInventoryItem(weaponCurrent, Mod10mmSup)
        Debug.Notification("Added Suppressor")
    EndIf

EndEvent

Also does anyone know how to retrieve a list of mods equipped on a weapon? Need to add logic that wont attach the suppress if it already has another muzzle equipped.

Link to comment
Share on other sites

Turns out the is not a direct way to do this, as ".AttachModToInventoryItem" only works if you have one of that weapon type in your inventory. So my best jump-through-hoops answer, so far, for anyone looking this up is as follows and it turns out you have to use two reference containers, one for the weapon to be modded, and one for all the other similar weapons. Note I still have to jump through a few more hoops as this method erases the Favorite references, most of the time, and I cant restore said favorite reffs with the "MarkItemAsFavorite" command given that there appears to be no way to figure out what the Favor references were in the first place without a script extender.

 

Weapon Property Type10mmPistol Auto

ObjectMod Property Mod10mmSup Auto

ObjectReference Property TransferObjectsRef1 Auto Const

ObjectReference Property TransferObjectsRef2 Auto Const

Event OnEnterSneaking()

Actor PlayerRef = Game.GetPlayer()

Weapon weaponCurrent = PlayerRef.GetEquippedWeapon()

 

If (weaponCurrent == Type10mmPistol as Form)

 

PlayerRef.RemoveItem(weaponCurrent, 1, True, TransferObjectsRef1)

PlayerRef.RemoveItem(Type10mmPistol as Form, PlayerRef.GetItemCount(Type10mmPistol as Form), True, TransferObjectsRef2)

 

TransferObjectsRef1.Additem(Mod10mmSup, 1, True)

TransferObjectsRef1.AttachModToInventoryItem(weaponCurrent, Mod10mmSup)

TransferObjectsRef1.RemoveItem(weaponCurrent, 1, True, PlayerRef)

PlayerRef.EquipItem(weaponCurrent)

; PlayerRef.MarkItemAsFavorite(weaponCurrent, 4) ;Still trying to find way to get orginal Fav#

 

TransferObjectsRef2.RemoveItem(Type10mmPistol as Form, TransferObjectsRef2.GetItemCount(Type10mmPistol as Form), True, PlayerRef)

Debug.Notification("Added Suppressor")

EndIf

EndEvent

Link to comment
Share on other sites

Well do you have a key that you are planning to use specifically to add remove? If you could trigger to open a workbench menu and pause the world it might work as a clunky way for now until you can bypass the screen and just have it switch on off.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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