[SOLVED] Resource per hour
[SOLVED] Resource per hour
For my browser game, im making a resource system, with wood, food and stone. The resources are gain bases on the building level, per hour: lumber yard is at 5, so i want to get 500 wood per hour. Can anyone explain me how to make that system?
Last edited by noswear on Thu Apr 28, 2011 12:44 pm, edited 1 time in total.
-
- Posts: 261
- Joined: Wed Apr 28, 2010 8:35 am
Re: Resource per hour
assuming you've already got a grid map system... I'd go with as a pure example:
1. create table called mines (mineid, mapr, mapc, minename, mineamount)
2. insert into mines table new mine at x,y coords on the map, set default amount
3. set up a cron to update the mines table, set mineamount=mineamount+whatever, and set the cron to execute every hour? or such.
1. create table called mines (mineid, mapr, mapc, minename, mineamount)
2. insert into mines table new mine at x,y coords on the map, set default amount
3. set up a cron to update the mines table, set mineamount=mineamount+whatever, and set the cron to execute every hour? or such.
Re: Resource per hour
Yes i have a grid map system, but thats not what im saying. I want something like Travian or Ikariam, to have resources per hour based on the building level.
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Resource per hour
thats with the time function...
i want it too but i want to make like a job and be payed for like 1 hour.
i want it too but i want to make like a job and be payed for like 1 hour.
Re: Resource per hour
Use timestamps. You can calculate offsets based on time right? Like 60*60 is 1 hour ( 60 seconds * 60 minutes = 3600 secs == hour ) and thus you know how many you should gain. This is based on hours, but ikariam and travian are minute based ( which is better )
You should have a last_update_time and a update function which checks the time every minute, if more then 60 seconds ( or 1 hour ) have passed since the last_update_time, you can update your resources for the player and once they have been updated, change the last_update_time to the current timestamp.
You should have a last_update_time and a update function which checks the time every minute, if more then 60 seconds ( or 1 hour ) have passed since the last_update_time, you can update your resources for the player and once they have been updated, change the last_update_time to the current timestamp.
Re: Resource per hour
Thanks for the tip, its done and working
once i finish the system, ill upload it to the game 

