Jump to content

Script Help Needed for In home Player Treasury/Vault


Brogdonc

Recommended 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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

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 OnInit()
  AddInventoryEventFilter(Gold001)
EndEvent
 
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  Int Quantity = Self.GetItemCount(Gold001)
  If EnableTreasure(Quanity,125000,GMarker125000)
  ElseIf EnableTreasure(Quanity,100000,GMarker100000)
  ElseIf EnableTreasure(Quanity,75000,GMarker75000)
  ElseIf EnableTreasure(Quanity,50000,GMarker50000)
  ElseIf EnableTreasure(Quanity,25000,GMarker25000)
  ElseIf EnableTreasure(Quanity,10000,GMarker10000)
  ElseIf EnableTreasure(Quanity,5000,GMarker5000)
  ElseIf EnableTreasure(Quanity,1000,GMarker1000)
  EndIf
EndEvent
 
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  Int Quantity = Self.GetItemCount(Gold001)
  If DisableTreasure(Quanity,115000,GMarker125000)
  ElseIf DisableTreasure(Quanity,85000,GMarker100000)
  ElseIf DisableTreasure(Quanity,60000,GMarker75000)
  ElseIf DisableTreasure(Quanity,40000,GMarker50000)
  ElseIf DisableTreasure(Quanity,15000,GMarker25000)
  ElseIf DisableTreasure(Quanity,7000,GMarker10000)
  ElseIf DisableTreasure(Quanity,2500,GMarker5000)
  ElseIf DisableTreasure(Quanity,500,GMarker1000)
  EndIf
EndEvent
 
Bool Function EnableTreasure(Int Gold, Int Display, ObjectReference Treasure)
  If Gold >= Display
    Treasure.Enable()
    Debug.Notification("The Treasury has increased")
    Return True
  Else
    Return False
  EndIf
EndFunction
 
Bool Function DisableTreasure(Int Gold, Int Display, ObjectReference Treasure)
  If Gold < Display
    Treasure.Disable()
    If Gold >= 500
      Debug.Notification("The Clan's wealth has decreased")
    Else
      Debug.Notification("The Clan's Treasury has been depleted")
    EndIf
    Return True
  Else
    Return False
  EndIf
EndFunction

Note, I put the repetitive code inside functions and simply call it as needed. Also, the inventory event filter allows only the designated object (gold in this case) to trigger the OnItemAdded and OnItemRemoved events. This would help reduce processing if the player opted to store gems and jewels in the container.

 

 

Link to comment
Share on other sites

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:

 

Message Property DBSLedgerMenu Auto
Message Property DBSLedgerWithdrawMenu Auto
Message Property DBSLedgerDepositMenu Auto

ObjectReference Property DBSWorldGoldChest Auto

MiscObject Property Gold001 Auto

Event OnActivate(ObjectReference akActionRef)
Menu()
EndEvent

Function Menu(int aiButton = 0)
aiButton = DBSLedgerMenu.Show()
If aiButton == 0

ElseIf aiButton == 1
aiButton = DBSLedgerDepositMenu.Show()
If aiButton == 0

ElseIf aiButton == 1 ; 1000
If (PlayerRef.GetItemCount(Gold001) >= 1000)
PlayerRef.RemoveItem(Gold001, 1000)
debug.notification ("1000 Gold has been Deposited")
DBSWorldGoldChest.Additem(Gold001, 1000)

Else
debug.notification ("You don't have enough Gold")
EndIf
ElseIf aiButton == 2 ; 5000
If (PlayerRef.GetItemCount(Gold001) >= 5000)
PlayerRef.RemoveItem(Gold001, 5000)
debug.notification ("5000 Gold has been Deposited")
DBSWorldGoldChest.Additem(Gold001, 5000)

Else
debug.notification ("You don't have enough Gold")
EndIf
ElseIf aiButton == 3 ; 10000
If (PlayerRef.GetItemCount(Gold001) >= 10000)
PlayerRef.RemoveItem(Gold001, 10000)
debug.notification ("10000 Gold has been Deposited")
DBSWorldGoldChest.Additem(Gold001, 10000)

Else
debug.notification ("You don't have enough Gold")
EndIf
EndIf
Elseif aiButton == 2
aiButton = DBSLedgerWithdrawMenu.Show()
If aiButton == 0 ;

ElseIf aiButton == 1 ; 1000
If (DBSWorldGoldChest.GetItemCount(Gold001) >= 1000)
PlayerRef.Additem(Gold001, 1000)
debug.notification ("1000 Gold has been Withdrawn")
DBSWorldGoldChest.Removeitem(Gold001, 1000)

Else
debug.notification ("Not enough gold in the Treasury")
EndIf
ElseIf aiButton == 2 ; 5000
If (DBSWorldGoldChest.GetItemCount(Gold001) >= 5000)
PlayerRef.Additem(Gold001, 5000)
debug.notification ("5000 Gold has been Withdrawn")
DBSWorldGoldChest.Removeitem(Gold001, 5000)

Else
debug.notification ("Not enough gold in the Treasury")
EndIf
ElseIf aiButton == 3 ; 10000
If (DBSWorldGoldChest.GetItemCount(Gold001) >= 10000)
PlayerRef.Additem(Gold001, 10000)
debug.notification ("10000 Gold has been Withdrawn")
DBSWorldGoldChest.Removeitem(Gold001, 10000)

Else
debug.notification ("Not enough gold in the Treasury")
EndIf
EndIf
EndIf
EndFunction

 

Link to comment
Share on other sites

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.

 

 

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  Int Quantity = Self.GetItemCount(Gold001)
  DisableTreasure(Quantity,115000,GMarker125000)
  DisableTreasure(Quantity,85000,GMarker100000)
  DisableTreasure(Quantity,60000,GMarker75000)
  DisableTreasure(Quantity,40000,GMarker50000)
  DisableTreasure(Quantity,15000,GMarker25000)
  DisableTreasure(Quantity,7000,GMarker10000)
  DisableTreasure(Quantity,2500,GMarker5000)
  DisableTreasure(Quantity,500,GMarker1000)
EndEvent

Function DisableTreasure(Int Gold, Int Display, ObjectReference Treasure)
  If Gold < Display
    Treasure.Disable()
    If Gold >= 500
      Debug.Notification("The Clan's wealth has decreased")
    Else
      Debug.Notification("The Clan's Treasury has been depleted")
    EndIf
  EndIf
EndFunction 

Spelled quantity correct this time :tongue:

 

 

 

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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