First of all, I apologize if this sort of question has been asked before. And for the lengthy post.
I have a bit of a two part question. I am the author of a mod named "Heljarchen Farm" where you can build up an abandoned farm and can set up a small farming business. The farm allows you to grow crops and earn income from the farming business.
As of right now I am looking at reworking the income system. The way my current system works is that after five days pass in-game, you can collect the farms earnings (gold). However, gold does not accumulate over time. Because of this, the player has to come back every five days to retrieve the income and 'refresh' the earnings system.
While I like this system, it would be nice if gold accumulated without having to check back at set periods of time. Furthermore, some people who have been using the mod so far have reported that the script is breaking and after a period of time they haven't been able to collect gold.
I'm at a loss as to what the problem is as I'm still a bit of a noob to scripting and modding (I'm not a programmer, I have a degree in business lol). I suspect that something is interfering with the script for some reason and causing it to malfunction, but I'm not 100% why or how it's happening. Or, how to fix it. I'll post a snippet of a portion of the script:
If SKHFFarmHireFarmersXMarker.IsDisabled()
Debug.MessageBox("Farmers must be hired before you can make money with your farm.")
ElseIf Count == 0
If SKHFFarmProfitBufferXMarker.IsEnabled()
Debug.MessageBox("Farm earnings not yet available. Come back later.")
Else
SKHFFarmProfitBufferXMarker.Enable(False)
Debug.Notification("Farm revenue script activated.")
Utility.WaitGameTime(120)
Count = Count + 1
SKHFCPFarmXMarker.Enable()
Debug.Notification("Farm earnings available.")
EndIf
ElseIf Count == 1
SKHFFarmProfitBufferXMarker.Disable(false)
Game.GetPlayer().AddItem(Gold001, 800, False)
SKHFMilkCrateC.Reset()
SKHFEggCrateC.Reset()
SKHFCPFarmXMarker.Disable()
Count = Count - 1
SKHFFarmProfitBufferXMarker.Enable()
Debug.MessageBox("Gold collected. Come back in 5 days for the next batch of farm earnings.")
Utility.WaitGameTime(120)
Count = Count + 1
SKHFCPFarmXMarker.Enable()
Debug.Notification("Farm earnings available.")
EndIf
With that said, I came up with an alternative system that would allow income to accumulate over time (without having to come back to the farm frequently). I basically used the automatic light switch script posted on the Creation Kit Wiki (Made by Cipscis I think) and repurposed it to add gold to a chest instead of switching on/off lights.
Overall the script works well, however there is one thing I've been having trouble with. Basically, I'd like an option to turn this off. I figured that this could be accomplished by having a third state (an 'inactive' state which does nothing) and selecting a menu option to go to this state. But whenever I select this option, gold still accumulates. What am I doing wrong? I'll post a portion of the script here so you can take a look at it:
Menu()
EndEvent
Function Menu(int aiButton = 0)
aiButton = SKHFTestEarningsMenu.Show()
If aiButton == 0
If (GetCurrentHourOfDay() > EarningsAddTime)
GoToState("EarningsAdd")
Else
GoToState("EarningsNull")
If aiButton == 1
GoToState("Inactive")
If aiButton == 3
EndIf
EndIf
EndIf
EndIf
EndFunction
State EarningsAdd
Event OnBeginState()
SKHFFarmEarningsSafe.Additem(Gold001, 150)
RegisterForSingleUpdateGameTimeAt(EarningsNullTime)
EndEvent
Event OnUpdateGameTime()
GoToState("EarningsNull")
EndEvent
EndState
State EarningsNull
Event OnBeginState()
RegisterForSingleUpdateGameTimeAt(EarningsAddTime)
EndEvent
Event OnUpdateGameTime()
GoToState("EarningsAdd")
EndEvent
EndState
State Inactive
Event OnBeginState()
; Do nothing
EndEvent
EndState
However while I like this system too, I'm not sure if this will be more stable or not than my other income system. Since it adds gold every day, could this cause save game bloat? I read that you should use RegisterForSingleUpdateGameTIme instead of RegisterForUpdate as it can cause problems. But I'm not sure if having a script like this could be problematic as well.
Any insight/advice/help would be appreciated, thanks.