ElliotSternberg Posted June 13, 2012 Share Posted June 13, 2012 I'm trying to create a mod where the player can use a chest inside of the rent-able rooms of any given inn and deposit items to sell. The chest would also have a potion in it when opened, which when drunk will empty the chest, add in another potion and add gold based on the chests content. I'm 99% sure on how to do everything except select an object within the chest. I cannot tell what will be in there, and thus can't use the normal commands. From there I would just use the GetGoldValue Form, add the value to a variable, remove the item and loop it for the rest of the items. That would all be on the consumption of the potion. I'm extremely new to modding, but have some experience in C++ and a lot in PHP. Any help would be appreciated. The end goal for the mod is to be used in combination with increasing prices by about 100 times to make money tighter. I like cut-throat merchants but can't stand everything under 10 gold being worth 0. This will be about 50% of the value but high costs. Thanks again. Link to comment Share on other sites More sharing options...
steve40 Posted June 13, 2012 Share Posted June 13, 2012 (edited) I haven't worker with containers in Skyrim before, so I'm not sure if this is the right way to go.There doesn't seem to be a simple function to keep track of what is in a container, as far as I can tell.The following test script (I haven't tried compiling or testing it) should (hopefully) maintain a Formlist that keeps track of all items added to a container. ** You will need to create a new FormList in the CK called "aaItemList". ** Put the script on the container. You can then expand the script to have a routine (that is called by drinking the potion) that processes the data in the formlist, eg:- Get the size of the formlist- Set up a while loop- Walk through each item in the FormList, get its value, add the value to the tally, remove the item from the FormList, remove the actual item from the container and disable/delete it.- Finish the loop, add the gold to the player- Add a new potion to the container Done. ScriptName aaCustomContainerScript extends ObjectReference FormList Property aaItemList auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) While aiItemCount > 0 aaItemList.AddForm(akBaseItem) ; tracking list of items in container aiItemCount -= 1 EndWhile EndEvent Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) While aiItemCount > 0 ItemList.RemoveForm(akBaseItem) ; tracking list of items in container aiItemCount -= 1 EndWhile EndEvent Edited June 13, 2012 by steve40 Link to comment Share on other sites More sharing options...
ElliotSternberg Posted June 13, 2012 Author Share Posted June 13, 2012 Thanks a ton! I had waited to reply because I wanted to see if I could get a final product out quickly enough, but I can't reset the GOD-DAMN CHEST! It's really annoying. Everything works fine, but when I try to reference the chest through a property the compiler says 'reset is not a function or does not exist.' I've read for about an hour now and know it has to do with the way it's referenced. For now I'm looking at a few other mods to try and see how it's done. Here's my script if you want to have a look at it: Scriptname AddProfit extends ObjectReference Int TotalGold ObjectReference CurrentForm FormList Property BulkSellFormList Auto MiscObject Property Gold001 Auto Container Property BulkSellChest Auto Event OnEffectStart(Actor GetPlayer) TotalGold = 0 While BulkSellFormList.GetSize() > 0 BulkSellFormList.GetAt(0) TotalGold = TotalGold + CurrentForm.GetGoldValue() BulkSellFormList.RemoveAddedForm(CurrentForm) EndWhile TotalGold * 0.5 Game.GetPlayer().Additem(Gold001, TotalGold) BulkSellChest.Reset() EndEvent That is attached to the magic effect of the potion. Let me know if you or anyone else can point me in the right direction. Link to comment Share on other sites More sharing options...
fg109 Posted June 13, 2012 Share Posted June 13, 2012 (edited) Change the BulkSellChest to an object reference property. Your chest's base object is a container; as an object in the game world, it is an object reference. Only objects that are in the game world can be reset. Well, other than quests. Also, I've had trouble getting RemoveAddedForm to work, just like the comment on the discussion page. I haven't tried using it since the past couple of updates, so maybe it's fixed now. And I don't know if it does work, how it will change the form list. Does it actually remove the entry and re-index everything, or does it just set the entry to "None"? It might be better if you iterated through the form list from the end. EDIT: Forgot to mention that form lists don't accept duplicates. So you can't have two entries that are the same (eg Gold001 at index 0 and index 1). You can have object references though (eg FF000801 at index 0 as the first gold coin, FF000802 at index 1 as the second gold coin). Edited June 13, 2012 by fg109 Link to comment Share on other sites More sharing options...
steve40 Posted June 13, 2012 Share Posted June 13, 2012 (edited) Further to fg109's comments, I think your magic effect script should be extending ActiveMagicEffect not ObjectReference. If only one of each base form can be added to a formlist, then the container script example that I posted above will have a problem handling multiple copies of the same item. The reason I didn't try adding the object reference (akItemReference) to the formlist is that that parameter can often be NONE. The script will probably have to be changed to check if akItemReference is not "none", in which case that reference could be added to the FormList, otherwise if it is "none" then add the base form akBaseItem instead. Edited June 14, 2012 by steve40 Link to comment Share on other sites More sharing options...
Recommended Posts