Jump to content

Script help


Recommended Posts

Having a little issue with a mod script I made a while back. Due to some issues I had to use a backup of it, but it's not quite working. The script is for making a treasury that, when it hits certain amounts, makes it slowly fill with treasure. Right now though, it's not filling with jack squat. Not sure what's really wrong, it saved fine, and all of the object references are connected.

Here's the script:

Spoiler
Scriptname EW_TreasuryScript extends ObjectReference  

ObjectReference property Vaultloot01 auto
ObjectReference property Vaultloot02 auto
ObjectReference property Vaultloot03 auto
ObjectReference property Vaultloot04 auto
ObjectReference property Vaultloot05 auto
ObjectReference property Vaultloot06 auto
ObjectReference property VaultLoot07 auto
ObjectReference property VaultLoot08 auto
ObjectReference property VaultLoot09 auto
ObjectReference property Vaultloot10 auto
ObjectReference property Vaultloot11 auto
ObjectReference property Vaultloot12 auto
ObjectReference property Vaultloot13 auto
ObjectReference property Vaultloot14 auto
ObjectReference property Vaultloot15 auto
ObjectReference property Vaultloot16 auto

ObjectReference property GoldVault auto

Form gold001

int value = 0

int Function ValueChange(Form akBaseItem, int aiItemCount)
    {Returns the value change from moving [aiItemCount] of [akBaseItem]}
    If akBaseItem==gold001
        return aiItemCount
    EndIf
EndFunction

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

    value += ValueChange(akBaseItem, aiItemCount)
    
    if (value >= 1000)
        Vaultloot01.enable()
    elseif  (value <= 999)
        Vaultloot01.disable()
    endif
    if (value >= 5000)
        Vaultloot02.enable()
    elseif  (value <= 4999)
        Vaultloot02.disable()
    endif
    if (value >= 10000)
        Vaultloot03.enable()
    elseif  (value <= 9999)
        Vaultloot03.disable()
    endif
    if (value >= 25000)
        Vaultloot04.enable()
    elseif  (value <= 24999)
        Vaultloot04.disable()
    endif
    if (value >= 50000)
        Vaultloot05.enable()
    elseif  (value <= 49999)
        Vaultloot05.disable()
    endif
    if (value >= 100000)
        Vaultloot06.enable()
    elseif  (value <= 99999)
        Vaultloot06.disable()
    endif
    if (value >= 200000)
        VaultLoot07.enable()
    elseif  (value <= 199999)
        VaultLoot07.disable()
    endif
    if (value >= 300000)
        VaultLoot08.enable()
    elseif  (value <= 299999)
        VaultLoot08.disable()
    endif
    if (value >= 400000)
        VaultLoot09.enable()
    elseif  (value <= 399999)
        VaultLoot09.disable()
    endif
    if (value >= 500000)
        Vaultloot10.enable()
    elseif  (value <= 499999)
        Vaultloot10.disable()
    endif
    if (value >= 650000)
        Vaultloot11.enable()
    elseif  (value <= 649999)
        Vaultloot11.disable()
    endif
    if (value >= 850000)
        Vaultloot12.enable()
    elseif  (value <= 749999)
        Vaultloot12.disable()
    endif
    if (value >= 1000000)
        Vaultloot13.enable()
    elseif  (value <= 999999)
        Vaultloot13.disable()
    endif
    if (value >= 1250000)
        Vaultloot14.enable()
    elseif  (value <= 1249999)
        Vaultloot14.disable()
    endif
    if (value >= 1500000)
        Vaultloot15.enable()
    elseif  (value <= 1499999)
        Vaultloot15.disable()
    endif
    if (value >= 2000000)
        Vaultloot16.enable()
    elseif  (value <= 1999999)
        Vaultloot16.disable()
    endif
Endevent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    
    value -= ValueChange(akBaseItem, aiItemCount)
    
    if (value >= 1000)
        Vaultloot01.enable()
    elseif  (value <= 999)
        Vaultloot01.disable()
    endif
    if (value >= 5000)
        Vaultloot02.enable()
    elseif  (value <= 4999)
        Vaultloot02.disable()
    endif
    if (value >= 10000)
        Vaultloot03.enable()
    elseif  (value <= 9999)
        Vaultloot03.disable()
    endif
    if (value >= 25000)
        Vaultloot04.enable()
    elseif  (value <= 24999)
        Vaultloot04.disable()
    endif
    if (value >= 50000)
        Vaultloot05.enable()
    elseif  (value <= 49999)
        Vaultloot05.disable()
    endif
    if (value >= 100000)
        Vaultloot06.enable()
    elseif  (value <= 99999)
        Vaultloot06.disable()
    endif
    if (value >= 200000)
        VaultLoot07.enable()
    elseif  (value <= 199999)
        VaultLoot07.disable()
    endif
    if (value >= 300000)
        VaultLoot08.enable()
    elseif  (value <= 299999)
        VaultLoot08.disable()
    endif
    if (value >= 400000)
        VaultLoot09.enable()
    elseif  (value <= 399999)
        VaultLoot09.disable()
    endif
    if (value >= 500000)
        Vaultloot10.enable()
    elseif  (value <= 499999)
        Vaultloot10.disable()
    endif
    if (value >= 650000)
        Vaultloot11.enable()
    elseif  (value <= 649999)
        Vaultloot11.disable()
    endif
    if (value >= 850000)
        Vaultloot12.enable()
    elseif  (value <= 749999)
        Vaultloot12.disable()
    endif
    if (value >= 1000000)
        Vaultloot13.enable()
    elseif  (value <= 999999)
        Vaultloot13.disable()
    endif
    if (value >= 1250000)
        Vaultloot14.enable()
    elseif  (value <= 1249999)
        Vaultloot14.disable()
    endif
    if (value >= 1500000)
        Vaultloot15.enable()
    elseif  (value <= 1499999)
        Vaultloot15.disable()
    endif
    if (value >= 2000000)
        Vaultloot16.enable()
    elseif  (value <= 1999999)
        Vaultloot16.disable()
    endif

Endevent

 

EDIT: I completely forgot to mention this is on Skyrim AE. IDK if that will help with solving, but I thought i'd bring it up.

Edited by wilwhitt56
Link to comment
Share on other sites

The most likely problem is that your properties are not filled.

Also, the OnItemAdded and OnItemRemoved events are only garanteed to fire when going from 0 to not 0, and the converse.  They often don't fire when adding items of a type already present in the container.  If there is some other event you can use as a trigger, that may be helpful.  In any case, adding debugging output will help clarify the actual behavior.

Otherwise...

Function ValueChange should have an else part to the if:

int Function ValueChange(Form akBaseItem, int aiItemCount)
	{Returns the value change from moving [aiItemCount] of [akBaseItem]}
	If akBaseItem==gold001
		Debug.notification( "Detected value change: " + aiItemCount)
		return aiItemCount
	Else
		Debug.notification( "No value change for: " + akBaseItem.getName())
		return 0
	EndIf
EndFunction

You should probably use "else" instead of "elseif <condition>" in your other two functions.

 

Link to comment
Share on other sites

You have a local form variable labeled gold001.  While this is the editor ID name of the gold item, there is no actual data assigned to this variable.  In essence, you are comparing a passed in item to nothing.  This will fail to increase your count which in turn causes your script to do nothing.  Change it from a local form variable to a MiscObject property and assign the correct item to it.  This should allow the rest of the script to continue processing.

Furthermore, a dual array approach may be best here.  By using arrays, you can work with more items with less code.  I've adapted your script to use arrays built at run time so that no changes to already assigned properties needs to be done.  That said, array properties would be an even cleaner approach.

Spoiler
Scriptname EW_TreasuryScript extends ObjectReference  

ObjectReference property Vaultloot01 auto
ObjectReference property Vaultloot02 auto
ObjectReference property Vaultloot03 auto
ObjectReference property Vaultloot04 auto
ObjectReference property Vaultloot05 auto
ObjectReference property Vaultloot06 auto
ObjectReference property VaultLoot07 auto
ObjectReference property VaultLoot08 auto
ObjectReference property VaultLoot09 auto
ObjectReference property Vaultloot10 auto
ObjectReference property Vaultloot11 auto
ObjectReference property Vaultloot12 auto
ObjectReference property Vaultloot13 auto
ObjectReference property Vaultloot14 auto
ObjectReference property Vaultloot15 auto
ObjectReference property Vaultloot16 auto

ObjectReference property GoldVault auto

MiscObject Property gold001 Auto

int count = 0

Event OnInit()
    VaultLoot = new ObjectReference[16]
    VaultLoot[0] = Vaultloot01
    VaultLoot[1] = Vaultloot02
    VaultLoot[2] = Vaultloot03
    VaultLoot[3] = Vaultloot04
    VaultLoot[4] = Vaultloot05
    VaultLoot[5] = Vaultloot06
    VaultLoot[6] = Vaultloot07
    VaultLoot[7] = Vaultloot08
    VaultLoot[8] = Vaultloot09
    VaultLoot[9] = Vaultloot10
    VaultLoot[10] = Vaultloot11
    VaultLoot[11] = Vaultloot12
    VaultLoot[12] = Vaultloot13
    VaultLoot[13] = Vaultloot14
    VaultLoot[14] = Vaultloot15
    VaultLoot[15] = Vaultloot16

    MaxValue = new Int[16]
    MaxValue[0] = 999
    MaxValue[1] = 4999
    MaxValue[2] = 9999
    MaxValue[3] = 24999
    MaxValue[4] = 49999
    MaxValue[5] = 99999
    MaxValue[6] = 199999
    MaxValue[7] = 299999
    MaxValue[8] = 399999
    MaxValue[9] = 499999
    MaxValue[10] = 649999
    MaxValue[11] = 749999
    MaxValue[12] = 999999
    MaxValue[13] = 1249999
    MaxValue[14] = 1499999
    MaxValue[15] = 1999999
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If akBaseItem == gold001
        count += aiItemCount
        DisplayPiles(count)
    EndIf
Endevent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    If akBaseItem == gold001
        count -= aiItemCount
        DisplayPiles(count)
    EndIf
Endevent

Function DisplayPiles(Int value)
    Int index = MaxValue.Length
    Int myActive = -1
    While index >= 0 
        ; scan from end to beginning (i.e. largest to smallest)
        index -= 1
        If (value > MaxValue[index]) && (myActive == -1)
            ; enable only the first highest value pile
            myActive = index
            VaultLoot[index].enable()
        Else
            ; disable all other entries if previously enabled
            If VaultLoot[index].isEnabled()
                VaultLoot[index].disable()
            EndIf
        EndIf
    EndWhile
EndFunction

 

 

Link to comment
Share on other sites

2 hours ago, IsharaMeradin said:

You have a local form variable labeled gold001.  While this is the editor ID name of the gold item, there is no actual data assigned to this variable.  In essence, you are comparing a passed in item to nothing.  This will fail to increase your count which in turn causes your script to do nothing.  Change it from a local form variable to a MiscObject property and assign the correct item to it.  This should allow the rest of the script to continue processing.

Furthermore, a dual array approach may be best here.  By using arrays, you can work with more items with less code.  I've adapted your script to use arrays built at run time so that no changes to already assigned properties needs to be done.  That said, array properties would be an even cleaner approach.

  Hide contents
Scriptname EW_TreasuryScript extends ObjectReference  

ObjectReference property Vaultloot01 auto
ObjectReference property Vaultloot02 auto
ObjectReference property Vaultloot03 auto
ObjectReference property Vaultloot04 auto
ObjectReference property Vaultloot05 auto
ObjectReference property Vaultloot06 auto
ObjectReference property VaultLoot07 auto
ObjectReference property VaultLoot08 auto
ObjectReference property VaultLoot09 auto
ObjectReference property Vaultloot10 auto
ObjectReference property Vaultloot11 auto
ObjectReference property Vaultloot12 auto
ObjectReference property Vaultloot13 auto
ObjectReference property Vaultloot14 auto
ObjectReference property Vaultloot15 auto
ObjectReference property Vaultloot16 auto

ObjectReference property GoldVault auto

MiscObject Property gold001 Auto

int count = 0

Event OnInit()
    VaultLoot = new ObjectReference[16]
    VaultLoot[0] = Vaultloot01
    VaultLoot[1] = Vaultloot02
    VaultLoot[2] = Vaultloot03
    VaultLoot[3] = Vaultloot04
    VaultLoot[4] = Vaultloot05
    VaultLoot[5] = Vaultloot06
    VaultLoot[6] = Vaultloot07
    VaultLoot[7] = Vaultloot08
    VaultLoot[8] = Vaultloot09
    VaultLoot[9] = Vaultloot10
    VaultLoot[10] = Vaultloot11
    VaultLoot[11] = Vaultloot12
    VaultLoot[12] = Vaultloot13
    VaultLoot[13] = Vaultloot14
    VaultLoot[14] = Vaultloot15
    VaultLoot[15] = Vaultloot16

    MaxValue = new Int[16]
    MaxValue[0] = 999
    MaxValue[1] = 4999
    MaxValue[2] = 9999
    MaxValue[3] = 24999
    MaxValue[4] = 49999
    MaxValue[5] = 99999
    MaxValue[6] = 199999
    MaxValue[7] = 299999
    MaxValue[8] = 399999
    MaxValue[9] = 499999
    MaxValue[10] = 649999
    MaxValue[11] = 749999
    MaxValue[12] = 999999
    MaxValue[13] = 1249999
    MaxValue[14] = 1499999
    MaxValue[15] = 1999999
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If akBaseItem == gold001
        count += aiItemCount
        DisplayPiles(count)
    EndIf
Endevent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    If akBaseItem == gold001
        count -= aiItemCount
        DisplayPiles(count)
    EndIf
Endevent

Function DisplayPiles(Int value)
    Int index = MaxValue.Length
    Int myActive = -1
    While index >= 0 
        ; scan from end to beginning (i.e. largest to smallest)
        index -= 1
        If (value > MaxValue[index]) && (myActive == -1)
            ; enable only the first highest value pile
            myActive = index
            VaultLoot[index].enable()
        Else
            ; disable all other entries if previously enabled
            If VaultLoot[index].isEnabled()
                VaultLoot[index].disable()
            EndIf
        EndIf
    EndWhile
EndFunction

 

 

I tried to use your script and it lit up with errors like crazy. 

all of the errors are saying:

-only arrays can be indexed

-variable MaxValue is undefined

 -type mismatch while assigning to a none (cast missing or types unrelated)

-none is not a known user-defined type

Link to comment
Share on other sites

Sorry, this is what happens when using an existing example that is unfortunately spread out on a fairly large script.  I forget the inital declarations for the arrays.

Add this to the empty state (i.e. with the properties)

ObjectReference[] VaultLoot
Int[] MaxValue

 

Add those two lines and the script will compile without error.  You'll need to test for proper function.

Link to comment
Share on other sites

Posted (edited)
On 3/22/2024 at 6:59 AM, IsharaMeradin said:

Sorry, this is what happens when using an existing example that is unfortunately spread out on a fairly large script.  I forget the inital declarations for the arrays.

Add this to the empty state (i.e. with the properties)

ObjectReference[] VaultLoot
Int[] MaxValue

 

Add those two lines and the script will compile without error.  You'll need to test for proper function.

It saved, but unfortunately it's still not working.

Here's how I set it up:

Spoiler
Scriptname EW_TreasuryScript extends ObjectReference  

ObjectReference property Vaultloot01 auto
ObjectReference property Vaultloot02 auto
ObjectReference property Vaultloot03 auto
ObjectReference property Vaultloot04 auto
ObjectReference property Vaultloot05 auto
ObjectReference property Vaultloot06 auto
ObjectReference property VaultLoot07 auto
ObjectReference property VaultLoot08 auto
ObjectReference property VaultLoot09 auto
ObjectReference property Vaultloot10 auto
ObjectReference property Vaultloot11 auto
ObjectReference property Vaultloot12 auto
ObjectReference property Vaultloot13 auto
ObjectReference property Vaultloot14 auto
ObjectReference property Vaultloot15 auto
ObjectReference property Vaultloot16 auto

ObjectReference property GoldVault auto

MiscObject Property gold001 Auto

ObjectReference[] VaultLoot

Int[] MaxValue

int count = 0

Event OnInit()
    VaultLoot = new ObjectReference[16]
    VaultLoot[0] = Vaultloot01
    VaultLoot[1] = Vaultloot02
    VaultLoot[2] = Vaultloot03
    VaultLoot[3] = Vaultloot04
    VaultLoot[4] = Vaultloot05
    VaultLoot[5] = Vaultloot06
    VaultLoot[6] = Vaultloot07
    VaultLoot[7] = Vaultloot08
    VaultLoot[8] = Vaultloot09
    VaultLoot[9] = Vaultloot10
    VaultLoot[10] = Vaultloot11
    VaultLoot[11] = Vaultloot12
    VaultLoot[12] = Vaultloot13
    VaultLoot[13] = Vaultloot14
    VaultLoot[14] = Vaultloot15
    VaultLoot[15] = Vaultloot16

    MaxValue = new Int[16]
    MaxValue[0] = 999
    MaxValue[1] = 4999
    MaxValue[2] = 9999
    MaxValue[3] = 24999
    MaxValue[4] = 49999
    MaxValue[5] = 99999
    MaxValue[6] = 199999
    MaxValue[7] = 299999
    MaxValue[8] = 399999
    MaxValue[9] = 499999
    MaxValue[10] = 649999
    MaxValue[11] = 749999
    MaxValue[12] = 999999
    MaxValue[13] = 1249999
    MaxValue[14] = 1499999
    MaxValue[15] = 1999999
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If akBaseItem == gold001
        count += aiItemCount
        DisplayPiles(count)
    EndIf
Endevent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
    If akBaseItem == gold001
        count -= aiItemCount
        DisplayPiles(count)
    EndIf
Endevent

Function DisplayPiles(Int value)
    Int index = MaxValue.Length
    Int myActive = -1
    While index >= 0 
        ; scan from end to beginning (i.e. largest to smallest)
        index -= 1
        If (value > MaxValue[index]) && (myActive == -1)
            ; enable only the first highest value pile
            myActive = index
            VaultLoot[index].enable()
        Else
            ; disable all other entries if previously enabled
            If VaultLoot[index].isEnabled()
                VaultLoot[index].disable()
            EndIf
        EndIf
    EndWhile
EndFunction

 

 

Edited by wilwhitt56
Link to comment
Share on other sites

Are you testing on a new game or one that has not seen the mod you are working on?  If the object that the script is attached to is already loaded and stored in the save file, not all script changes will be recognized.

Without actually seeing the setup and how everything hooks together, I cannot begin to speculate where it might be failing.  The script itself is sound.

Link to comment
Share on other sites

Posted (edited)
31 minutes ago, IsharaMeradin said:

Are you testing on a new game or one that has not seen the mod you are working on?  If the object that the script is attached to is already loaded and stored in the save file, not all script changes will be recognized.

Without actually seeing the setup and how everything hooks together, I cannot begin to speculate where it might be failing.  The script itself is sound.

I do a new game every time. I've made sure all of the properties are attached to their respected parts. The activator itself is a container with the mesh of a ledger, which has the script in it. The process itself is the object references are connected to static objects, aka chests, which are scattered around the chamber. These chests are the source for the various gold piles, jewels, shinies, etc that are in the room inself. These shinies are connected via Enable Parent to their respected chests. The chests though are set to initially disabled, making both the chest AND the loot connected to them invisible. When someone reaches the set goal for the first chest, the script triggers and makes the chest visible again, along with all connected loot.

Edited by wilwhitt56
Link to comment
Share on other sites

OnInit, in particular, will not run again when you update the script without starting a new game.

The console command "sqv EW_Treasury" should give you more info on the current state of your script variables (assuming the quest is called EW_Treasury").

Link to comment
Share on other sites

  • Recently Browsing   0 members

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