MacManChomp Posted August 22, 2012 Share Posted August 22, 2012 With some work I have managed to get very close to having a working script to sort items from player inventory to containers. It seems that the only way to accomplish this goal though is through a very long script. For Example: ObjectReference Property IronIngot Auto ObjectReference Property Container Auto int iCount Event OnActivate (ObjectReference akActionRef) iCount = Game.GetPLayer(),GetItemCount(IronIngot) Game.GetPlayer().RemoveItem(IronIngot, num, true) Container.Additem(IronIngot, num, true) endEvent you would have to do this for every item you wanted the chest to handle. I don't have the time to do this. I am looking for a way to move the items (so far only MiscObject with the use of a FormList. Something more like Scriptname CSItemSorting extends ObjectReference {An item sorting script to move player inventory into chests. (hope this works out..... )} Int iIndex Int iReference ObjectReference Reference ObjectReference Property Landing Auto FormList Property ListOfObjectsFLST Auto Message Property ActivateMSG Auto Message Property FailedMSG Auto Int Button Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Button = ActivateMSG.show() If Button == 0 iIndex = ListOfObjectsFLST.GetSize() ; Indices are offset by 1 relative to size While(iIndex > 0) iIndex -= 1 Debug.Trace("Form " + iIndex + " is " + ListOfObjectsFLST.GetAt(iIndex)) Reference = ListOfObjectsFLST.GetAt(iIndex) as ObjectReference ; Note that you must typecast the entry from the formlist using 'As'. Debug.Trace("Reference is " + Reference); Trace the output of the ObjectReference Reference, currently only returns none!!! Debug.Trace("FormID is " + Reference.GetFormID()) iReference = Reference.GetItemCount(Reference) Debug.Trace("iReference is " + iReference) If Game.GetPlayer().GetItemCount(Reference) >= 1 Game.GetPlayer().RemoveItem(Reference, iReference, true) Landing.AddItem(Reference, iReference, true) EndIf EndWhile EndIf EndIf EndEvent The upsetting part is that even though this SHOULD work, it does not. The line Debug.Trace("Form " + iIndex + " is " + ListOfObjectsFLST.GetAt(iIndex))is outputting [08/21/2012 - 04:17:11PM] Form 1 is [MiscObject < (000DB8A2)>]And using a MiscObject instead of an ObjectReference does not compile. The above script will compile and will run, asking you if you want to add your ingots to the chest and regardless of choice continue to open the chest. (I have it attached to the container for now, plans are for buttons or maybe a magical wall of buttons to move items into respective chests.) Link to comment Share on other sites More sharing options...
MacManChomp Posted August 22, 2012 Author Share Posted August 22, 2012 UPDATE: A little more trial and error got me so far as to get this read-out: [08/21/2012 - 06:16:18PM] Form 9 is [MiscObject < (0005ACE5)>] [08/21/2012 - 06:16:19PM] Item is [MiscObject < (0005ACE5)>] [08/21/2012 - 06:16:19PM] FormID is 371941 [08/21/2012 - 06:16:19PM] Form 8 is [MiscObject < (0005ACE3)>] [08/21/2012 - 06:16:19PM] Item is [MiscObject < (0005ACE3)>] [08/21/2012 - 06:16:19PM] FormID is 371939 [08/21/2012 - 06:16:19PM] Form 7 is [Form < (0005ADA0)>] [08/21/2012 - 06:16:19PM] Item is [Form < (0005ADA0)>] [08/21/2012 - 06:16:19PM] FormID is 372128 [08/21/2012 - 06:16:19PM] Form 6 is [Form < (0005AD99)>] with this script: Scriptname CSItemSorting extends ObjectReference {An item sorting script to move player inventory into chests. (hope this works out..... )} Int iIndex Int iReference ObjectReference Reference ObjectReference Property Landing Auto FormList Property ListOfObjectsFLST Auto Message Property ActivateMSG Auto Message Property FailedMSG Auto Int Button Form Item Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Button = ActivateMSG.show() If Button == 0 iIndex = ListOfObjectsFLST.GetSize() ; Indices are offset by 1 relative to size While(iIndex > 0) iIndex -= 1 Debug.Trace("Form " + iIndex + " is " + ListOfObjectsFLST.GetAt(iIndex)) Item = ListOfObjectsFLST.GetAt(iIndex) ; Note that you must typecast the entry from the formlist using 'As'. Debug.Trace("Item is " + Item) Debug.Trace("FormID is " + Item.GetFormID()) If Game.GetPlayer().GetItemCount(Item) >= 1 iReference = Game.GetPlayer().GetItemCount(Item) Game.GetPlayer().RemoveItem(Item, iReference, true) Landing.AddItem(Item, iReference, true) EndIf EndWhile EndIf EndIf EndEvent as you can see there are no errors, but the items are not removed from my inventory or added to the container. Maybe I am doing something wrong? It seems as though I have made good progress and the script looks good to me, but I am certain I am missing something. Link to comment Share on other sites More sharing options...
MacManChomp Posted August 22, 2012 Author Share Posted August 22, 2012 Yet another update... Starting to feel stupid.with the addition of tracing the item count, I am finding that it counts none on the player! There must be another way, as I have worked on this too much to just give up because Papyrus doesn't allow me to check for the item associated with a form on the player. Link to comment Share on other sites More sharing options...
steve40 Posted August 22, 2012 Share Posted August 22, 2012 With some work I have managed to get very close to having a working script to sort items from player inventory to containers. It seems that the only way to accomplish this goal though is through a very long script. The line iReference = Reference.GetItemCount(Reference) should be iReference = Game.GetPlayer().GetItemCount(Reference) Link to comment Share on other sites More sharing options...
MacManChomp Posted August 22, 2012 Author Share Posted August 22, 2012 (edited) Yeah thanks I already fixed that, sorry about the stupid mistakes. in my most recent build I am finding that object references are required to add or remove an item but not obtainable from the forms. To be expected, but I need to find a way to get the references of all of these items. Is there a way that I could do something more like a addform with a blank form to populate the entire form with viable object references? I have this right now: Scriptname CSItemSorting extends ObjectReference {An item sorting script to move player inventory into chests. (hope this works out..... )} Int iIndex Int iReference ObjectReference Reference ObjectReference Property Landing Auto FormList Property ListOfObjectsFLST Auto Message Property ActivateMSG Auto Message Property FailedMSG Auto Int Button Form Item Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Button = ActivateMSG.show() If Button == 0 iIndex = ListOfObjectsFLST.GetSize() ; Indices are offset by 1 relative to size While(iIndex > 0) iIndex -= 1 Debug.Trace("Form " + iIndex + " is " + ListOfObjectsFLST.GetAt(iIndex)) Item = ListOfObjectsFLST.GetAt(iIndex) ; Note that you must typecast the entry from the formlist using 'As'. Debug.Trace("Item is " + Item) Debug.Trace("FormID is " + Item.GetFormID()) Debug.Trace(" Item count is " + Game.GetPlayer().GetItemCount(Item)) Debug.Trace("Reference = " +Reference) If Game.GetPlayer().GetItemCount(Item) >= 1 Debug.Trace("player has enough items of " + Item + ": " + Game.GetPlayer().GetItemCount(Item)) iReference = Game.GetPlayer().GetItemCount(Item) Game.GetPlayer().RemoveItem(Item, iReference, false) Landing.AddItem(Item, iReference, false) EndIf EndWhile EndIf EndIf EndEvent still in the middle of some extensive reworking as the debug file is always showing a count of 0 on the player. Is there maybe a way to add these items to the player and remove them from the player without having to get rid of the formlist? the debug output is aggravating me and I can't seem to Incorporate the skse functions into my script like GetName() and such. It just fails to compile and I cannot find any information on how to use the skse functions.... *pulling my hear out here* Edited August 22, 2012 by MacManChomp Link to comment Share on other sites More sharing options...
steve40 Posted August 22, 2012 Share Posted August 22, 2012 Afaik, it should work with Forms, not just ObjectReferences: "If a base object (like armor or a weapon), it will count the how many instances of that base object are in the container", otherwise what's the use? :biggrin: Just cleaning up the script a bit. I don't have a compiler handy so I can't test anything until tonight. Scriptname CSItemSorting extends ObjectReference {An item sorting script to move player inventory into chests.} Int iIndex Int iCount Int Button ObjectReference Reference ObjectReference Property Landing Auto FormList Property ListOfObjectsFLST Auto Form Item Message Property ActivateMSG Auto Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Button = ActivateMSG.show() If Button == 0 iIndex = ListOfObjectsFLST.GetSize() While(iIndex > 0) iIndex -= 1 Item = ListOfObjectsFLST.GetAt(iIndex) iCount = akActionRef.GetItemCount(Item) Debug.Trace("[CSItemSorting]Item = " + Item + ", iCount = " + iCount) If iCount > 0 akActionRef.RemoveItem(Item, iCount, true) Landing.AddItem(Item, iCount, true) EndIf EndWhile EndIf EndIf EndEvent Link to comment Share on other sites More sharing options...
MacManChomp Posted August 22, 2012 Author Share Posted August 22, 2012 (edited) success!!!! Though the values are wrong! For some reason it missed the Iron Ingot (I don't know why, looking into it now!) But I have successfully removed a selection of ingots from my inventory and moved them into the container!Edit: I forgot the Iron Ingot on the form list >.> but it seems that everything works now, thank you for the help! I will continue to make more scripts for use with other types of items such as weapons, soulgems and more. Edited August 22, 2012 by MacManChomp Link to comment Share on other sites More sharing options...
steve40 Posted August 22, 2012 Share Posted August 22, 2012 Cool. Link to comment Share on other sites More sharing options...
Ez0n3 Posted August 22, 2012 Share Posted August 22, 2012 Tinkering on something similar. Maybe something like this:Scriptname CSItemSorting extends ObjectReference {An item sorting script to move player inventory into chests.} ObjectReference Property Landing Auto FormList Property ListOfObjectsFLST Auto Message Property ActivateMSG Auto Message Property FailedMSG Auto Event OnActivate(ObjectReference akActionRef) If (akActionRef == Game.GetPlayer()) Int iButton = ActivateMSG.show() If (iButton == 0) Int iIndex = ListOfObjectsFLST.GetSize() - 1 Form Item = ListOfObjectsFLST.GetAt(iIndex) as Form While(Item as Form) Debug.Trace("Form " + iIndex + " is " + Item) Int iCount = akActionRef.GetItemCount(Item) If (iCount > 0) akActionRef.RemoveItem(Item, iCount, true, Landing) EndIf iIndex -= 1 Item = ListOfObjectsFLST.GetAt(iIndex) as Form EndWhile EndIf EndIf EndEvent Link to comment Share on other sites More sharing options...
MacManChomp Posted August 22, 2012 Author Share Posted August 22, 2012 Current is working perfect! Nice and cleaned up thanks to tips from steve40!and thank you en0z3! Link to comment Share on other sites More sharing options...
Recommended Posts