Hey, what I was wondering is if anyone has a stable way of calculating a persons offline time. That's pretty vague, so let me give an example:
"You log in for the first time and your var/Cash is set to 100. Now from this point on, your 'Cash' will increase by 10% every hour, even if you are offline. So if you log in again two hours later, your 'Cash' will be 121 as it has increased by 10% for two hours."
I hope that clears things up a lot better. Now I do not care about the method of adding the 10%, what I am looking for is how to figure out how long they have been offline. I have experimented with using timestamps when a user logs in and out, calculating the difference and finding how long they have been offline; but to no avail.
Without this, the core aspect of my game will fall apart, so I appreciate any help with this.
ID:272427
![]() Jul 8 2008, 8:08 am
|
|
![]() Jul 8 2008, 8:21 am
|
|
Make a temporary mob where you logged off, and give the Cash to it. Then when you log back in, transfer the cash from the temp. mob to you.
|
This would work, although if the game itself were to go offline, you would not gain the money when it comes back up. This is the very reason why i tried using timestamps.
|
Danny Roe wrote:
Hey, what I was wondering is if anyone has a stable way of calculating a persons offline time. That's pretty vague, so let me give an example: While I'm sure there's probably a more mathematically convenient way of doing this, what I would do is give each player a variable called last_online, and when the player logs out, their last_online var is set to world.realtime, then saved in the player's savefile. Now, when the player logs in, you can find out how much time has elapsed since they were last online by checking:
var/time_offline = world.realtime - src.last_online
The remaining value will be (roughly, and most likely inaccurate by a few seconds) the number of 1/10th seconds that the player was offline for. So then divide the remaining value by 36000 to find out roughly how many hours the player was offline for. After that, if you insist on multplying the player's value by 10% for every hour that they were offline, then you could so something like this: mob/proc/IncValueByHours(time_offline) Although I imagine doing it that way could create a brief game-wide pause if the player has been offline for a good year or so. Plus those values are going to reach astronomical sizes after a few hours. Personally I'd just ADD to the player's value every few hours, then you can just calculate <code>hours * increase</code> and it would be much faster. |
Thank you Foomer, I will test this out when I get the chance. As for the equation, it was only an example to describe what I wanted and I will not be using it. What will roughly happen is that the time_offline variable will be made into minutes and added to another variable. That is about as far as the time_offline variable will go.
|
Foomer wrote:
mob/proc/IncValueByHours(time_offline) The easy way to do this mathematically is to replace the loop with: value *= 1.1 ** round(hours) Since x to the power N (x**N) is the same a multiplying x by itself N times. Note the round() to ensure "hours" is an integer, since exponentiation by a real number is valid, but not what you want. |