Jump to content

Photo

Script Help Needed for In home Player Treasury/Vault

vault ck script scripting onitemadded onitemremoved treasury skyrim creationkit gold

  • Please log in to reply
5 replies to this topic

#1
Brogdonc

Brogdonc

    Stranger

  • Premium Member
  • 9 posts

Hello all,

 

I've spent the past few weeks trying to learn the best way to go about scripting a chest inside one cell of a player home to control the enabling/disabling of 'Treasures' in another cell (player home vault),  determine based on the amount of Gold added or removed from that chest.  From what I've read and watched so far it seems like this should be a fairly simple task but no success :sad: .. 

 

Below is my best attempt thus far at getting a script to work as intended.  Everything compiles just fine but unfortunately with what I have only items attached to the marker for Gold >= 1000 will enable.  The debug message continues to fire no matter how much gold I put in the chest but the other markers are not displaying when their respective values are added.  The other issue is that the OnItemRemoved event doesn't seem to want to disable anything.  Once the 1000 gold marker items have displayed, removing all gold from the chest fires the Debug message for ("The treasury has been Depleted") but the maker still leaves the items enabled on the table.  I'm certainly still learning so I'm hoping anyone out there with some experience with this can take a look at my script and help identify what I'm missing.

 

Also I'm not sure if it makes a difference but I have the same chest with this script on it linked to another reference safe with the cloud chest script in Breeze Home.  My thought was that it would be pretty cool to be able to access the player vault from anyone of the main hold purchasable homes and still have objects inside the treasury impacted.  Not sure if that's possible but if so that would be ideal.  Thank you for the help!

 

Scriptname DBS_TreasuryDeposit extends ObjectReference  
 
ObjectReference Property GMarker1000 Auto
ObjectReference Property GMarker5000 Auto
ObjectReference Property GMarker10000 Auto
ObjectReference Property GMarker25000 Auto
ObjectReference Property GMarker50000 Auto
ObjectReference Property GMarker75000 Auto
ObjectReference Property GMarker100000 Auto
ObjectReference Property GMarker125000 Auto
MiscObject Property Gold001 Auto  
 
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
   If akBaseItem == Gold001 ;
     If aiItemCount >= 1000
     GMarker1000.Enable()
     debug.notification("The Treasury Has Increased")
     EndIf
 
      If aiItemCount >= 5000
      GMarker5000.Enable()
      debug.notification("The Treasury Has Increased")
      EndIf
 
      If aiItemCount >= 10000
      GMarker10000.Enable()
      debug.notification("The Treasury Has Increased")
      EndIf
 
     If aiItemCount >= 25000
     GMarker25000.Enable()
     debug.notification("The Treasury Has Increased")
     EndIf
 
     If aiItemCount >= 50000
     GMarker50000.Enable()
     debug.notification("The Treasury Has Increased")
     EndIf
 
     If aiItemCount >= 75000
     GMarker75000.Enable()
     debug.notification("The Treasury Has Increased")
     EndIf
 
    If aiItemCount >= 100000
    GMarker100000.Enable()
    debug.notification("The Treasury Has Increased")
    EndIf
 
    If aiItemCount >= 125000
    GMarker125000.Enable()
    debug.notification("The Treasury Has Increased")
    EndIf
  EndIf
EndEvent
 
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
   If akBaseItem == Gold001 ;
     If aiItemCount < 115000
     GMarker125000.Disable()
     debug.notification("The treasury has been Depleted")
     EndIf
 
     If aiItemCount < 85000
     GMarker100000.Disable()
     debug.notification("The Clan's Wealth has Decreased")
     EndIf
 
     If aiItemCount < 60000
     GMarker75000.Disable()
     debug.notification("The Clan's Wealth has Decreased")
     EndIf
 
     If aiItemCount < 40000
     GMarker50000.Disable()
     debug.notification("The Clan's Wealth has Decreased")
     EndIf
 
     If aiItemCount < 15000
     GMarker25000.Disable()
     debug.notification("The Clan's Wealth has Decreased")
     EndIf
 
     If aiItemCount < 7000
     GMarker10000.Disable()
     debug.notification("The Clan's Wealth has Decreased")
     EndIf
 
     If aiItemCount < 2500
     GMarker5000.Disable()
     debug.notification("The Clan's Wealth has Decreased")
     EndIf
 
     If aiItemCount < 500
     GMarker1000.Disable()
     debug.notification("The Clan Treasury has been Depleted")
     EndIf
   EndIf
EndEvent


#2
Brogdonc

Brogdonc

    Stranger

  • Premium Member
  • 9 posts

EDIT:  

 

I did some more testing this morning and found that the script is actually working just not as intended.   

 

Seems as though the script doesn't count the amount of gold in the chest when gold has been added or removed... Rather it counts the amount deposited or removed at the time the object was activated.  I'm assuming this is why if I have > 5000 gold in the chest but added it increments < 5000 the objects don't display.  But when I activate the chest and actually add 5k gold or more it displays those objects.   Seems like the same is true for the Disable event.  It only removes the Marker for the objects tied to 1000 gold If I remove a value less than 500... :(  which is why even though I have over 500 gold in the chest... taking out 200 gets rid of the objects...

 

I'm assuming I need to change my script to simply count how much gold is in the chest when the Event starts.  Maybe an OnClose event? Not sure how that script would look though.



#3
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 8,837 posts

You are comparing the amount of gold to the amount that is added or removed that is why it only deals with the amounts that you add rather than the entire amount. If you want it to work with the entire quantity, you could use the OnClose event or you can simply perform a GetItemCount check on the gold item.  Or both.

 

Example using the OnItemAdded and OnItemRemoved events

Spoiler

 



#4
Brogdonc

Brogdonc

    Stranger

  • Premium Member
  • 9 posts

Thank you for your reply!

 

 

I gave that code a shot only tweaking the spelling for Quantity so it would compile.  The enable part of the event now works flawlessly  :D  counting the total amount of gold in the container before displaying the objects in the next cell.  

 

Although For some reason the objects still don't want to disable when gold is removed. Now when All the gold is removed from the chest, no matter how much gold was in the chest or how many of the markers are enabled they all continue to display.  Maybe there is something I should be adding to that half of the event or the properties?

 

 

To add a side note: 

 

I was able to get a working script on a ledger as an activator to allow the player to deposit or withdraw gold in increments of 1k 5k and 10k using a small menu system.  (I got annoyed that I couldn't take smaller amounts of gold straight from the chest itself).  I thought maybe the objects weren't disabling because too much gold is being removed from the chest at once but that doesn't seem to make the markers disappear either.  

 

I added the code for the working menu in case anyone finds it useful.

 

The Code:

 

Spoiler



#5
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 8,837 posts

Sorry about the typo, didn't even see that.

 

Think I know what is wrong with the disabling.  I had the code processing in an either/or type of sequence so that only one could be true.  While that can work for the adding of gold, the taking away of gold should check all displays to ensure that all that need to be disabled get disabled. 

 

I don't know how your displays are set up.  If they are all supposed to be visible when the highest amount has been added, then OnItemAdded event should probably have similar adjustment. 

 

At any rate, modified code for the disable portion.  See if it works.

Spoiler

 

FYI - Any more levels than what is here already and you may want to consider using index matching arrays.  One of integers for your levels in gold and one for the displays to enable or disable.



#6
Brogdonc

Brogdonc

    Stranger

  • Premium Member
  • 9 posts

That adjustment worked beautifully!  Can't thank you enough for that!  I was thinking about adding more levels as I continue to come across resources that really stand out.  I will definitely look into index matching arrays if the list needs to grow.







Also tagged with one or more of these keywords: vault, ck, script, scripting, onitemadded, onitemremoved, treasury, skyrim, creationkit, gold

Page loaded in: 1.095 seconds