Code: Select all
+----+-------------+--------+--------------+--------+--------------+
| id | username | energy | energy_total | health | health_total |
+----+-------------+--------+--------------+--------+--------------+
| 1 | Opalelement | 10 | 10 | 10 | 10 |
| 2 | DougFresh | 10 | 10 | 10 | 10 |
+----+-------------+--------+--------------+--------+--------------+My idea was to make a database structure like the following:
Code: Select all
+----+-------------+--------+--------------+-------------+--------+--------------+-------------+
| id | username | energy | energy_total | energy_used | health | health_total | health_used |
+----+-------------+--------+--------------+-------------+--------+--------------+-------------+
| 1 | *********** | 10 | 10 | | 10 | 10 | |
| 2 | ********* | 10 | 10 | | 10 | 10 | |
+----+-------------+--------+--------------+-------------+--------+--------------+-------------+Then use a query to select the *_used fields and do "time() - *_used"
Then divide the result by however long I want the increment to be
After doing that I will just do something like [ICODE]UPDATE users SET energy=energy+$add_energy[/ICODE] because if it hasn't been enough time the $add_energy will be 0
That will of course be set to max out at the users energy_total
My questions are:
Would this be a good way to do this?
Is there a better way to do this?
Also, would this structure work instead and jsut compare everything to last_revoked?
Code: Select all
+----+-------------+--------+--------------+--------+--------------+--------------+
| id | username | energy | energy_total | health | health_total | last_revoked |
+----+-------------+--------+--------------+--------+--------------+--------------+
| 1 | *********** | 10 | 10 | 10 | 10 | |
| 2 | ********* | 10 | 10 | 10 | 10 | |
+----+-------------+--------+--------------+--------+--------------+--------------+