Jump to content

I need help with my easy script!


benstei21

Recommended Posts

So I am trying to use this easy script here, but it wont work. I have no idea on how to fix it

 

 

Event OnItemAdded(ObjectReference akActionRef)
KitchenShelf1FoodClutter.Enable()
EndEvent
Event OnItemRemoved(ObjectReference akActionRef)
KitchenShelf1FoodClutter.disable()
EndEvent
Edited by benstei21
Link to comment
Share on other sites

You really need to be a lot more specific on what you mean by "it won't work." That's far too vague for anyone to help you.

 

Besides the AddInventoryEventFilter mentioned, have you defined the clutter reference as a property? Is this your complete script? Is this is applied to a container? If so, you don't have a condition for the container to know if it's empty or not to enable/disable the clutter. Again, with no real info to work with we can only ask random questions 'till the brahmin come home guessing what the problem is.

 

Lastly, you've posted this in the General Discussion forum. In future, this is the sort of question better asked in the Creation Kit and Modders forum. You'll stand a much better chance of getting help there provided you include a better description of what you need help with. There are lots of people there that could easily figure out the problem if you give them the info they will need to help you. Not to say you can't get help in this forum, but the CK forum is a better place to ask for scripting help. :wink:

Link to comment
Share on other sites

Well I am trying to make a design shown in your video RedRocketTV. Its the video where you show of your weapon racks. I can probably figure out how to use a formlist to limit the items possible to put in the cointainer by myself, but I need it to somehow enable the clutter Static colletion inside the shelf if 1++ items are added. When there are less then 1 item inside the container I want the clutter to get disabled. I tried using getItemCount, but could not figure out how to transform the "output" generated from GetItemCount to making an action and disable/enable the clutter. Here is the whole script I made. Its not much but....

 

Scriptname KitchenCounter1Script extends ObjectReference
ObjectReference Property KitchenShelf1FoodClutter Auto
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
KitchenShelf1FoodClutter.Enable()
EndEvent
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
KitchenShelf1FoodClutter.disable()
EndEvent
Link to comment
Share on other sites

AddInventoryEventFilter is a little confusing to use at first. Check out the parameters section on the wiki link that RedRocketTV posted to see how to use it. KitchenShelf1FoodClutter is a static you said.

 

So with "AddInventoryEventFilter(KitchenShelf1FoodClutter)" you told the script "hey script whenever a KitchenShelf1FoodClutter static is added/removed into this container, I want you to take notice and receive an OnItemAdded event or OnItemRemoved event." Of course we can't add statics into containers so your container will never receive an event. I actually didn't even know you could put a specific ObjectReference into AddInventoryEventFilter's parameters since it's not in the wiki so that's pretty neat.

 

The usable parameters in AddInventoryEventFilter from the wiki:

https://www.creationkit.com/fallout4/index.php?title=AddInventoryEventFilter_-_ObjectReference

 

akFilter: The item to filter with.

If none, all items will be allowed through - but you MUST be able to handle several hundred at once!
If a base object, this object will only be notified of base objects matching exactly.
If a keyword, it will check the object for said keyword
If a component, it will check the object for said component
If a form list, it will filter using all of the forms in the form list (only items in the form list will be allowed through).

 

Fun fact: it' not on the wiki but if you call GetItemCount() and pass in "none" as its parameter, it will count anything and everything in a container/inventory.

 

I haven't tested this but give it a shot:

Scriptname KitchenCounter1Script extends ObjectReference


ObjectReference Property KitchenShelf1FoodClutter Auto

   Event OnInit()
        AddInventoryEventFilter(none)
       ;We passed in none here since we want to be aware when anything at all is being put in or out.
       ;You could filter for certain items in a formlist and then kick out any item that doesn't match but I'll leave that up to you. 
   endEvent

    Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
        debug.messagebox("Item added event received!")
        KitchenShelf1FoodClutter.Enable()
    EndEvent


    Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
        debug.messagebox("Item removed event received!")
        int ItemCounter
        ItemCounter = self.GetItemCount(none) ;from the fun fact trick
        if ItemCounter == 0
               KitchenShelf1FoodClutter.disable()
        endif

    EndEvent

Edit: Make sure you remember to initialize your KitchenShelf1FoodClutter property in the properties window!! I almost wish Creation Kit had a plugin that would interface with a cattle prod on my chair to stop me from forgetting to do this allllll the time.

 

Edit2: RedRocketTV's post right below this will get you the behavior you're looking for. My post is just for informative purposes and will have some weird things if you copy paste it. Like adding a gun to the container will make your kitchen clutter appear etc.

Edited by shatsnazzle
Link to comment
Share on other sites

Gotcha. Knowing what you’re trying to do definitely helps. Looks like you’re 3/4 of the way there but just need to plug a few holes. I do recommend using a form list as you mentioned. It makes it easier to add/remove the forms you want the script to recognize for controlling the clutter reference.

 

In this case, the AddInventoryEventFilter should be targeted to the form list. That way the script knows what items to look for when deciding to enable/disable the clutter or not. Anything not flagged by AddInventoryEventFilter is ignored when put into the container. The CK wiki entry I linked to earlier gives more info on its use.

 

You pretty much figured that GetItemCount is what you can use for this. I use .GetSize attached to the form list to get the number of items from the form list that are added then use GetItemCount with a condition set to >=1 for adding items and <=0 for removing items. When either threshold is reached, the clutter is enabled or disabled.

 

With the extra bits added to what you've already got, you end up with something like this:

Scriptname  KitchenCounter1Script extends ObjectReference

FormList Property ShelfItemSortList Auto

ObjectReference Property KitchenShelf1FoodClutter Auto

;tells script what items to act upon when enabling/disabling clutter
Event OnActivate(ObjectReference akActionRef)
 AddInventoryEventFilter(ShelfItemSortList)
EndEvent


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

;lets the container count how many items are added and decide when to enable clutter
Int iIndex = ShelfItemSortList.GetSize()
While iIndex
  iIndex-=1
  if akBaseItem && GetItemCount(ShelfItemSortList) >= 1 ;sets the threshold for when to enable clutter
  KitchenShelf1FoodClutter.enable(true)
  EndIf
EndWhile
EndEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

;lets the container count how many items are removed and decide when to disable clutter
Int iIndex = ShelfItemSortList.GetSize()
While iIndex
  iIndex-=1
  if akBaseItem && GetItemCount(ShelfItemSortList) <= 0 ;sets the threshold for when to disable clutter
  KitchenShelf1FoodClutter.disable(true)
  EndIf
EndWhile

EndEvent

You can remove the ‘true’ boolean if you want the clutter to pop in. I prefer to have it fade in/out...looks less jarring to me.

 

Someone who is more experienced with this sort of thing might be able to suggest a better method to pull this off, but this is what works for me so I go with it. Hope this helps point you in the right direction.

 

EDIT: looks like I was ninja'd while typing this by shatsnazzle offering a possible alternative.

 

Also should mention the obvious because this is something I often forget to do: if your container is starting off empty, be sure to set your clutter to Initially Disabled.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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