WolfmanMODS Posted July 30, 2016 Share Posted July 30, 2016 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 More sharing options...
shavkacagarikia Posted July 30, 2016 Share Posted July 30, 2016 For the mod to be attached on weapon you have to remove it from player and add again Link to comment Share on other sites More sharing options...
WolfmanMODS Posted August 1, 2016 Author Share Posted August 1, 2016 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 AutoObjectMod Property Mod10mmSup AutoObjectReference Property TransferObjectsRef1 Auto ConstObjectReference Property TransferObjectsRef2 Auto ConstEvent 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") EndIfEndEvent Link to comment Share on other sites More sharing options...
balsac Posted August 1, 2016 Share Posted August 1, 2016 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 More sharing options...
WolfmanMODS Posted August 2, 2016 Author Share Posted August 2, 2016 That imitatively would work, but as you say would be clunky. This was a secondary task for a bigger mod I'm working on so it either needs to operate smoothly, or I will just leave it out. Link to comment Share on other sites More sharing options...
Recommended Posts