Jump to content

Trying to make a container that auto replenish itself


yian

Recommended Posts

Hello! I am in the process of creating a device that will provide you salt and flour automatically everyday. It needs to:

 

1) Give you 3 portions of salt and 3 portions of flour everyday.

2) Will not give you additional salt or flour if they are already present in the machine.

 

I think that if the container is set to respawn, whatever content was in the container will be rest so that is not a problem. However, I'm not quite sure how to set the respawn timer to a specific container. If it is not an easy task, I think I will just use the default respawn rate of a cell and triple the amount of the items.

 

Please help, thank you!

Edited by yian
Link to comment
Share on other sites

  • 1 month later...

Then a simple script will work.

 

Here's a script I had written for someone else who wanted an activator to give the player a reward item periodically but it puts the items directly in the player's inventory and has multiple options.

 

 

ScriptName RewardWithTimeoutScript extends ObjectReference
{Activating this object gives a reward only once per time period.}

LeveledItem Property RewardList Auto
{Required: A list of one or more items the player receives when activating this object.}

float Property TimeoutHours Auto
{Required: The amount of time, in game hours, before the player can get the reward again.}

Message Property TimeoutMsg Auto
{Optional: Message shown if player activates this object again during the timeout period.}

bool Property AllowNormalActivationDuringTimeout Auto
{Optional: Allow normal activation for furniture, containers, etc. during the timeout period.}

Event OnInit()
	BlockActivation()
EndEvent

Event OnActivate(ObjectReference akActionRef)
	if akActionRef == Game.GetPlayer() ; do not allow other characters to get the reward!
		GoToState("TimeoutActive")
		if TimeoutHours > 0
			RegisterForSingleUpdateGameTime(TimeoutHours)
		endif
		if RewardList
			akActionRef.AddItem(RewardList)
		endif
	endif
EndEvent

Event OnUpdateGameTime()
	GoToState("")
EndEvent

State TimeoutActive
	Event OnActivate(ObjectReference akActionRef)
		if TimeoutMsg
			TimeoutMsg.Show()
		endif
		if AllowNormalActivationDuringTimeout
			Activate(akActionRef, true)
		endif
	EndEvent
EndState

 

 

 

Here's the stripped down version that will put the items into the container and then open it. It still doesn't do quite what you wanted because if the player clicks on it or chooses to put other items in the container a full set of new items will still be added each day the player activates it. But the items only get added if the player actually opens the container each day. If the player skips a few days the container doesn't just keep accumulating more and more.

 

 

ScriptName RewardInContainerWithTimeoutScript extends ObjectReference
{Activating this object gives a reward only once per time period.}

LeveledItem Property RewardList Auto
{Required: A list of one or more items the player receives when activating this object.}

float Property TimeoutHours = 24.0 Auto
{Required: The amount of time, in game hours, before the player can get the reward again.}

Event OnInit()
	BlockActivation()
EndEvent

Event OnActivate(ObjectReference akActionRef)
	if akActionRef == Game.GetPlayer() ; do not allow other characters to get the reward!
		GoToState("TimeoutActive")
		RegisterForSingleUpdateGameTime(TimeoutHours)
		AddItem(RewardList)
		Activate(akActionRef, true)
	endif
EndEvent

Event OnUpdateGameTime()
	GoToState("")
EndEvent

State TimeoutActive
	Event OnActivate(ObjectReference akActionRef)
		Activate(akActionRef, true)
	EndEvent
EndState

 

 

 

And finally here's one specific to your need for 3 salt and 3 flour per day. It won't take away extras if the player stashes extra salt, flour, or other items in the container but it only adds enough salt and flour to bring the total up to 3 if there is less. (I haven't actually tried to compile it so there might be small errors, but it should work.)

ScriptName DailySaltAndFlourScript extends ObjectReference
{Keep the container stocked with a minimum of 3 salt and 3 flour each day.}

Ingredient Property SaltPile Auto

Potion Property BYOHFoodFlour Auto


Event OnInit()
	BlockActivation()
EndEvent

Event OnActivate(ObjectReference akActionRef)
	if akActionRef == Game.GetPlayer() ; do not allow other characters to get the reward!
		GoToState("TimeoutActive")
		RegisterForSingleUpdateGameTime(24.0)
		int n = 3 - GetItemCount(SaltPile)
		if n > 0
			AddItem(SaltPile, n)
		endif
		n = 3 - GetItemCount(BYOHFoodFlour)
		if n > 0
			AddItem(BYOHFoodFlour, n)
		endif
		Activate(akActionRef, true)
	endif
EndEvent

Event OnUpdateGameTime()
	GoToState("")
EndEvent

State TimeoutActive
	Event OnActivate(ObjectReference akActionRef)
		Activate(akActionRef, true)
	EndEvent
EndState

Link to comment
Share on other sites

  • Recently Browsing   0 members

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