Page 1 of 1

[SOLVED] Resource per hour

Posted: Wed Apr 27, 2011 8:47 am
by noswear
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?

Re: Resource per hour

Posted: Wed Apr 27, 2011 10:21 am
by ConceptDestiny
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.

Re: Resource per hour

Posted: Wed Apr 27, 2011 10:57 am
by noswear
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.

Re: Resource per hour

Posted: Wed Apr 27, 2011 12:36 pm
by vitinho444
thats with the time function...
i want it too but i want to make like a job and be payed for like 1 hour.

Re: Resource per hour

Posted: Wed Apr 27, 2011 3:36 pm
by Xaleph
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.

Re: Resource per hour

Posted: Thu Apr 28, 2011 12:43 pm
by noswear
Thanks for the tip, its done and working :D once i finish the system, ill upload it to the game ;)