batchbat Posted February 5, 2016 Share Posted February 5, 2016 (edited) Greetings all, I'm working on a script that allows merchants to be lootable, preferably via pickpocketing and/or slaughtering them. I'm very new to scripting but was (somehow) able to conjure up this little script that I added to a merchant (in this case, Ambarys Rendar (first merchant alphabetically :tongue:)): Scriptname LM_Cornerclub extends ObjectReference Actor Property PlayerRef auto ;This is the player, ObjectReference Property CornerclubCONT Auto ;this is my container, FormList Property ItemList Auto ;and this will be a list of the items I get. Event onDeath(Actor akKiller) ;When I'm killed, CornerclubCONT.removeAllItems(akTransferTo = self);take all items from my merchant chest and give it to me endevent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) ;and when I get those items, ItemList.AddForm(akBaseItem) ;add them to a list, endevent Event onActivate(ObjectReference akActionRef) ;When I'm activated if akActionRef == PlayerRef ;By the player, int ILsize = ItemList.GetSize() ;check how many items were added to me int index = 0 While index < ILSize ;and while I still have more items to add, Form entry = ItemList.GetAt(index ;check which item is to be added next Int qty = self.GetItemCount(entry ;and find how much of that item there is to add, if qty > 0 CornerclubCONT.AddItem(entry,qty,true) ;and add those items back to the vendor chest. EndIf index += 1 ;mark that item as being done, and move onto the next. EndWhile ;Once that's finished, ItemList.Revert() ;Clear the list so we can use it later again. EndIf EndEvent Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) ;If somebody takes something from my corpse CornerclubCONT.RemoveItem(akBaseItem, aiItemCount) ;make sure anyone else who also uses the same chest can have the same "shared" inventory as me EndEvent So it compiles nicely and probably works fine in-game, but a potential problem with this script has been made known to me. Currently (assuming that the same script will be used in applicable circumstances), if a player kills a merchant linked to a container that multiple vendors use, only the first merchant killed will have the items from the vendor chest. I want to be able to access both corpse's inventories as if they were a single, shared inventory, presumably with the vendor chest that they used being a middleman of sorts. A good way to circumvent this would be to only transfer the items after the corpse has been activated; this, however, I perceive to be not possible, since any changes that the player makes to one corpses inventory would (presumably) have to be reflected in the vendor chest so that the second merchant's corpse would have the same contents as the first. Unfortunately, the only way I see this able to be implemented would be if the inventory from the vendor chest (FormList ItemList in above code) is transferred back to the vendor chest from one corpse after the player makes all the changes that he wants; hence the need for an event that is triggered after the player EXITS the inventory of the corpse, or "deactivates"(?) the corpse. Searching at length for such an event, I found nothing that I could use (not entirely true; I found "onClose", but from the wiki page it seems that it doesn't apply to an inventory[CITATION NEEDED]), so I now turn to you, members of the forum, for help, and present you with these questions: Does such an event exist for me to use? Is there a better way to approach this problem? and of course, Is there anything I can change in above code to make it work better/more efficiently? Any help, even an attempt, would be greatly appreciated. TL;DR:Is there a Papyrus event that is triggered when a player exits an inventory? EDIT: Why does every other line in the above code snippet have a white background making it incredibly hard to see, and what can I do to fix that? Edited February 5, 2016 by batchbat Link to comment Share on other sites More sharing options...
sLoPpYdOtBiGhOlE Posted February 5, 2016 Share Posted February 5, 2016 (edited) I'm probably missing the point of what your trying to do. So I recap.Script is attached to 2 merchents.Those 2 merchants share the same merchant chest. When pickpocketing or if a merchant is dead you want access to the merchant chest contents.If you access the merchant and you add some items, remove some other items then exit that merchant..Then access the other merchent and he/she should refledct what the merchant chest should contain after the first merchant was acceesed? if so this may or mat not work, give it a shot if you like.Attach this script to each merchent that is sharing the one chest.Fill the Chest property in. Scriptname LM_Cornerclub extends Actor ObjectReference Property CornerclubCONT Auto Event OnActivate(ObjectReference akActionRef) If (akActionRef As Actor).IsSneaking() || Self.IsDead() CornerclubCONT.removeAllItems(self) RegisterForMenu("ContainerMenu") EndIf EndEvent Event OnMenuClose(String MenuName) If MenuName == "ContainerMenu" UnregisterForMenu("ContainerMenu") Self.RemoveAllItems(CornerclubCONT) EndIf EndEventEven though I compiled the above script, I have not actually tested in the game. Edited February 5, 2016 by sLoPpYdOtBiGhOlE Link to comment Share on other sites More sharing options...
batchbat Posted February 5, 2016 Author Share Posted February 5, 2016 I'm probably missing the point of what your trying to do. So I recap.Script is attached to 2 merchents.Those 2 merchants share the same merchant chest. When pickpocketing or if a merchant is dead you want access to the merchant chest contents.If you access the merchant and you add some items, remove some other items then exit that merchant..Then access the other merchent and he/she should refledct what the merchant chest should contain after the first merchant was acceesed? if so this may or mat not work, give it a shot if you like.Attach this script to each merchent that is sharing the one chest.Fill the Chest property in. Scriptname LM_Cornerclub extends Actor ObjectReference Property CornerclubCONT Auto Event OnActivate(ObjectReference akActionRef) If (akActionRef As Actor).IsSneaking() || Self.IsDead() CornerclubCONT.removeAllItems(self) RegisterForMenu("ContainerMenu") EndIf EndEvent Event OnMenuClose(String MenuName) If MenuName == "ContainerMenu" UnregisterForMenu("ContainerMenu") Self.RemoveAllItems(CornerclubCONT) EndIf EndEventEven though I compiled the above script, I have not actually tested in the game.Ah, okay. So it's "onMenuClose" that I'm looking for. It's actually an SKSE event, but that's not a problem.Thanks for pointing that out! Link to comment Share on other sites More sharing options...
Recommended Posts