OnClose function for a Container

Post » Mon Jun 18, 2012 9:47 am

I have a "Bag of Trash", I want to empty the bag when the container is closed.

What I need is to detect that the player has closed the container (Tab) in the UI.

So I put an Event OnClose() with a RemoveAllItems() in the script. It does compile but does not remove the items. Maybe RemoveAllItems() is not working?

Is OnClose() fired when the container is closed (with Tab in the UI)? What is considered "closed". I have a suspicion that the container is not closed once activated, just doing Tab to close the container in the UI maybe does not close the container.

I just realized I may need to put a DebugText in the OnClose() to see if it is firing. Where does the DebugText output go to? I'm going to try this now. I'll be back later if anyone has any info or good ideas.

[EDIT] Figured out Debug - Thanks Cipscis. I'm lazy, I just needed to look up Debug on the WIKI - it's documented there.

[EDIT] OnClose() does not fire when the bag is closed by the player in the UI. So how do I detect when the player closes the bag?

[EDIT] Duh...! I think OnClose() is for doors closing, not for objects closing. So, OnClose() won't do anything for a container.

There is a clumsy workaround: Put an object (permanently) in the bag named something like "_empty the bag_", taking that object would cause the bag to empty and that special object would be placed back into the bag. Clumsy and dirty, so I'd like a better solution if possible.
User avatar
Rhiannon Jones
 
Posts: 3423
Joined: Thu Sep 21, 2006 3:18 pm

Post » Mon Jun 18, 2012 7:10 pm

Debug.Notification prints to the screen. The stickied "Having Papyrus trouble?" has some good information about debugging functions.

Cipscis
User avatar
Brittany Abner
 
Posts: 3401
Joined: Wed Oct 24, 2007 10:48 pm

Post » Mon Jun 18, 2012 8:05 am

How about a lever or button next to the bag, making it like a trash chute?
User avatar
Katy Hogben
 
Posts: 3457
Joined: Mon Oct 30, 2006 12:20 am

Post » Mon Jun 18, 2012 1:57 pm

I have a "Bag of Trash", I want to empty the bag when the container is closed.

What I need is to detect that the player has closed the container (Tab) in the UI.

So I put an Event OnClose() with a RemoveAllItems() in the script. It does compile but does not remove the items. Maybe RemoveAllItems() is not working?

Is OnClose() fired when the container is closed (with Tab in the UI)? What is considered "closed". I have a suspicion that the container is not closed once activated, just doing Tab to close the container in the UI maybe does not close the container.

I just realized I may need to put a DebugText in the OnClose() to see if it is firing. Where does the DebugText output go to? I'm going to try this now. I'll be back later if anyone has any info or good ideas.

[EDIT] Figured out Debug - Thanks Cipscis. I'm lazy, I just needed to look up Debug on the WIKI - it's documented there.

[EDIT] OnClose() does not fire when the bag is closed by the player in the UI. So how do I detect when the player closes the bag?

[EDIT] Duh...! I think OnClose() is for doors closing, not for objects closing. So, OnClose() won't do anything for a container.

There is a clumsy workaround: Put an object (permanently) in the bag named something like "_empty the bag_", taking that object would cause the bag to empty and that special object would be placed back into the bag. Clumsy and dirty, so I'd like a better solution if possible.
You can try playing around with the http://www.creationkit.com/OnItemAdded_-_ObjectReference
User avatar
Rebecca Dosch
 
Posts: 3453
Joined: Thu Jan 18, 2007 6:39 pm

Post » Mon Jun 18, 2012 12:27 pm

How about a lever or button next to the bag, making it like a trash chute?
The Trash Bag is used from the player inventory, the player carries the bag around, the bag can be dropped but it's not a fixed world item. It would be possible to have a separate equipable inventory item named something like "Empty the Trash" but I think that would make the inventory too busy.

You can try playing around with the http://www.creationkit.com/OnItemAdded_-_ObjectReference
I originally was going to just delete the items as they were transferred to the Trash Bag (in OnItemAdded()) but I thought it would be better to maintain the list until the bag was closed so the player could take items back out that they might have accidentally put in the Trash.

All fixed now! The items placed in the Trash are deleted the next time the bag is activated. It's not possible to detect that the player has closed the inventory but the activator for the Trash Bag (not the Trash object itself) empties the bag then activates it. The point of the Trash Bag is to positively remove excess inventory items from the game and from the savegame file.

The Trash Bag allows the player to put items into the Trash and get the gold value of the item back. It's mildly a cheat item. I got really tired of finding high value items that I could not sell because vendors don't have enough gold. Once you've maxed out your vendor skills (Speech) there's no real point in selling to the vendors anyway. I've been putting stuff in empty barrels just to get rid of excess inventory, with the Trash Bag I can easily remove items from the game (and from the savegame file) and get some gold for them too.
User avatar
Sami Blackburn
 
Posts: 3306
Joined: Tue Jun 20, 2006 7:56 am

Post » Mon Jun 18, 2012 7:01 pm

Would it be possible to use http://www.creationkit.com/RegisterForSingleUpdate_-_Form to delete the objects?

It won't run if the player is in a menu (i.e., the inventory.) So once it starts, it should automatically do what it's set to do once the player exits the inventory.
User avatar
BrEezy Baby
 
Posts: 3478
Joined: Sun Mar 11, 2007 4:22 am

Post » Mon Jun 18, 2012 10:04 am

Would it be possible to use http://www.creationkit.com/RegisterForSingleUpdate_-_Form to delete the objects? It won't run if the player is in a menu (i.e., the inventory.) So once it starts, it should automatically do what it's set to do once the player exits the inventory.
Well... Yes. I had considered that. The problem is that it is a real-time operator and I'm especially cautious with real-time stuff. The player could close and re-open the Trash Bag before the update was completed causing two (or more) updates to be scheduled. This is not such a big problem, the updates would complete successfully, but I don't like messing with real-time stuff just because it might slow down the game performance. It's possible to schedule only one update by using a global variable - but I don't know now if it's possible to create and access a global variable from a script.

[EDIT] Found it - create a Global variable in the .esp, see http://www.creationkit.com/GlobalVariable_Script for the syntax.
User avatar
BaNK.RoLL
 
Posts: 3451
Joined: Sun Nov 18, 2007 3:55 pm


Return to V - Skyrim