Jump to content

Help with a "Sell from Chest" script?


XxLeafeater27xX

Recommended Posts

Hi all. I am working on a mod that allows the player to load certain items up into a custom container. I have it to where it will kick back any items without the necessary keyword so the container itself is fine. 

However, the next issue I have is setting up a script to actually "sell" those items within the container. 

 

The Method I want to use:

Essentially, you walk up to a ledger and use it as an activator. When you hit the correct menu button, I want it to check the contents of the chest, determine the value (in gold) of the the items in said chest, then remove them. Then it will disable the wagon (not the container itself, but the wagon to simulate something is being shipped off) and after 3 days, I want the wagon to re-appear and have the total value of gold determined from that shipment be placed into a separate container (a lockbox in the office). 

 

I know how to set up menus, messageboxes, how to register the game for a single gametime update, and how to enable and re-enable something afterwards. However, I cannot for the life of me determine how to get the script to determine the value of all goods in a container then place the determined total amount into a separate chest. 

 

Is anyone willing to help? I'm not sure if it is best to assign this as a script directly to the ledger you will be activating or if I should make a quest run to handle it and use the fragments section to enable/disable things or remove/add contents to containers. 

 

I am not using SKSE and would like to avoid doing so if possible so those on xbox could also download the mod. 

 

Thanks and any help would be greatly appreciated. 

Link to comment
Share on other sites

Well, SKSE would allow you to cycle through the contents of the container and build up the gold value in one fairly quick setting. But without SKSE, you'll need to use the OnItemAdded event to catch each item as it is added to the container and use GetGoldValue to obtain the gold value of the object.  Do note that enchanted items won't have the correct value, only the non-enchanted base value would be obtained.  You'll also need to use OnItemRemoved to catch whenever the player pulls an item out and adjust the value down.

You are in luck. I already have code that does this in one of my mods.  Its purpose is to show the value of all items stored within a container and adjust the value of an item in the player's inventory that represents that container. However, you'll need to adapt it for your needs as it will not work directly as-is.  But it can give you an idea of what you will need to do.

Function SetRepItemValue(Form RepItem,Form TheItem, Int mult, Bool DoAdd = true)
	If DoAdd == true
		LocalGoldValue = RepItem.GetGoldValue() + (TheItem.GetGoldValue() * mult)
	Else
		LocalGoldValue = RepItem.GetGoldValue() - (TheItem.GetGoldValue() * mult)
	EndIf
	RepItem.SetGoldValue(LocalGoldValue)
EndFunction

The above function is called within the OnItemAdded event:

SetRepItemValue(TheRepItem,akBaseItem,aiItemCount)

And called again within the OnItemRemoved event:

SetRepItemValue(TheRepItem,akBaseItem,aiItemCount,false)

In my scenario I add the gold value of the added item to the value previously set on the representation item.  You will instead need to store the value in a variable and modify that variable's value as necessary and then use that variable to assign the appropriate amount of gold in the correct location.

If you're adapting my function, you would replace the Form RepItem parameter with an integer, float or possibly a GlobalVariable.  And then replace its instance of use accordingly within the function.

Hopefully, this information is helpful.

 

Link to comment
Share on other sites

Thanks for the reply! I currently already have an onItemAdded event for the container (The function is to make certain crates/objects appear in the cart depending on the item added using keywords) and also has an OnitemRemoved function doing the inverse. 

So what I am taking from this is that I will need to add this function (after adaptation) to my current container. To clarify what you mean for my own understanding:

 

LocalGoldValue = RepItem.GetGoldValue() + (TheItem.GetGoldValue() * mult)

Thi

This function specifically should be set under the same function of the OnItemAdded in my script on my container

 

LocalGoldValue = RepItem.GetGoldValue() - (TheItem.GetGoldValue() * mult)

Whereas this should be added under my OnItemRemoved functions.

 

Am I understanding that correctly? The functions I'd be adding this to check keywords so it *Should* check any items with that keyword so long as I change RepItem to akBaseItem right?

Is there any way to store the GoldValue determined to be used on a different script/activator?

 

thank you for the help. 

 

 

W

Link to comment
Share on other sites

When the player adds items to the container, and you've determined that it matches your keyword(s), you'll then want to add that items gold value to the stored gold value.

When the player removes items from the container (as they can change their mind and move stuff back and forth while the container menu is open), you'll need to subtract the items gold value from the stored value provided it met your keyword criteria in the first place.

To break down my earlier example:

When adding: Current value = stored value + new item value

When removing: Current value = stored value - new item value

I had an item in player inventory whose value was modified hence I grabbed its current value and added the newly added item's value to a local variable that was then used to update the inventory held item.

Your case is a little bit different.  You are not using an inventory held item to display the value but rather a variable that stores it and is updated up or down as necessary.

Not sure how the rest of your code goes but I think it would be adapted as follows:

ScriptName myWagonScript Extends ObjectReference

Int property WagonItemValue = 0 Auto Hidden
Keyword Property AwesomeKeyword Auto

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If akBaseItem.HasKeyword(AwesomeKeyword)
    WagonItemValue += (akBaseItem.GetGoldValue() * aiItemCount)
    ;do other stuff
  EndIf
EndEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  If akBaseItem.HasKeyword(AwesomeKeyword)
    WagonItemValue -= (akBaseItem.GetGoldValue() * aiItemCount)
    ;do other stuff
  EndIf
EndEvent

Then the script that adds gold to the lockbox would have something like the following:

ObjectReference Property myLockbox Auto
MiscObject Property Gold01 Auto
myWagonScript Property MWS Auto ; CK will offer a dropdown that lists all valid objects with the myWagonScript attached, select the wagon

;inside the appropriate function or event
myLockbox.AddItem(Gold01,MWS.WagonItemValue) ; add the wagons stored item value as gold to the lockbox
MWS.WagonItemValue = 0  ; reset the wagons stored item value as the wagon was emptied

In case you are wondering the above bit also shows how to remotely access and modify a property on a separate script.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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