Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Help] Regenerate "Health"

Joined
May 19, 2007
Messages
440
Reaction score
78
How I can create a Regeneration? It's kinda same as Travian's resources regaining.
I want in example a 10/100 HP to start regenerating itself like 11/100, 12/100, 13/100 in some time without requiring that the player is online. Something other methods than something that relates to time() function?

Of course it must be non-exploitable.

Thanks.
 
Custom Title Activated
Loyal Member
Joined
May 23, 2011
Messages
1,607
Reaction score
588
You could calculate how long they've been playing for during one session, and then multiply that by a small integer to get another number which then is added onto their current health. So basically, the longer they play, the more health they gain.

Another way is to calculate based on certain attributes (resistance to x (i.e poison)) could be a good one.
 
Joined
Jul 6, 2010
Messages
352
Reaction score
126
Yeah, if they aren't necessarily online, there's no need to do it gradually? On their next session it would appear gradual if you add it to their previous health.

You could use a unix timestamp (just a suggestion). Getting the difference between the times of their sessions (log off then next log on) then as Caustik said, multiplying it by the amount of health you want them to regain per second (or whatever) then adding it to their previous health upon their next session start
 
Junior Spellweaver
Joined
Sep 24, 2006
Messages
186
Reaction score
19
what about creating a cron job that updates all players health and run that every 10 seconds?
Tbh i have no idea if this is a good implementation, maybe someone else can reply on this? :D
 
Junior Spellweaver
Joined
Sep 24, 2006
Messages
186
Reaction score
19
but doesnt the way you specify, only update the players health, incase the player executes that code/loads the page.
Regenerating shouldnt be executed.
 
Junior Spellweaver
Joined
Sep 24, 2006
Messages
186
Reaction score
19
thought about the multiplayer concept? What if someone else plans to attack the player in a pvp battle while the player is offline?
If the player quits its session with 30 hp, the system should behave like if he was online on this matter imo.
 
Joined
Jul 6, 2010
Messages
352
Reaction score
126
How can a player be attacked if they are offline?

And if the player is offline, as said, there is no need to regenerate gradually as the user wouldn't see the gradual change but just a jump to a new hp level on their next login.

Example: I end my session with 34hp at 1:35, (assuming the regeneration is 1hp every 20 seconds) if I log back in 8 minutes later at 1:43, my HP would be 58hp, but I wouldn't have seen all the 1hp steps to get there (34hp... 35hp... 36hp...) So there would be no need to do It gradual, unless the regeneration is done whilst the user is online.
 
Junior Spellweaver
Joined
Sep 24, 2006
Messages
186
Reaction score
19
How I can create a Regeneration? It's kinda same as Travian's resources regaining.

In travian, players can be attacked while being offline, if I remember well, same for other browser games.
 
Joined
Jul 6, 2010
Messages
352
Reaction score
126
Wouldn't that mean that you'd have to be online 24/7 to prevent yourself from always being killed?

But yeah, if its that case, you could use a chron job, or looper, etc. depending on what language you're in
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Don't do it until the last possible second. That's how.

If something regenerates health CONSTANTLY, you calculate the effective health it has each time you need to use it, you don't use some cron job to update it every 5 minutes or something. Then whenever it's changed (after it's hit, etc), you update it in the database with the new value and when it was updated, and from there you can calculate the current HP at any time. You can even get your SQL query to return the current HP by using a little math in the query.

So if currentHp is 100 and max is 1000, and rate of gain is say 50/min, you store lastUpdated at some timestamp X. In the future, you get currentHp, then multiply rate of gain * (Y - X)/60 where Y = current timestamp.
 
Last edited:
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
I would put the equation in a getter method for the player.health field. It wouldn't matter which player is accessing that data, it would be loosely coupled with anything using it, and it could easily be used in such a way the player can see their health-rate increase in real-time.
This information is intended to be used in conjunction with jMerliN's answer.
 
Back
Top