Jump to content

Simple Income Script?


Deleted11438360User

Recommended Posts

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
Endif

So 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

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

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
 
EndEvent

This 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

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.")
EndIf

Please 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

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

  • Recently Browsing   0 members

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