dizietemblesssma Posted May 29, 2022 Share Posted May 29, 2022 Is there a code snippet that I can be pointed at that will help me identify duplicate items in a container? I don't want to reinvent the wheel, but I don't want anyone else to either, so only already existing code:)I'm looking to go through a container full of books and remove duplicates back to another container or the player. diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 29, 2022 Share Posted May 29, 2022 (edited) With a script on the container we can remove excess items as added when there is already at least one present. Non-SKSESome sort of trigger (hotkey, spell or activator object) with a script attached could be used to scan the container's items and remove extra down to one remaining. Definitely SKSE. As far as existing code, pretty sure there is similar stuff but I do not know of anything that would specifically match up to what you want. No wheel reinventing going on but rather figuring out how many spokes you want and how far apart to space them... EDIT: There would be a non-SKSE way to do the second idea but it requires a "hack" by using a second container using the first idea and a stack dump potential transfer of all items from the first container into the second and using that second container to send back just one of each object. Edited May 29, 2022 by IsharaMeradin Link to comment Share on other sites More sharing options...
dizietemblesssma Posted May 30, 2022 Author Share Posted May 30, 2022 Using SKSE, I have the following so far: ScriptName dz_move_duplicates_script Extends ObjectReference Actor Property PlayerRef Auto Event OnActivate(ObjectReference akItemRef) ;akItemRef will be a container dz_move_dupes(akItemRef, PlayerRef) EndEvent Function dz_move_dupes(ObjectReference oldcontainer, ObjectReference newcontainer) Int NumItems = oldcontainer.GetNumItems() ;number of items in container While NumItems > 0 ;for each item... NumItems -= 1 Form Item = GetNthForm(NumItems) Int ItemCount = GetItemCount(Item) ;...get the number(count) of that item If ItemCount > 1 ;if there are duplicates... Int newItemCount = ItemCount - 1 ;...how many to remove oldcontainer.RemoveItem(Item, newItemCount, False, newContainer) EndIf EndWhile EndFunction I envisage a hotkey activation on a container so the event part will change as this will possibly become part of a larger MCM menu script.My use case in mind is a collection of books, so items that are tempered and or enchanted wouldn't be an issue, so do I need more? diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 30, 2022 Share Posted May 30, 2022 That looks like it would do the job. Shouldn't need anything else for books. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted May 30, 2022 Author Share Posted May 30, 2022 Thankyou, diziet Link to comment Share on other sites More sharing options...
dizietemblesssma Posted May 31, 2022 Author Share Posted May 31, 2022 Anyone reading this, I made a mistake in the script, the two lines:Form Item = GetNthForm(NumItems) Int ItemCount = GetItemCount(Item) should read:Form Item = oldcontainer.GetNthForm(NumItems) Int ItemCount = oldcontainer.GetItemCount(Item) I didn't notice because it compiled! diziet Link to comment Share on other sites More sharing options...
Recommended Posts