Jump to content

need help with part of my script, plz and thx :)


Recommended Posts

So I have another small question relating to this. The array is built when the script runs for the first time (OnInit()) but now I am trying to update my Immersive Weapons addon so that I can tack some additional weapons onto the existing chain. Obviously the build of the array cannot happen again. I've tried running the same build functions in an OnPlayerLoadGame() block but it seems that since the array is already defined, it won't simply re-build it. I also can't seem to find any functions online to reset the array or delete or clear it so that it CAN be redefined. Any ideas?

Link to comment
Share on other sites

You should be able to call OnInit() just like any other function, be it from the existing script or from any other script.

Calling OnInit() yourself manually should rebuild the array fine.

 

No need to try deleting the existing array as PM = Utility.CreateStringArray(iWhateverSize) would would null the original array when recreating it.

Well that's the way it works for me anyway.

I use it in an MCM menu that dynamically creates the Pages array before my MCM menu opens.

Link to comment
Share on other sites

according to info on the OnInit entry on the wiki page OnInit only fires once unless called up again by a quest starting or when a cell resets. The cell I am using these in however need to be a noresetzone otherwise the mannequins will unequip their crap. Can the container the script is attached to be called to reset() itself OnCellAttach() perhaps? Would that then trigger the OnInit() on it as well?... oh but that would clear it's inventory crap...

Link to comment
Share on other sites

You can call OnInit() yourself anytime yourself just like you would call any other function.

Example (I wouldn't do it from this event, but just as an example):

Scriptname DD_WeaponArmorDisplayScript extends ObjectReference

String[] MP

Event OnInit()
    Int i = countLinkedRefChain()
    MP = Utility.CreateStringArray(i)
    While i
        i -= 1
        MP[i] = (GetNthLinkedRef(i).GetBaseObject() As Weapon).GetModelPath()
    EndWhile
EndEvent

Event onCellAttach()
    OnInit()  ;<--- Calling it myself
    ResetDisplay()
EndEvent

You can even call OnInit() that is in another script anytime you like.

It's the same for any event, events can be called manually anytime just like any normal function, but use caution when you do is all.

Link to comment
Share on other sites

Good you got it sorted.

 

Keep in mind it's really not advised to call that block of code every cell attach or an event that get fired repeatedly all the time for good reason.

The block itself only needs to be called once initially when your mod is first loaded.

If your needing to update what's attached due to you released a mod and then you added more to the chain in an update and the user is updating from your prior version (not starting a new game, not advised ever) then set up version update in an OnPlayerLoadGame() event.

Make it so the update only fires once only for an updated version of your mod.

 

Specially if your planning to use multiple separate display containers using the same method.

Calling that block repeatedly every event over and over is just more script load and is not needed.

Link to comment
Share on other sites

Thanks for the advice, I'll refine it a bit so it runs less often.

 

A little update on the script performance. Seems that the script is not resilient enough to handle running the havoc assignment in addition to the display check because of the While loops, especially on a slow system or a script heavy modded one. So I attached havoc management directly to the objects when they load, and trimmed down the main display script a bit. Also needed to add a base form if check on the OnInit so that it didn't try and poll the chest itself for a model path, but all in all it's working flawlessly now. Thanks for the help.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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