Deleted11438360User Posted May 25, 2016 Share Posted May 25, 2016 How would I go about doing an income script? I think I could use states, but I am pretty scared to mess with the game time functionality in the case something keeps looping or something silly. What I want is a script that can attach to my activator and then a button menu like this:If aiButton == 0 ;Collect Gold button. If TimePassed ;Add Gold to container. Else ;Not enough time passed. Elseif aiButton == 1 ;Stop Income button. Reset the TimePassed. Else ;Cancel button. Exit. EndIf EndifSo I sort of know what I want, but again, the way to do it simply and without issue is out of my realm. Can anyone please help me learn and give me a visual example if possible? Link to comment Share on other sites More sharing options...
Deleted11438360User Posted May 25, 2016 Author Share Posted May 25, 2016 (edited) Hmm would this work?If (aiButton == 0) aiButton = MessageMenu.Show() If aiButton == 0) ;Cancel ElseIf (aiButton == 1) RegisterForUpdateGameTime(24.0) Else UnregisterForUpdateGameTime() Endif Endif Event OnUpdateGameTime() Game.GetPlayer().AddItem(Gold001, 100) EndEvent Edit: Nah lol. Edited May 25, 2016 by Guest Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 25, 2016 Share Posted May 25, 2016 Incomplete code (use wiki to ensure proper syntax). Also need to add in your message box stuff.Float CurrentTime = 0.0 Float LastTime = 0.0 Int IncomeMult = 1 Float Property TimeToWait Auto ; 1.0 = 1 game day | 0.5 = 12 hours | etc... Bool TimePassed = false Event OnActivate() CurrentTime = Utility.GetCurrentGameTime() If LastTime == 0.0 LastTime = CurrentTime EndIf If CurrentTime - LastTime >= TimeToWait Float PassedTime = CurrentTime - LastTime Float PassedInstances = PassedTime / TimeToWait IncomeMult = Math.Floor(PassedInstances) TimePassed = true LastTime = CurrentTime ;advances last interaction time to current time for next interaction EndIf ;do message stuff ;use bool variable TimePassed to determine if gold should be given ;use integer IncomeMult to multiple the gold given in order to cover missed time periods ;reset bool variable TimePassed to false once gold is given EndEventThis would only give gold whenever the object was interacted with and enough time had passed. Calculations are in place to allow giving multiple time periods worth of gold (so player doesn't have to return every so often just to click on an object) Link to comment Share on other sites More sharing options...
Deleted11438360User Posted May 25, 2016 Author Share Posted May 25, 2016 Wow you are brilliant. I just sent you a PM too to thank you for before. This is really helping me learn new things. :happy: Link to comment Share on other sites More sharing options...
Deleted11438360User Posted May 25, 2016 Author Share Posted May 25, 2016 Quote use integer IncomeMult to multiple the gold given in order to cover missed time periods Could you give an example here please? I might have had too much Gin. The other stuff makes sense obviously. I just don't think I have ever had to multiply anything before. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 25, 2016 Share Posted May 25, 2016 Okay. Somewhere in your message box code where you have the option for the player to pick up their money...If TimePassed == true Int GoldToGive = GoldValue * IncomeMult PlayerRef.AddItem(Gold001,GoldToGive) TimePassed = false ;reset for next use IncomeMult = 1 ;reset for next use Else Debug.Notification("Not enough time has passed to earn income.") EndIfPlease note GoldValue is whatever value you are using for a single time period of income. I have no idea if you plan that to be a hard set value, a property or a value passed in from another script (like an MCM script) so I used simple text to represent where it would go. Link to comment Share on other sites More sharing options...
Deleted11438360User Posted May 25, 2016 Author Share Posted May 25, 2016 (edited) Great, thanks again. I'm using a Property set to 1.0 - or 24 hours as you put it for me. Edit: Drunk question I think I already know the answer too. Haha. Edited May 25, 2016 by Guest Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 25, 2016 Share Posted May 25, 2016 hmm... If you change a variable name within the script, the old variable would no longer be in use and its value would not automatically translate to the new variable name. So yes, it could break things. A change like that could sometimes mean that the user needs to start a new game or attempt creating a "clean save" (i.e. uninstall, save game, possibly run through a save game cleaner, install new version). Personally, I'd just do a new game. But there are others who know better the subtle workings of such changes and could give a better answer... Link to comment Share on other sites More sharing options...
Deleted11438360User Posted May 25, 2016 Author Share Posted May 25, 2016 I edited it out because I assumed the same. If you change a variable name and someone already has that variable stored, it does sound like it would certainly break everything. Link to comment Share on other sites More sharing options...
Recommended Posts