Jump to content

Changing Weight on all items of a specific type?


Recommended Posts

Is there any way to dynamically change the weight of all objects of a certain type without having to go manually change each individual form? Say like (as an example) changing the weight of all items of the ammo type? Something that would work if mods add more of this type of object to the game.

Link to comment
Share on other sites

An in-game method?

 

Create a quest with a player alias

Add a script to the player alias

The script will use the OnPlayerLoadGameEvent to re-set the weight of previously set items

The script will use the OnItemAdded event to listen for the desired items and change their weight if not already changed

The script will store modified items in an originally empty formlist so they can be re-set easier.

Finally, the script will use SetWeight to actually change the weight.

This process will require SKSE

 

Drawback to this method: The lack of an inventory event filter will cause this script to run for EVERY item added to the player inventory. This means that it could contribute to an overall stack dump should there be a lot of scripts running that do not have inventory event filters. Especially when large groups of items are transferred at once.

 

The script would look something like:

 

 

Scriptname SomeScript Extends ReferenceAlias
 
Formlist Property myItemList Auto
Float Property newWeight Auto
 
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If akBaseItem as Ammo ; is this the object type that we want?
    If !(myItemList.HasForm(akBaseItem)) ;is the object on the formlist?
      myItemList.AddForm(akBaseItem) ; add to list
      akBaseItem.SetWeight(newWeight)
    EndIf
  EndIf
EndEvent
 
Event OnPlayerLoadGame()
  Int idx = myItemList.GetSize() - 1
  While idx >= 0
    Form Entry = myItemList.GetAt(idx)
    Entry.SetWeight(newWeight)
    idx -= 1
  EndWhile
EndEvent

 

 

 

Outside of game?

 

A script that can be run in SSEEdit could be created to run through all active plugins and change the weight of the desired item type.

Drawback to this method: The end user would be required to run it on their game, else nothing gets changed.

Link to comment
Share on other sites

An in-game method?

 

Create a quest with a player alias

Add a script to the player alias

The script will use the OnPlayerLoadGameEvent to re-set the weight of previously set items

The script will use the OnItemAdded event to listen for the desired items and change their weight if not already changed

The script will store modified items in an originally empty formlist so they can be re-set easier.

Finally, the script will use SetWeight to actually change the weight.

This process will require SKSE

 

Drawback to this method: The lack of an inventory event filter will cause this script to run for EVERY item added to the player inventory. This means that it could contribute to an overall stack dump should there be a lot of scripts running that do not have inventory event filters. Especially when large groups of items are transferred at once.

 

The script would look something like:

 

 

Scriptname SomeScript Extends ReferenceAlias
 
Formlist Property myItemList Auto
Float Property newWeight Auto
 
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If akBaseItem as Ammo ; is this the object type that we want?
    If !(myItemList.HasForm(akBaseItem)) ;is the object on the formlist?
      myItemList.AddForm(akBaseItem) ; add to list
      akBaseItem.SetWeight(newWeight)
    EndIf
  EndIf
EndEvent
 
Event OnPlayerLoadGame()
  Int idx = myItemList.GetSize() - 1
  While idx >= 0
    Form Entry = myItemList.GetAt(idx)
    Entry.SetWeight(newWeight)
    idx -= 1
  EndWhile
EndEvent

 

 

 

Outside of game?

 

A script that can be run in SSEEdit could be created to run through all active plugins and change the weight of the desired item type.

Drawback to this method: The end user would be required to run it on their game, else nothing gets changed.

 

Thanks, I'm gonna try the in-game method

Link to comment
Share on other sites

Additional to IsharaMeradins posting I would suggest some minor changes in scripting.

 

tbGuyItemWeightPlayerAliasScript

 

Scriptname tbGuyItemWeightPlayerAliasScript extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/10102303-changing-weight-on-all-items-of-a-specific-type/
 
  Formlist PROPERTY myList  auto        ; Mandatory!! you have to create a new formlist with CK, and assign to this property
  Float    PROPERTY fWeight auto        ; [default=0.0]


; -- EVENTs --

EVENT OnInit()
    Debug.Trace(" OnInit() - has been called for " +self)        ; see "papyrus.0.log"
    IF (SKSE.GetVersion() > 0)
        gotoState("Waiting")     ; ### STATE ###
    ENDIF
ENDEVENT

EVENT OnPlayerLoadGame()
IF (SKSE.GetVersion() > 0)
    gotoState("Waiting")         ; ### STATE ###
ELSE
    gotoState("")                ; ### STATE ###
    RETURN    ; - STOP -
ENDIF
;-----------------------
int i = myList.GetSize()
    WHILE (i)                    ; (i != 0)
        i = i - 1
        form fm = myList.GetAt(i)
        IF (fm as Ammo)                        ; safety net
            fm.SetWeight( fWeight )
        ENDIF
    ENDWHILE
ENDEVENT


EVENT OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    ; no action here, missing SKSE!
ENDEVENT

;=======================
state Waiting    ; SKSE
;============
EVENT OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
IF (aiItemCount < 3)
    RETURN    ; - STOP -    if player adds minor than three arrows for example, finish immediately
ENDIF
;---------------------
IF (akBaseItem as Ammo)
ELSE
    RETURN    ; - STOP -    short circuit, no ammo here
ENDIF
;---------------------
; https://www.creationkit.com/index.php?title=SetWeight_-_Form

    IF myList.HasForm(akBaseItem)
        ; already in our list
    ELSE
        myList.AddForm(akBaseItem)            ; add to list
        akBaseItem.SetWeight( fWeight )       ; change weight of this ammo
    ENDIF
ENDEVENT
;=======
endState

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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