Energy Regeneration

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.

Energy Regeneration

Postby Fireal » Sat Jan 04, 2020 10:57 am

Hey guys, I'm trying to figure out the best way to handle how energy restores for my game. At first I was just going to run a cron every 10 minutes adding 10 energy points to all users. However, that didn't seem right because certain users perform energy depleting actions at different times, and I would want the regeneration to be 10 minutes from their last action. With that said, how would you handle this?

Add 10 to a user's energy 10 minutes after they performed their last action.

Only thing I can think of is starting to use timestamps in the user tables. By the way I am using PHP/MySQL. :mrgreen:
User avatar
Posts: 11
Joined: Sun May 21, 2017 12:51 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Energy Regeneration

Postby a_bertrand » Mon Jan 06, 2020 7:22 am

You could have different ways to do it:
1) Have a cron every min which queries who did an action before 10 min ago => restore energy
2) When a page load you run basically the same as in point 1 (but doesn't require a cron, yet it may be run a lot more often, so you may need to have some way to make it less frequent or extremely quick)
3) When a page load for a given user, the check (of point 1) is done on his/her player only
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
New Worlds Engine creator
Posts: 1535
Joined: Mon Feb 25, 2013 8:46 am
Has thanked: 15 times
Been thanked: 23 times

Re: Energy Regeneration

Postby hallsofvallhalla » Sat Jan 11, 2020 11:07 am

yeah a timestamp in the table then every reload checks the timestamp but you could also not make it a static minute or amount, you could make each action affect the time and amount based on the action.
User avatar
Site Admin
Posts: 12023
Images: 13
Joined: Wed Apr 22, 2009 6:29 pm
Location: mobile, al
Has thanked: 11 times
Been thanked: 165 times
Blog: View Blog (3)

Return to Advanced Help and Support

Who is online

Users browsing this forum: No registered users and 1 guest