I’m making a “Steal a” game and I want to add offline cash, but I don’t know how to calculate it. I know you need their CPS and time since last join, but I don’t know exactly how.
When the player leaves the game, add the current os.time() to their datastore.
When they rejoin, you do os.time() - TIME_IN_DATASTORE to calculate the time they were offline (in seconds).
To calculate the money this would earn, you would need to look at whatever object/things they currently have, and how much each of them earns per second (Money / Time). You would then sum all the earnings per second, and then multiply it by the offline time.
The games seem to have a cap or divide the earnings, because some things that would earn around 8 billion in around an hour, would be the earnings after a day of not playing.
If you want to set a cap on the time they can be offline, then you would do something like
local Cap = 3600 * 24 -- 1 day
local TimeOfflineRAW = os.time() - TIME_IN_DATASTORE
local TimeOffline = math.clamp(TimeOfflineRAW, 0, Cap)
And if they divide the earnings - just add / 5 (or some other value) in the money calculation
They most likely do Indeed divide the earnings. I believe most AFK/Offline games do that, as I know of games that have an “Offline Earnings Multiplier”. What Seargent is saying is good.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.