Divide the amount you are adding by math.floor(result / 60)
then.
Thats for how long they left not for how much money they made in a minute.
result is how long they left am i correct?
local Result = os.time() - oldTime
local Earned = however_much_they_earned
print(Earned / (Result / 60))
Yeah, with Result being how long they were gone for, dividing the amount they’ve earned since they last played by the amount of minutes (Result / 60) will give you about how much they “made” each minute.
so track all the money that made? as “Earned”?
Yeah, you’d need that number if you want to get an average out of it, unless you want to do it periodically somehow every time they earn something, which may not be as efficient.
alright thanks
but wait if the player stayed for shorter they would get less money…
I was under the assumption the player was not ingame?
so in miners haven, you join the game you get money you leave you get that money every time you got money.
Not sure, I haven’t played the game myself. It really depends on what you’re trying to accomplish but I’m not sure I follow.
game is here if you wanna play it lol
If it’s dropper based, just do some quick math for each dropper and insert a value into the dropper that has the average money per minute. Do the same for all droppers. Then, do what @Rerumu said with the os.time
, saving it when they leave. Then, when they get back, you can do a quick calculation of ((os.time() - SavedTime)/60) * CashPerMinute
, with CashPerMinute
being the sum of all the droppers’ Average Cash/Minute values. Then, add the final earned cash to their current cash.
What information do you have? To calculate the average rate of income over time, you divide the total change in money by the total amount of time elapsed. Are you missing one of these components? If your problem is something else then you should explain what it is.
If we are speaking of miners haven I think they pick some delta time to calculate average earning over, which is stored as you leave and multiplied by the time since you left when you get back. That way the upgraders and any other tricks a player uses to raise their income is not lost as the formula merely accounts for what you did achieve as income rather than what you ‘theoretically could achieve’ with a given setup.
You calculate how much money someone makes in a minute by analysing the tycoon or whatever
The rest is very simple to set up, but calculating how much someone makes in a minute might be tricky depending on how you want to approach it
The thing with analysing a setup is that it does not account for how a setup is used; for instance launching ores through an upgrader that hangs in the air is virtually impossible to calculate theoretically and accurately. The solution is the tycoon itself taking an ‘agnostic’ approach, merely tracking the ores that are fed to a furnace by measuring their value and adding that to a particular time frame to calculate the average earnings within said frame. If you store the most recent average frame(s), you do not need to account for anything else and can multiply that value by the time the player was gone (although some factor to diminish it for not being actively at the place is likely required)
I assume the problem you have is the rates of the droppers are not uniform, but I assume they are all specified in seconds (ie, for every dropper they drop something x times every y seconds).
If so, we want to find the rate per second so that all the values can be compared.
For any given dropper, the normalized value ($ per drop per second) is simply just
local n = moneyPerDrop / timeBetweenDrops
(drop refers to generation of blocks. if you have a dropper that drops 2 blocks every second and each block is worth $3, then you get a $6 drop (3x2) every second, which n = 6 / 1 = 6
you would use a for loop to calculate ‘n’ for every single dropper in your game, and then add all individual n’s to find out what the total income for every dropper is per second.
With the sum of all n for every dropper, now you would just figure out how long they’ve been gone. Save the os.time() when they leave the game and when they rejoin fetch it again from datastore and subtract it from the current os.time(). We’ll get the time theyve been gone in seconds (note: could be off by an hour or so!) Multiply the time theyve been gone by the sum total of n’s for every dropper to get how much they wouldve made.
At least I think this is what you’re asking for.
figured it out, was able to do this by finding out how much cash was made in 1 second, making values in a folder named by os.time() and setting the value to the amount of cash. I would make sure there are always 60 values (1 for each second.) which would add up to one minute. I would add all the values together then divide by how meny values. That is the average amount of money per second. Then when a player joins, get how long they where gone for then * the seconds left by the averge money… and thats how much they made while they where gone!