Arcaidus Posted August 2, 2019 Share Posted August 2, 2019 I'm attempting to make a script that will see what the player is wearing using slot masks and then add up the weight of all the items. I know there's an easier way to be doing this for vanilla armors, but I wanted something that'd be compatible with all used body slots.My current iteration of the script (and believe me there's been a lot over the past couple of days) is this: Scriptname naguWeight extends ReferenceAlias GlobalVariable Property naguWeightTotal Auto Event OnObjectUnequipped(form akBaseObject, ObjectReference akReference) int SlotMask = 0x00000001 float naguWeightBase = 0.0 While (SlotMask < 0x40000001) naguWeightBase += (Game.GetPlayer().GetWornForm(SlotMask) as Armor).GetWeight() SlotMask *= 2 Debug.Trace("Trace: " + SlotMask + " weighs " + naguWeightBase) EndWhile naguWeightTotal.SetValue(naguWeightBase) EndEvent Event OnObjectEquipped(form akBaseObject, ObjectReference akReference) Utility.Wait(1) .... same s*** as unequipped .... EndEvent Which results in the following Papyrus errors being repeated (resulting in a 200k line long log lol): [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectUnequipped() - "naguWeight.psc" Line ? [08/02/2019 - 06:59:59PM] warning: Assigning None to a non-object variable named "::temp4" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectUnequipped() - "naguWeight.psc" Line ? [08/02/2019 - 06:59:59PM] Trace: 16 weighs 0.000000 [08/02/2019 - 06:59:59PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectUnequipped() - "naguWeight.psc" Line ? [08/02/2019 - 06:59:59PM] warning: Assigning None to a non-object variable named "::temp4" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectUnequipped() - "naguWeight.psc" Line ? [08/02/2019 - 06:59:59PM] Trace: 32 weighs 0.000000 [08/02/2019 - 06:59:59PM] Trace: 64 weighs 1.000000 [08/02/2019 - 06:59:59PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectUnequipped() - "naguWeight.psc" Line ? [08/02/2019 - 06:59:59PM] warning: Assigning None to a non-object variable named "::temp4" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectUnequipped() - "naguWeight.psc" Line ? [08/02/2019 - 06:59:59PM] Trace: 2 weighs 0.000000 [08/02/2019 - 07:00:00PM] Trace: 4 weighs 1.000000 [08/02/2019 - 07:00:00PM] Trace: 8 weighs 2.000000 [08/02/2019 - 07:00:00PM] Trace: 16 weighs 6.000000 ... a lot of other s*** that appears the same ... [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] Trace: 1024 weighs 15.000000 [08/02/2019 - 07:00:30PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] warning: Assigning None to a non-object variable named "::temp8" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] Trace: 2048 weighs 15.000000 [08/02/2019 - 07:00:30PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] warning: Assigning None to a non-object variable named "::temp8" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] Trace: 4096 weighs 15.000000 [08/02/2019 - 07:00:30PM] Trace: 8192 weighs 16.000000 [08/02/2019 - 07:00:30PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] warning: Assigning None to a non-object variable named "::temp8" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] Trace: 16384 weighs 16.000000 [08/02/2019 - 07:00:30PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] warning: Assigning None to a non-object variable named "::temp8" stack: [alias PlayerRef on quest naguWeightModQuest (0D001DE2)].naguWeight.OnObjectEquipped() - "naguWeight.psc" Line ? [08/02/2019 - 07:00:30PM] Trace: 32768 weighs 16.000000 [08/02/2019 - 07:00:30PM] Error: Cannot call GetWeight() on a None object, aborting function call stack: Which I'm having a lot of trouble figuring out. I've tried a lot of different solutions, but I can't seem to understand what the "Cannot call GetWeight() on a None object, aborting function call" or ""naguWeight.psc" Line ?" are about. I've only been working with Papyrus for a week with no prior experience in any sort of scripting or programming, so I'm very ignorant to a lot of things. Sorry for that in advance.PSThis is what the tabs in my browser look like: https://i.imgur.com/0ZyqRjY.gifvI am sincerely trying my best to figure out the answer on my own, but a lot of it is going over my head, and I'm sort of overloading myself with information lol. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 3, 2019 Share Posted August 3, 2019 SKSE adds a series of properties to the Armor script which contain the slot mask values. It may be better to create an Int array via script and assign those slot mask properties to the array entries and then cycle through those. Here is an example (not tested for compilation or function). Requires SKSE and testing on a new game or one where the quest holding the reference alias has not yet been started. Scriptname naguWeight extends ReferenceAlias GlobalVariable Property naguWeightTotal Auto Int[] SlotArray Event OnInit() SlotArray = new Int[32] SlotArray[0] = Armor.kSlotMask30 ; HEAD SlotArray[1] = Armor.kSlotMask31 ; Hair SlotArray[2] = Armor.kSlotMask32 ; BODY SlotArray[3] = Armor.kSlotMask33 ; Hands SlotArray[4] = Armor.kSlotMask34 ; Forearms SlotArray[5] = Armor.kSlotMask35 ; Amulet SlotArray[6] = Armor.kSlotMask36 ; Ring SlotArray[7] = Armor.kSlotMask37 ; Feet SlotArray[8] = Armor.kSlotMask38 ; Calves SlotArray[9] = Armor.kSlotMask39 ; SHIELD SlotArray[10] = Armor.kSlotMask40 ; TAIL SlotArray[11] = Armor.kSlotMask41 ; LongHair SlotArray[12] = Armor.kSlotMask42 ; Circlet SlotArray[13] = Armor.kSlotMask43 ; Ears SlotArray[14] = Armor.kSlotMask44 ; Unnamed SlotArray[15] = Armor.kSlotMask45 ; Unnamed SlotArray[16] = Armor.kSlotMask46 ; Unnamed SlotArray[17] = Armor.kSlotMask47 ; Unnamed SlotArray[18] = Armor.kSlotMask48 ; Unnamed SlotArray[19] = Armor.kSlotMask49 ; Unnamed SlotArray[20] = Armor.kSlotMask50 ; DecapitateHead SlotArray[21] = Armor.kSlotMask51 ; Decapitate SlotArray[22] = Armor.kSlotMask52 ; Unnamed SlotArray[23] = Armor.kSlotMask53 ; Unnamed SlotArray[24] = Armor.kSlotMask54 ; Unnamed SlotArray[25] = Armor.kSlotMask55 ; Unnamed SlotArray[26] = Armor.kSlotMask56 ; Unnamed SlotArray[27] = Armor.kSlotMask57 ; Unnamed SlotArray[28] = Armor.kSlotMask58 ; Unnamed SlotArray[29] = Armor.kSlotMask59 ; Unnamed SlotArray[30] = Armor.kSlotMask60 ; Unnamed SlotArray[31] = Armor.kSlotMask61 ; FX01 EndEvent Function WornArmorWeight() Actor PlayerRef = Game.GetPlayer() float naguWeightBase = 0.0 Int aSize = SlotArray.Length ;NOTE - last index is always 1 less than the total entries While aSize >= 0 aSize -= 1 Armor WornA = (PlayerRef.GetWornForm(SlotArray[aSize]) as Armor) Float WornAWeight = WornA.GetWeight() naguWeightBase += WornAWeight Debug.Trace("Trace: " + WornA.GetName() + " in slot " + SlotArray[aSize] + " weighs " + WornAWeight +"| TOTAL WEIGHT: " + naguWeightBase) EndWhile naguWeightTotal.SetValue(naguWeightBase) EndFunction Event OnObjectUnequipped(form akBaseObject, ObjectReference akReference) If akBaseObject as Armor ; only need to update weight if armor changes WornArmorWeight() EndIf EndEvent Event OnObjectEquipped(form akBaseObject, ObjectReference akReference) If akBaseObject as Armor ; only need to update weight if armor changes WornArmorWeight() EndIf EndEvent I have never quite understood how the slot mask system handles armor that uses more than one slot. Thus I adapted the script to include the armor's name in the trace string. That way you'll know if a piece of armor is being counted more than once due to using more than one slot. Further I separated obtaining the armor weight to its own variable so that both the current armor piece weight and the current total weight could be included in the trace string. Since both events will be using the same code, put the code into a custom function and called that. Less typing ^^ Link to comment Share on other sites More sharing options...
Arcaidus Posted August 3, 2019 Author Share Posted August 3, 2019 I got it figured out boys we did it.I was right about my interpretation of what the errors meant, so I retried a solution I attempted earlier and it worked this time. I'm fairly certain I typo'd or something when I was trying it earlier. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 3, 2019 Share Posted August 3, 2019 I got it figured out boys we did it.I was right about my interpretation of what the errors meant, so I retried a solution I attempted earlier and it worked this time. I'm fairly certain I typo'd or something when I was trying it earlier.Well, I got ninja'd big time! LOL Glad you worked it out. Link to comment Share on other sites More sharing options...
Arcaidus Posted August 3, 2019 Author Share Posted August 3, 2019 SKSE adds a series of properties to the Armor script which contain the slot mask values. It may be better to create an Int array via script and assign those slot mask properties to the array entries and then cycle through those. Here is an example (not tested for compilation or function). Requires SKSE and testing on a new game or one where the quest holding the reference alias has not yet been started. Scriptname naguWeight extends ReferenceAlias GlobalVariable Property naguWeightTotal Auto Int[] SlotArray Event OnInit() SlotArray = new Int[32] SlotArray[0] = Armor.kSlotMask30 ; HEAD SlotArray[1] = Armor.kSlotMask31 ; Hair SlotArray[2] = Armor.kSlotMask32 ; BODY SlotArray[3] = Armor.kSlotMask33 ; Hands SlotArray[4] = Armor.kSlotMask34 ; Forearms SlotArray[5] = Armor.kSlotMask35 ; Amulet SlotArray[6] = Armor.kSlotMask36 ; Ring SlotArray[7] = Armor.kSlotMask37 ; Feet SlotArray[8] = Armor.kSlotMask38 ; Calves SlotArray[9] = Armor.kSlotMask39 ; SHIELD SlotArray[10] = Armor.kSlotMask40 ; TAIL SlotArray[11] = Armor.kSlotMask41 ; LongHair SlotArray[12] = Armor.kSlotMask42 ; Circlet SlotArray[13] = Armor.kSlotMask43 ; Ears SlotArray[14] = Armor.kSlotMask44 ; Unnamed SlotArray[15] = Armor.kSlotMask45 ; Unnamed SlotArray[16] = Armor.kSlotMask46 ; Unnamed SlotArray[17] = Armor.kSlotMask47 ; Unnamed SlotArray[18] = Armor.kSlotMask48 ; Unnamed SlotArray[19] = Armor.kSlotMask49 ; Unnamed SlotArray[20] = Armor.kSlotMask50 ; DecapitateHead SlotArray[21] = Armor.kSlotMask51 ; Decapitate SlotArray[22] = Armor.kSlotMask52 ; Unnamed SlotArray[23] = Armor.kSlotMask53 ; Unnamed SlotArray[24] = Armor.kSlotMask54 ; Unnamed SlotArray[25] = Armor.kSlotMask55 ; Unnamed SlotArray[26] = Armor.kSlotMask56 ; Unnamed SlotArray[27] = Armor.kSlotMask57 ; Unnamed SlotArray[28] = Armor.kSlotMask58 ; Unnamed SlotArray[29] = Armor.kSlotMask59 ; Unnamed SlotArray[30] = Armor.kSlotMask60 ; Unnamed SlotArray[31] = Armor.kSlotMask61 ; FX01 EndEvent Function WornArmorWeight() Actor PlayerRef = Game.GetPlayer() float naguWeightBase = 0.0 Int aSize = SlotArray.Length ;NOTE - last index is always 1 less than the total entries While aSize >= 0 aSize -= 1 Armor WornA = (PlayerRef.GetWornForm(SlotArray[aSize]) as Armor) Float WornAWeight = WornA.GetWeight() naguWeightBase += WornAWeight Debug.Trace("Trace: " + WornA.GetName() + " in slot " + SlotArray[aSize] + " weighs " + WornAWeight +"| TOTAL WEIGHT: " + naguWeightBase) EndWhile naguWeightTotal.SetValue(naguWeightBase) EndFunction Event OnObjectUnequipped(form akBaseObject, ObjectReference akReference) If akBaseObject as Armor ; only need to update weight if armor changes WornArmorWeight() EndIf EndEvent Event OnObjectEquipped(form akBaseObject, ObjectReference akReference) If akBaseObject as Armor ; only need to update weight if armor changes WornArmorWeight() EndIf EndEvent I have never quite understood how the slot mask system handles armor that uses more than one slot. Thus I adapted the script to include the armor's name in the trace string. That way you'll know if a piece of armor is being counted more than once due to using more than one slot. Further I separated obtaining the armor weight to its own variable so that both the current armor piece weight and the current total weight could be included in the trace string. Since both events will be using the same code, put the code into a custom function and called that. Less typing ^^ Lmao I replied literally the second you did, I'm sorry if my last post appeared to be ignoring you - I didn't mean to.Thanks a ton for showing me how I could apply arrays to my mod. I haven't learned about them yet because I feel like I'm struggling so much just getting a lot of functions to interact with plain variables and properties, but I might jump into them since that seems more efficient. Link to comment Share on other sites More sharing options...
Arcaidus Posted August 3, 2019 Author Share Posted August 3, 2019 I got it figured out boys we did it.I was right about my interpretation of what the errors meant, so I retried a solution I attempted earlier and it worked this time. I'm fairly certain I typo'd or something when I was trying it earlier.Well, I got ninja'd big time! LOL Glad you worked it out. We've got to stop responding like this lmao Link to comment Share on other sites More sharing options...
Recommended Posts