Jump to content

How could i do this ? Give me some ideas


adicrst

Recommended Posts

Something bugs me for some time and i want to know how could i create PHP script that does this:Every game (i'm talking about browser based games) have HP (health points). Let's say that the max HP is 10. From some reasons, the user's HP drops to 5, so he has only 5 more left.Now, my question is how could i make a script that every minute that passes, his HP to increase by 1 point. So if 2 minutes pass, his HP increases from 5 to 7, but it doesn't go beyond 10 (that is maxHP).I have the fallowing idea:using CronJob, make a script like this to execute itself every 1 minute:* extract all user's HP that is < then maxHP* add 1 to the previous value* update the database with the new HP valueDoesn't this technique stress the database, considering that i make every minute hundred of queries if i have hundred of members in the game ?How could i find another solution ? Something based on the user, like everytime he refreshes his profile to know what was his last activity time and what is the current time and to make a difference and see how many minutes have passed and add to his HP the amount of points, but not to go over the maxHP. But how do i save his last activity time and the time he makes a refresh (refresh means he made another activity) and see how much points to add ?

Link to comment
Share on other sites

The other solution is that every time the script runs, record the current time and add all the health points based on how many minutes passed since last time that was recorded.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...