Hello all
I have been trying to set a carry cap to containers. I searched some forums and I got to this script eventually:
ScriptName ContainerMaxCarryWeight Extends ObjectReferenceFloat fCurrentWeightFloat Property fMaxWeight = 420.0 AutoEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Float fWeight = akBaseItem.GetWeight() If aiItemCount > 1 Float fWeightTotal = fWeight * aiItemCount If fCurrentWeight + fWeightTotal > fMaxWeight Int iCount = aiItemCount While iCount iCount -= 1 If fCurrentWeight + fWeight > fMaxWeight RemoveItem(akBaseItem, iCount + 1, False, akSourceContainer) Debug.Notification("The " + GetBaseObject().GetName() + " is full. (Current weight: " + fCurrentWeight + ")") Return Else fCurrentWeight += fWeight EndIf EndWhile Else fCurrentWeight += fWeightTotal EndIf ElseIf fCurrentWeight + fWeight < fMaxWeight fCurrentWeight += fWeight Else RemoveItem(akBaseItem, 1, False, akSourceContainer) Debug.Notification("The " + GetBaseObject().GetName() + " is full. (Current weight: " + fCurrentWeight + ")") EndIfEndEvent
(-> Properties: fMaxWeight = 1000)
I'm not an expert at scripting. I only know a few basics. I just found this script on the forums, and changed a few lines, but it doesn't seem work properly.
When the container already has close to 1000 current carry weight and I deposit an item which makes it go over the cap, I want it to do the following:
- Return the item to my inventory.
- Display a message:" The
is full. (Current weight: )". ( should be like "750" though, not "750.00000000", without any decimals)
I'm having the following issue though:
Basically, when I put a stack of multiple items into the container and that makes it go over the cap, the whole stack of items will still go in there and nothing will be returned to my inventory.
- For instance: Let's say I have 90 Dragon Bones (10 Weight each) and 10 Dragon Scales (15 Weight each).
- The cap is set at 1000 carry weight.
- First, I deposit 90 Dragon Bones (= 900 carry weight), so far so good.
- Then, I deposit the 10 Dragon Scales (= 150 carry weight), which brings the total current carry weight of the container to 1050. (900 + 150)
- Instead of returning 4 Dragon Scales (= 60 weight, 1050 - 60 = 990 -> below the cap) to my inventory, I keeps all 10 without returning any. It only displays the message: "The Chest is full (Current weight: 1000.00000000)" This is obviously a bug. (
should also be like "1000" though, not "1000.00000000", without any decimals) - If I deposit anything now, it automatically returns it to my inventory and displays the message. This is intended since the current carry weight is still 1050, so it is supposed to return it.
- If I take all the Dragon Scales and Dragon Bones back to my inventory (which brings the current container weight to 0), it still displays the message and returns everything regardless of the current carry weight. This is a bug again.
Is there any way to fix this? Anything wrong with the script? All advice is welcome.
Thanks in advance
Kind regards
Andre