Jump to content

Script problem


Recommended Posts

So I have what seems like a simple task but for some reason or another I'm having an Einsteinian moment (running thousands of ideas through your head at once but forgetting to put your pants on)

 

So I have a liquor cabinet, and an actual bottle of wine sitting on a table. I have the wine disabled (and blocked for havoc and activation) and I want it to enable when the same wine type is put into the cabinet. I can achieve this with FormLists no problem, but what I am looking for is a few conditions that will check the akBaseItem added against the BASE type of the reference that is on the formlist, but so far I'm coming up lemons. Anyone have any ideas?

Link to comment
Share on other sites

Is the disabled Non havok item on the table the same base form as what is being added to the liquor cabinet?

Is there more then one type of item on the table that will be doing the same eg: different other bottles of wine or whatever that will be being enabled as stuff is put into the liquor cabinet?

 

If so then I'd just use Linked Refs from the liquor cabinet to each disabled items on the table.

 

Edit: test what I posted prior and what a failure that was.

But same principle including your method of Disable havok in the script as well, so i didn't need to add the script to each item.

 

So I dropped a vanilla cupboard into the Whiterun Bannered Mare Inn (behind the counter on the left).

Attached this script to the cupboard in the render window:

 

Scriptname LiquorCabinetScript Extends ObjectReference

Form[] BID
ObjectReference LR

Event OnInit()
    Int i = countLinkedRefChain()
    BID = Utility.CreateFormArray(i)
    While i
        i -= 1
        BID[i] = GetNthLinkedRef(i).GetBaseObject()
    EndWhile
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    Int i = BID.Find(akBaseItem)
    If i >= 1
        LR = GetNthLinkedRef(i)
        If LR.IsDisabled()
            LR.Enable()
            onLoadGame()
        EndIf
    Else
        ;Return the items to the player (if your wanting to only permit the same type items as linked to the cupboard)
    EndIf
EndEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    Int i = BID.Find(akBaseItem)
    If i >= 1 && GetItemCount(akBaseItem) == 0
        LR = GetNthLinkedRef(i)
        If LR.IsEnabled()
            LR.Disable()
        EndIf
    EndIf
EndEvent

Event onLoad()
    Int i = BID.Length
    While i > 1
        i -= 1
        LR = GetNthLinkedRef(i)
        LR.BlockActivation(true)
        LR.setMotionType(Motion_Keyframed, FALSE)
        LR.MoveToMyEditorLocation()
    EndWhile
EndEvent

Event onCellAttach()
    Int i = BID.Length
    While i > 1
        i -= 1
        LR = GetNthLinkedRef(i)
        LR.BlockActivation(true)
        LR.MoveToMyEditorLocation()
    EndWhile
EndEvent

Event onLoadGame()
    Int i = BID.Length
    While i > 1
        i -= 1
        LR = GetNthLinkedRef(i)
        LR.MoveToMyEditorLocation()
        LR.BlockActivation(true)
        If (Self.Is3DLoaded())
            LR.setMotionType(Motion_Keyframed, FALSE)
        EndIf
    EndWhile
EndEvent

 

 

 

Then dropped 11 different types of grog bottles into the render window (set as Disabled) and sat them on the cupboard shelf.

Then created Linked Ref from the cupboard to the first bottle, created a linked ref from first bottle to the next bottle, repeat until my bottles are linked in a chain.

 

Saved esp load and yep it works.

No need to add your havok script to each bottle or item, the cupboard script looks after whatever is in the linked ref chain.

 

This was my test esp:

Link to comment
Share on other sites

So in effect if anything you add to the container matches anything in the chain it will enable the first reference of that which matches the same base item put into the container? So would this work for, like you said, having several bottle types all laid out? and if I say had 3 mead bottles in a chain with a wine bottle at the end, and added the wine bottle to the container, would it enable? or would it have to wait for the others in the chain to enable first?
Link to comment
Share on other sites

Yes.

 

So say the bottle on the end of the chain is Alto Wine, then you add a bottle of Alto wine to the container, then the Alto Wine bottle gets enabled.

 

Say there's a bottle of nord mead somewhere in the chain and you ad a bottle of nord mead to the container the nord mead in the chain gets enabled... etc.

 

Same if you remove all of a type of bottle from the container then the display item gets disabled.

 

Just load up the esp and try it.

 

Basically if you have 10 of the same bottles in the chain then only one of the same 10 would be enabled.

Since your only finding the first matching base id in the chain and enable or disable as needed.

 

But you could write more to it to groups of the same bottle.

or just use 1 bottle of the group in the chain and the other same bottles make the chain the bottle the parent.

(That's if your wanting for example 10 Nor Mead or how ever many of just one type)

The only thing I can see that you will need on the bottles that aren't in the chain and using one of the chain as parent, then each of the children would need your havok script attached to it.

 

Other way of handling multi of the same type in the chain is use a loop when adding or removing items.

So that if the item added/removed from the container, then loop through every link ref and if one matches, enable/disable and keep going through the loop and doining the same.

Example of doing this, just replace the OnItemAdd/Remove functions in the script with this (slower though, but will enabled/disable more then one of the same type in the chain)

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If BID.Find(akBaseItem) >= 1
        Int i = BID.Length
        While i > 1
            i -= 1
            LR = GetNthLinkedRef(i)
            If LR.GetBaseObject() == akBaseItem
                If LR.IsDisabled()
                    LR.Enable()
                EndIf
            EndIf
        EndWhile
        onLoadGame()
    Else
        ;Return the items to the player (if your wanting to only permit the same type items as linked to the cupboard)
    EndIf
EndEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    If BID.Find(akBaseItem) >= 1 && GetItemCount(akBaseItem) == 0
        Int i = BID.Length
        While i > 1
            i -= 1
            LR = GetNthLinkedRef(i)
            If LR.GetBaseObject() == akBaseItem
                If LR.IsEnabled()
                    LR.Disable()
                EndIf
            EndIf
        EndWhile
    EndIf
EndEvent

I just did it as Find() in an array which obviously is fast, but doesn't look any further then the first match.

Link to comment
Share on other sites

I'll have to check out the demo ESP because I must be missing something very simple because it doesn't seem to work for me. I slap the scrip on the container, LinkedRef to a bottle, LinkRef THAT bottle to another and so on until it links to the last bottle. I do to add bottle of those types into the container and nothing happens.
Link to comment
Share on other sites

Requires SKSE 1.7.2 or above, 1.7.3 is what I'm using

 

Line 11

BID = GetNthLinkedRef(i).GetBaseObject()

 

in this:

Form[] BID
ObjectReference LR

Event OnInit()
    Int i = countLinkedRefChain()
    BID = Utility.CreateFormArray(i) ;<-- SKSE 1.7.2 or above
    While i
        i -= 1
        BID[i] = GetNthLinkedRef(i).GetBaseObject()
    EndWhile
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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