Jump to content

[LE] Script logic problem


Recommended Posts

I have this script attached to a container which waits until you exit the container, blocks access to the container and then runs 2 processes; one disables all of the displayed items and the other checks the container for items which match the display items and enables any of the display that have items for them stored. I am having an issue because I have an external SKSE plugin which allows sharing of display data between saves, so if a handful of items are enabled already in the case, the script as it is now disables those, but will not enable them again, and this affects the display count poorly as a result.

 

I am rewriting the script to try and export a list of display references which are enabled but DO NOT have a matching display, into a formlist so that at the end I can re-enable those displays despite not having the item in the container. Problem I am having though is it seems to be adding incorrect forms to the list and any items I manually add, will now cause their matching display references to perma-enable and the system will not disable and re-check them. so I'm stumped.

 

 

Armor M
ObjectReference O

GlobalVariable Property DBM_DisplayMax Auto

FormList Property DBM_PMJewlertyResetList auto
FormList Property DBM_JewelryUnique Auto

int index

Auto State Waiting

Event OnActivate(ObjectReference akActionRef)
    BlockActivation()
    GoToState("Sorting")
    Utility.Wait(1.0)

    RecordPM()
    ResetDisplay()
    UpdateDisplay()

    BlockActivation(False)
    GoToState("Waiting")
    DBM_PMJewlertyResetList.Revert()
EndEvent

EndState

State Sorting

Event OnActivate(ObjectReference akActionRef)
    debug.notification("Displaying items, please wait")
EndEvent

EndState

Function RecordPM()
    Index = DBM_JewelryUnique.GetSize()
    While index
            Index -= 1
            O = DBM_JewelryUnique.GetAt(index) as Objectreference
            M = O.GetBaseObject() as Armor
            If O.Isenabled() && Self.GetItemCount(M) == 0
                DBM_PMJewlertyResetList.AddForm(O)
            Endif
    EndWhile
EndFunction

Function ResetDisplay()

    Index = DBM_JewelryUnique.GetSize()
    While index
            Index -= 1
            O = DBM_JewelryUnique.GetAt(index) as Objectreference
            M = O.GetBaseObject() as Armor
            If O.Isenabled() && !DBM_PMJewlertyResetList.HasForm(O)
                O.Disable()
                if DBM_Utils.getSharingEnabled()
                    DBM_Utils.saveDisplayStatus(O)
                Endif
                DBM_DisplayMax.Value -= 1
            Endif
    EndWhile
EndFunction

Function UpdateDisplay()

    Index = DBM_JewelryUnique.GetSize()
    While index
            Index -= 1
            O = DBM_JewelryUnique.GetAt(index) as Objectreference
            if O.GetBaseObject() as Armor
                M = O.GetBaseObject() as Armor
                if Self.GetItemCount(M) >= 1
                    O.Enable()
                    if DBM_Utils.getSharingEnabled()
                        DBM_Utils.saveDisplayStatus(O)
                    Endif
                    DBM_DisplayMax.Value += 1
                Endif
            Endif
    EndWhile
            ;Index = DBM_PMJewlertyResetList.GetSize()
            ;While Index
            ;    Index -= 1
            ;    O = DBM_PMJewlertyResetList.GetAt(index) as Objectreference
            ;    M = O.GetBaseObject() as Armor
            ;    if Self.GetItemCount(M) == 0                
            ;        O.Enable()
            ;        DBM_DisplayMax.Value += 1
            ;    Endif
            ;EndWhile



EndFunction
Link to comment
Share on other sites

I don' t know why it is behaving that way. Persistence stuff across characters can get complicated fast.

 

I would first try to keep all the enabling within the initial formlist on the outside chance that something is screwing up when using the reset list. To that end the following may be useful to replace the commented code that is giving you trouble.

Index = DBM_PMJewlertyResetList.GetSize()
While Index
  Index -= 1
  Form E = DBM_PMJewlertyResetList.GetAt(index)
  Int Idx = DBM_JewelryUnique.Find(E)
  O = DBM_JewelryUnique.GetAt(Idx) as ObjectReference
  O.Enable()
  DBM_DisplayMax.Value += 1
EndWhile

If you did have an index matching pair of lists where one list was the displays and the other was the armor, then you could use the container's OnItemRemoved event to Find the index of the armor and use that index to disable the display rather than going through and disabling all displays and re-enabling those 'persistent' and those with the armor item in the container. That may also help resolve this issue as well.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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