Jump to content

Listening to OnItemAdded on workshop container


niston

Recommended Posts

Im trying in my script (attached to a workshop object) to catch this event on the workshop container like so:

RegisterForRemoteEvent(refSourceContainer, "OnItemAdded")
Self.AddInventoryEventFilter(refItemImInterestedIn)
 
; and then
 
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
 
EndEvent

Problem is: The OnItemAdded event handler is never called. And most unfortunately, there are zero error message related to my script in papyrus log.

 

I tried AddInventoryEventFilter(none) and I tried refSourceContainer.AddInventoryEvent... but to no avail. I tried changing Event OnitemAdded... to Event ObjectReference.OnitemAdded, but then the compiler complains that the first paramter must be of type ObjectReference. If I go and change the first parameter to ObjectReference, the compiler then complains that the signature of the event handler is not the same as on ObjectReference script.

 

How can I get my script to receive inventory events from the workshop container?

 

Edit: Got the compiler to stop complaining by using this signature:

Event ObjectReference.OnItemAdded(ObjectReference sender, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

It however doesn't work, the event is not received. Idk what I'm doing wrong, someone please point it out to me.

Edited by niston
Link to comment
Share on other sites

RegisterForRemoteEvent is used to receive events on scripts that are NOT attached to the object from which you want to receive the event, so if you want to handle an event in the script that is attached to the object you don't need it, therefore the event is used as is shown in the wiki, otherwise, if you register for a remote event form lets say a quest script, you need to append the object type to the event name as you did, and the first parameter must be the object that is receiving this event.

 

The OnItemAdded event requires an inventory filter in order to receive it, and None as filter will receive the event for every object you add to the inventory of the object.

 

You must make sure that AddInventoryEventFilter is being called. You might be calling it in an event, like OnInit or OnLoad that's not being called when you test it, so you would need to fast travel in order to make sure the event is received and the filter function is called.

Link to comment
Share on other sites

Sorry if I was unclear. My script is attached to some workshop object, a furniture to be specific. I want it to listen to inventory events on the workshop container (to which it is not attached to).

 

I removed the filter only to see if it was causing problems. Of course I will normally have a filter in place :smile:

 

But I got it working now. A call to UnRegisterRemoteEvent() was being made when it shouldn't have been :smile:) *double facepalm*

 

PS: I also have a mechanism in place that will trigger only once if player, or something else, decides to dump a whole bunch of stuff into workshop in rapid succession.

 

And in case you wonder why: I added smoke that emanates from the smoke stack of my blast furnace (or really any F4MS Factory, if so desired). Now, the smoke turns on and off, depending whether the blast furnace has power, has a settler assigned, is not paused and has enough resources in the workshop for at least one single product. And if resources are added/removed to/from the workshop, the smoke updates accordingly :D

 

Such realistic. Very immersion. :D :D :D

 

Also its somewhat useful, because player will see immediately when the blast furnace stops producing because it has no resources, no power or the settler died.

Edited by niston
Link to comment
Share on other sites

Good. I misread it then.

 

It seems a bit weird registering for a workshop workbench's event on a workshop object script, I would rather use a RefCollectionAlias pointing to an external alias for Workshops in the WorkshopParent quest, and attach a script to this collection so you receive OnItemAdded for all workshops but, on the other hand, if the workshop is added from a mod and, for whatever reason, it's not being properly initialized (added to the Workshops RefCollectionAlias) your method will work anyway.

Link to comment
Share on other sites

Thing is, it must work with any container. The workshop is just the standard configuration. Also, I'm really only interested in the local workshop. :smile:

 

Anyway. Looks kinda cool, I think:

 

 

 

JV3cOE4.jpg

 

 

 

 

 

6sxj6Rq.jpg

 

 

Edited by niston
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...