Jump to content

Script problem


Recommended Posts

Here's an update.

I noticed I didn't change Self.Is3DLoaded() to LR.Is3DLoaded() in onOnLoadGame() event.

So Log spits spam no 3d.. blah blah blah.

Also cast as form on line eleven (but it works without it for me.

Also the changes to search the chain for same types instead of just the first type on add or remove.

 

 

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() As Form
    EndWhile
EndEvent

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

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 LR.Is3DLoaded()
            LR.setMotionType(Motion_Keyframed, FALSE)
        EndIf
    EndWhile
EndEvent

 

 

 

1.7.2 has a bug with CreateFormArray() and CreateReferenceAliasArray()

It doesn't null the array properly.

 

In other words you need to null the array yourself, then the array works.

Something like that.

1.7.3 fixed it supposedly

this is from 1.7.3 What'sNew.txt

 

- fixed Utility.CreateArray initialization with empty Forms/Aliases
Link to comment
Share on other sites

Ok updated to 1.7.3 and it works fine.

 

Only remaining issue is that it doesn't enable more than one of any one base for in the chain. I have 4 nord mead, a firebrand wine a couple spiced wines and it will only enable one of each

 

EDIT: Ah beat me to the punch. I'll check that other version out, thanks. I appreciate all your help with this.

Link to comment
Share on other sites

Dude, ya can't have ya cake and eat as well!

 

:D

 

You want it to represent how many of each type are in the container to how many are displayed as well?

That costs extra :tongue:

I given you a method, adapt it to your needs :smile:

 

Once you've refined the script, you can use it on any container and attach anything to the container that it can hold and you won't need to edit the script at all.

Just attach it, link ref chain from the container to your items and done.

 

Could be handy for more then just one custom display with minimal fuss.

Link to comment
Share on other sites

I appreciate it, I think I could probably condition out the script to enable specific quantities in the chain or even adapt it to look at the quantity of the placed item to make sure that quantity is in the container before enabling it. I'll just have to wrap my head around the array, it's my main weakness as far as scripting goes. I can do some pretty elaborate stuff but I have a mental block on it a bit.

 

Thanks for you help man :)

Link to comment
Share on other sites

Your welcome, hope it comes of use.

I think the most putting off thing with the array the way it's used in this instance is you skip the first element at index 0.

Index 0 = Cupboard ( the container itself).

This is why you see While i > 1 Or BID.Find(akBaseItem) >= 1

Which can throw one off when trying to mentally visualize the array index position

The reason why I left that element at that index in the array instead of only just the the BaseID of the actual wanted items in the chain.
Mainly so you can call GetNthLinkedRef(i) without having to compensate the index count.

eg: having the array without the container at index 0 then you would base searches and loops on the array from index 0
and when calling GetNthLinkedRef() you would use GetNthLinkedRef(i + 1).

So either way I would have had to compensate for that index 0 to keep sync.

 

I think the plus side of the method though is your not dependent CK predefined script properties, formlists and such.

Well it's close to self sufficient dynamic on the fly, doing it's thing as needed.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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