Add a maximum weight capacity to containers

Post » Wed Jun 20, 2012 6:25 am

Just wondering if its possible to add a maximum weight capacity setting to a container? This way you would only be able to put a certain number of items in the container before it cant hold anymore (like maximum weight for the PC).

:biggrin: :ermm:
User avatar
GRAEME
 
Posts: 3363
Joined: Sat May 19, 2007 2:48 am

Post » Wed Jun 20, 2012 3:57 pm

there is a weight property to containers yes, I'm pretty sure if it's 0 it's unlimited, if it's anything higher, that's the limit.
User avatar
Phillip Brunyee
 
Posts: 3510
Joined: Tue Jul 31, 2007 7:43 pm

Post » Wed Jun 20, 2012 6:27 am

there is a weight property to containers yes, I'm pretty sure if it's 0 it's unlimited, if it's anything higher, that's the limit.

I think thats the weight of the actual container, I tested it once and the weight limit of the container was still unlimited.

:blink:
User avatar
CYCO JO-NATE
 
Posts: 3431
Joined: Fri Sep 21, 2007 12:41 pm

Post » Wed Jun 20, 2012 9:46 am

You could make FormLists of items according to their weight, derive the cumulative weight with a custom function, then check if the weight limit is exceeded OnItemAdded() style and have the container refuse new items until enough weight is removed...

Spoiler
ScriptName ContainerWeightScript extends ObjectReferenceFloat fWeightFormList Property FormListOfFormListsFLST Auto ; Has all the others in itFormList Property HalfPoundFLST AutoFormList Property OnePoundFLST AutoFormList Property TwoPoundFLST AutoFormList Property ThreePoundFLST AutoFormList Property FourPoundFLST AutoFormList Property FivePoundFLST AutoFormList Property TenPoundFLST AutoEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	fWeight = GetContainerWeight(Self)		If (fWeight > 9000)		RemoveItem(akBaseItem, 1, True, akSourceContainer)		Debug.MessageBox("This thing is stuffed! Remove items to make room.")	EndIf	EndEvent;===============================================Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)	fWeight = GetContainerWeight(Self)		If (fWeight > 9000)		If HalfPoundFLST.HasForm(akBaseItem)			fWeight -= 0.5		ElseIf OnePoundFLST.HasForm(akBaseItem)			fWeight -= 1		ElseIf TwoPoundFLST.HasForm(akBaseItem)			fWeight -= 2		ElseIf ThreePoundFLST.HasForm(akBaseItem)			fWeight -= 3		ElseIf FourPoundFLST.HasForm(akBaseItem)			fWeight -= 4		ElseIf FivePoundFLST.HasForm(akBaseItem)			fWeight -= 5		ElseIf TenPoundFLST.HasForm(akBaseItem)			fWeight -= 6		EndIf	EndIfEndEvent;===============================================Float Function GetContainerWeight(ObjectReference akContainer = None, FormList akFormList = None, Int aiIndex = 0, Int aiCount = 0)	fWeight = 0	aiIndex = (FormListOfFormListsFLST.GetSize() - 1)		While (aiIndex > -1)		akFormList = FormListOfFormListsFLST.GetAt(aiIndex) As FormList		aiCount = akContainer.GetItemCount(akFormList)		If (aiIndex == 6) ; 10 'pound' items			fWeight += (aiCount * 10) As Float		ElseIf (aiIndex == 5) ; 5 'pound' items			fWeight += (aiCount * 5) As Float		ElseIf (aiIndex == 4) ; 4 'pound' items			fWeight += (aiCount * 4) As Float		ElseIf (aiIndex == 3) ; 3 'pound' items			fWeight += (aiCount * 3) As Float		ElseIf (aiIndex == 2) ; 2 'pound' items			fWeight += (aiCount * 2) As Float		ElseIf (aiIndex == 1) ; 1 'pound' items			fWeight += (aiCount * 1.0) As Float		ElseIf (aiIndex == 0) ; .5 'pound' items			fWeight += (aiCount * 0.5) As Float		EndIf		aiIndex -= 1	EndWhile	Return fWeightEndFunction

Haven't tested the above, but it should work with some finagling...
User avatar
Katharine Newton
 
Posts: 3318
Joined: Tue Jun 13, 2006 12:33 pm

Post » Wed Jun 20, 2012 5:19 pm

You could make FormLists of items according to their weight, derive the cumulative weight with a custom function, then check if the weight limit is exceeded OnItemAdded() style and have the container refuse new items until enough weight is removed...

Spoiler
ScriptName ContainerWeightScript extends ObjectReferenceFloat fWeightFormList Property FormListOfFormListsFLST Auto ; Has all the others in itFormList Property HalfPoundFLST AutoFormList Property OnePoundFLST AutoFormList Property TwoPoundFLST AutoFormList Property ThreePoundFLST AutoFormList Property FourPoundFLST AutoFormList Property FivePoundFLST AutoFormList Property TenPoundFLST AutoEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	fWeight = GetContainerWeight(Self)		If (fWeight > 9000)		RemoveItem(akBaseItem, 1, True, akSourceContainer)		Debug.MessageBox("This thing is stuffed! Remove items to make room.")	EndIf	EndEvent;===============================================Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)	fWeight = GetContainerWeight(Self)		If (fWeight > 9000)		If HalfPoundFLST.HasForm(akBaseItem)			fWeight -= 0.5		ElseIf OnePoundFLST.HasForm(akBaseItem)			fWeight -= 1		ElseIf TwoPoundFLST.HasForm(akBaseItem)			fWeight -= 2		ElseIf ThreePoundFLST.HasForm(akBaseItem)			fWeight -= 3		ElseIf FourPoundFLST.HasForm(akBaseItem)			fWeight -= 4		ElseIf FivePoundFLST.HasForm(akBaseItem)			fWeight -= 5		ElseIf TenPoundFLST.HasForm(akBaseItem)			fWeight -= 6		EndIf	EndIfEndEvent;===============================================Float Function GetContainerWeight(ObjectReference akContainer = None, FormList akFormList = None, Int aiIndex = 0, Int aiCount = 0)	fWeight = 0	aiIndex = (FormListOfFormListsFLST.GetSize() - 1)		While (aiIndex > -1)		akFormList = FormListOfFormListsFLST.GetAt(aiIndex) As FormList		aiCount = akContainer.GetItemCount(akFormList)		If (aiIndex == 6) ; 10 'pound' items			fWeight += (aiCount * 10) As Float		ElseIf (aiIndex == 5) ; 5 'pound' items			fWeight += (aiCount * 5) As Float		ElseIf (aiIndex == 4) ; 4 'pound' items			fWeight += (aiCount * 4) As Float		ElseIf (aiIndex == 3) ; 3 'pound' items			fWeight += (aiCount * 3) As Float		ElseIf (aiIndex == 2) ; 2 'pound' items			fWeight += (aiCount * 2) As Float		ElseIf (aiIndex == 1) ; 1 'pound' items			fWeight += (aiCount * 1.0) As Float		ElseIf (aiIndex == 0) ; .5 'pound' items			fWeight += (aiCount * 0.5) As Float		EndIf		aiIndex -= 1	EndWhile	Return fWeightEndFunction

Haven't tested the above, but it should work with some finagling...

Or I could just use an NPC as the "container" which i just realised I could do.

:dry:
User avatar
jasminε
 
Posts: 3511
Joined: Mon Jan 29, 2007 4:12 am


Return to V - Skyrim