// Retrieve the world time and player's current energy upon logout
// Calculate the time difference between the current time and the last recorded logout time to determine the number of hours elapsed
ID:2945477
Sep 21, 4:52 pm
|
|
Over a decade ago, there was a browser-based caveman RPG that regenerated 5 energy points per hour, and I’m interested in replicating that mechanic using a world-time variable. Currently, I can only track the in-game time of day. How would I implement a system where a player regenerates 5 points of energy per hour, even while they are logged out?
|
Login to reply.
The above code is just a way to track how many hours since the player's last regeneration. If it has been at least an hour, then you do:
energy + = regen_count * 5.
last_time_regen = world.time
You'd also include this same check in a global loop that is constantly ticking.
This is napkin code, but it should get the gears turning, yeah?
EDIT:
Went to sleep and woke up realizing this code is flawed. the flw here is that let's say a person has logged on after being offline for 1.5 hours. They'd get 5 energy, but would then have to wait another hour when it should just be 30 minutes.
So instead, you'd want to keep track of the remainder and adjust the last_time_regen accordingly.