Jump to content

[LE] [Script]RemoveAllItems with exception those are worn/equipped


anb2004

Recommended Posts

Hi

 

Basically a very first stage for auto sorting stuff, putting all player items into specific container that already has auto sorting script after activate something. The only addition that would be great is, how to make worn/equipped armor & weapon is not affected by it, so player just don't go...well u know the situation is. Anyone care to show how to code that ?

 

 

Scriptname _ATS_Master extends ObjectReference

Message Property _MSG_Stored auto

ObjectReference Property _Cont_AutoSortChest auto

Event OnActivate(ObjectReference akActor)
; MSG_Stored.show()
If akActor == Game.GetPlayer()
Game.GetPlayer().RemoveAllItems(_Cont_AutoSortChest)
endif
endEvent

 

 

Novice scripter here, any help will be appreciated

Link to comment
Share on other sites

Do not use RemoveAllItems. Instead build formlists of objects that you want sorted to the different containers. Then loop through those lists checking each object to ensure that it is not equipped or a favorite prior to removing it. Problem, it is extremely slow.

 

Here is a function I made for my Inventory Management System mod that included the process described above. It is commented out because it is extremely slow and I did not want something that took a long time to process. At least it gives you an idea.

 

 

Function SortOut(Int index)
; this method is faster to sort out, but cannot include weapons and armor in the lists
	FormList MasterList = (abim_IMS_MasterItemList.GetAt(index) as FormList)
	int q = PlayerRef.GetItemCount(MasterList)
	If q > 0
		PlayerRef.RemoveItem(MasterList,q,true,(abim_IMS_ModContainers.GetAt(index) as ObjectReference))
	EndIf
; this method is slower to sort out, but can include weapons and armor in the lists
;	FormList MasterList = (abim_IMS_MasterItemList.GetAt(index) as FormList)
;	int s = MasterList.GetSize() - 1
;	While s >= 0
;		Form Entry = MasterList.GetAt(s)
;		Int q = PlayerRef.GetItemCount(Entry)
;		If Entry as Weapon || Entry as Armor
;			If !(PlayerRef.IsEquipped(Entry)) && !(Game.IsObjectFavorited(Entry))
;				PlayerRef.RemoveItem(Entry,q,true,(abim_IMS_ModContainers.GetAt(index) as ObjectReference))
;			EndIf
;		Else
;			PlayerRef.RemoveItem(Entry,q,true,(abim_IMS_ModContainers.GetAt(index) as ObjectReference))
;		EndIf
;		s -= 1
;	EndWhile
EndFunction

Please note that this only cycled through ONE formlist per call of the SortOut function. The function itself was called multiple times as the master formlist was cycled through in a separate function. The larger the formlists involved, the longer it will take.

 

May require SKSE for the IsObjectFavorited function.

 

 

Link to comment
Share on other sites

Do not use RemoveAllItems.

 

Yeah, realize RemoveAllItems is a bad idea, tested with new player with few items in inventory is ggreat but with items more than 50+ is like having a system freeze.

 

Instead build formlists of objects that you want sorted to the different containers. Then loop through those lists checking each object to ensure that it is not equipped or a favorite prior to removing it.

 

That's the thing, i want to avoid using formlist if possible because it kind of "limited", it also the reason i set up a trigger on activate to take all player items into a container than another trigger to sort all the items inside it (same as Jaggarfeld did).

 

Planning to release a player home with auto sorting function. My main goal for the auto sorting is by having a single activator (like leaf rest did) that can check all player items for every each akbaseitem and base keyword than take all items and stored them into each assigned container without using formlist and leave equipped items untouch (so any added/modded items can work as well and of course they were set with appropriate keyword).

 

Believe i've tested any auto sorting mod and i found 2 type of mechanism :

- Auto sort by dropping the item into a container (base on keyword : Jaggarsfeld)

- Auto sort by activate something (base on formlist : Leaf Rest )

 

I know it's like i'm asking for more, more and more especially with my limited coding skill but's it worth a try. Anyway thanks for sharing your codes, i'll see if i can tweak it as i want it.

 

Thanks

Link to comment
Share on other sites

Hey, if you don't mind using SKSE, you could use Player.GetNumItems() and Player.GetNthForm. Something like this:

 

 

 

ObjectReference Property _Cont_AutoSortChest auto
Actor Property pPlayerRef auto

Function RemoveItems()
    Int M = pPlayerRef.GetNumItems()
    While M > 0
        M -= 1
        Form Item = pPlayerRef.GetNthForm(M)
        If pPlayerRef.IsEquipped(Item) == false && Game.IsObjectFavorited(Item) == false
            pPlayerRef.RemoveItem(Item, pPlayerRef.GetItemCount(Item), True, _Cont_AutoSortChest)
        Endif 
    EndWhile
EndFunction

 

 

 

Edited by dylbill
Link to comment
Share on other sites

  • Recently Browsing   0 members

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