py6upouq Posted October 4, 2012 Share Posted October 4, 2012 Hello everyone, need some help with scripting: How to define when certain object was placed in container and in what quantity and then how to replace these objects by other objects in same quantity and transfer them to the another container (perhaps in another cell or world).Thanks in advance! Link to comment Share on other sites More sharing options...
LtMattmoo Posted October 4, 2012 Share Posted October 4, 2012 Clarify for me: You want a script which runs when a specific object (X) is placed into a specific container (A). You want this script to work out what quantity of object X was added then remove all of these objects and replace them with that same quantity of a different specific object (Y). You then want all of the object Y to be moved from container A and placed into another specific container. Is that right? Link to comment Share on other sites More sharing options...
py6upouq Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) Clarify for me: You want a script which runs when a specific object (X) is placed into a specific container (A). You want this script to work out what quantity of object X was added then remove all of these objects and replace them with that same quantity of a different specific object (Y). You then want all of the object Y to be moved from container A and placed into another specific container. Is that right?Precicely, but I don't know functions. At least can you specify the commands that are needed? Edited October 4, 2012 by py6upouq Link to comment Share on other sites More sharing options...
Mujuro Posted October 4, 2012 Share Posted October 4, 2012 Try attaching an OnItemAdded() event to your container, and then checking first against the item you want, and then with each add of that specific item, either increment a counter or do a GetItemCount(). When you hit the requisite number of items you want in the container, do a RemoveItem() against the old item, followed by an AddItem() of the new. Something to the general effect of the following: Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Int givenItem = akBaseItem.GetFormID() Int yourItem = yourItemProperty.GetFormID() If akSourceContainer == Game.GetPlayer() && givenItem == yourItem If akContainer.GetItemCount(yourItem) >= yourItemCount akContainer.RemoveItem(akBaseItem, yourItemCount) akContainer.AddItem(akNewItem, yourItemCount) endIf endIf endEvent Link to comment Share on other sites More sharing options...
py6upouq Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) Thank you, Mujuro, I'll try.P.S. What is "akContainer"? Do I need to add line: "ObjectReference akContainer" or I confuse something? thx again Edited October 4, 2012 by py6upouq Link to comment Share on other sites More sharing options...
Mujuro Posted October 5, 2012 Share Posted October 5, 2012 Good luck! akContainer in the script sample represents the container that is holding your items that you're checking against. Basically, what the example does: Whenever an item is added to the container you attach the script to (akContainer), the script makes certain "checks"The first check "who put in the item in the container" and, in this case, it looks for the player as the sourceThe second check is against what the player is putting into the container (yourItem = what you're checking for); if the item isn't what you're looking for and/or it's an NPC using the container, the script takes no additional actionIf the item matches, and it's from the player, then next check is to see if the number of matched items meets whatever your trigger threshold is (yourItemCount)If it meets the item count, it'll remove the item via RemoveItem() and add the replacement item (akNewItem) Link to comment Share on other sites More sharing options...
py6upouq Posted October 5, 2012 Author Share Posted October 5, 2012 Compilation of suggested code has failedStarting 1 compile threads for 1 files... Compiling "sssContainerScript01"... d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(5,23): variable yourItemProperty is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(5,40): none is not a known user-defined type d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(5,12): type mismatch while assigning to a int (cast missing or types unrelated) d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(7,19): variable akContainer is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(7,31): none is not a known user-defined type d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(7,57): variable yourItemCount is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(7,54): cannot relatively compare variables to None d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(8,24): variable akContainer is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(8,59): variable yourItemCount is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(8,36): none is not a known user-defined type d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(9,24): variable akContainer is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(9,44): variable akNewItem is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(9,55): variable yourItemCount is undefined d:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\sssContainerScript01.psc(9,36): none is not a known user-defined type No output generated for sssContainerScript01, compilation failed.I tried adding some corrections but it still crashes. help? Link to comment Share on other sites More sharing options...
Mujuro Posted October 5, 2012 Share Posted October 5, 2012 It appears that you didn't set your properties. You need to click the "Properties" button on your script and get those filled and corresponding to your items, etc. Similarly, you need to define your variables. E.g., Int yourItemCount = 5, assuming 5 is the number you're looking for. To be clear, the sample script above assumes, perhaps dangerously, that you have your properties/variables declared. Scriptname yourScriptname extends ObjectReference ; or whatever, depending on how you set this up, could extend other stuff like ReferenceAlias ; Properties yourItemType Property yourItem Auto yourNewItemItem Property yourReplacementItem Auto ... etc. ... ; Variables (or you could do as properties if you choose) Int yourItemCount = x ; replace x with whatever you want your check quantity to be ObjectReference akContainer = Self ; depends on how you set up your "container" in the first place, you can just use Self ... code from earlier .... Link to comment Share on other sites More sharing options...
py6upouq Posted October 5, 2012 Author Share Posted October 5, 2012 (edited) This how I've managed to run code successfully, don't know how good it is but still nothing happens when I put matched items in containerScriptname sssContainerScript01 extends ObjectReference ObjectReference Property akIdealItem Auto ObjectReference Property akContainer Auto ObjectReference Property akNewItem Auto Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) Int givenItem = akBaseItem.GetFormID() Int yourItem = akIdealItem.GetFormID() If akSourceContainer == Game.GetPlayer() && givenItem == yourItem Int yourItemCount = akSourceContainer.GetItemCount(akBaseItem) akSourceContainer.RemoveItem(akBaseItem, yourItemCount) akContainer.AddItem(akNewItem, yourItemCount) endIf endEvent Thx for the help though!All I need is replace whatever amount of iron ingot placed in one chest to the same amount of gold ingot in another chest.Or perhaps replace any random items to gold ingot in accordance with their total weight. Also second variant: add containers around Skyrim so whatever player put in those would be transported into one central chest and backwards (you just push appropriate button and items from central chest transports to the chosen destination). I'm currently working on some mod maybe someone decide to join work and help me make scripts. All credits will be given. Edited October 5, 2012 by py6upouq Link to comment Share on other sites More sharing options...
Mujuro Posted October 5, 2012 Share Posted October 5, 2012 The script above isn't set up properly. It's removing the item from the PLAYER inventory when the conditions are matched (and you have an extra space there, but that should be harmless). Is akContainer your "another chest"? You can toss some debug.trace/messagebox lines in there to determine what step the script gets caught up at/fails to work as expected. Link to comment Share on other sites More sharing options...
Recommended Posts