senterpat Posted August 12 Share Posted August 12 Hello, so I'm trying to make the items added with a script to a ships cargo hold show up in the top right corner as they normally would if adding directly to the player. I've added a inventory filter to a container the items are moved to when looted. And then I add the items to the player, then immediately remove them and place in the ships cargo. But I'm having issues with the process showing items in the players inventory after the process is done, as well as it not running quite as fast as I would like, and sometimes items left in the temporary container. So is there a better way to do this? I'm not too adept at scripting, so I may be doing it in a dumb way. ScriptName Test_ItemDisplayScript Extends ObjectReference ObjectReference Property TempContainer auto Formlist Property TempFormlist Auto SQ_PlayerShipScript Property SQ_PlayerShip auto const mandatory Event OnInit() AddInventoryEventFilter(None) EndEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer, int aiTransferReason) TempFormlist.AddForm(akBaseItem) Process() EndEvent Function Process() debug.notification("processing") Int iIndex = TempFormlist.GetSize() While iIndex > 0 Form iForm = TempFormlist.GetAt(iIndex) int iCount = TempContainer.GetItemCount(iForm) game.getplayer().additem(iForm, iCount, False) SQ_PlayerShip.PlayerShip.GetRef().AddItem(iForm, iCount, False) game.getplayer().removeitem(iForm, iCount, True) TempContainer.removeitem(iForm, iCount, True) if TempContainer.GetItemCount(iForm) == 0 TempFormlist.RemoveAddedForm(iForm) endif iIndex -= 1 EndWhile if TempFormlist.GetSize() > 0 Process() endif EndFunction Link to comment Share on other sites More sharing options...
Evangela Posted August 18 Share Posted August 18 (edited) Use arrays because they're faster than formlists. Prepping for that will be annoying because you can't drag and drop forms into an array property like you can with a formlist. Secondly GetItemCount isn't really fast either because it's basically a loop that returns the number of each item. Change Game.GetPlayer() to the much faster PlayerRef actor property, or store Game.GetPlayer() to a variable and do all of that outside of the loop. GetPlayer() is (if it holds up in Starfield) is 1000x slower than the actor property. Overall it is a bit slow due to multiple calls to the same functions. AddItem x2 x how much iterations it has to do. Same thing with RemoveItem and GetItemCount. Double calls inside a loop. Edited August 18 by Evangela Link to comment Share on other sites More sharing options...
Recommended Posts