Page 1 of 1

Resources update

Posted: Sun Oct 02, 2011 8:51 pm
by willbill161
I'm making my game at the moment in PHP, and if you have 200 metal, you can buy a refinery, which instantly gives you 350 metal after, but how would I make it so that instead of 1 large sum, it gives you so much metal/hour depending on the level of the building?

Re: Resources update

Posted: Sun Oct 02, 2011 9:11 pm
by hallsofvallhalla
you could run a cron that would update hourly. Have a table that defines all the buildings then select from it where your building equals that building, update metal the amount it defines.

Re: Resources update

Posted: Sun Oct 02, 2011 9:20 pm
by willbill161
Do you have any tutorials showing a Cron, as I'll clueless with that...

Re: Resources update

Posted: Mon Oct 03, 2011 12:26 am
by hallsofvallhalla

Re: Resources update

Posted: Tue Oct 04, 2011 5:34 pm
by willbill161
Thanks for that vid, but are there any ways to do it in a .PHP file, which i could make in e.g Notepad++?
I dont want to pay for hosting atm :P

Re: Resources update

Posted: Tue Oct 04, 2011 6:59 pm
by hallsofvallhalla
i have seen people use windows to set a program to run at certain times. All you have to do is have it open internet explorer and go to the page.

All a cron does is run a php file. Just find a way to auto run that file for now.

Re: Resources update

Posted: Fri Feb 01, 2013 6:03 am
by Briermay
if your using MySQL as the database this is done easily without using a cronjob. mysql supports doing it within itself its called an event scheduler. You just do similar to this:

CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
UPDATE myschema.mytable SET mycol = mycol + 1;

change myevent to something like updatewood
change interval to how ever often you want I used 5mins when I was working on a game in the past
change myschema to your database name
change mytable to the table that contains the city resources
change mycol to the field that holds the resource value

this will even run when the user is offline. also useful for battles as it runs whether either user is online or offline in real-time.

here is the MySQL help page for the event system:

http://dev.mysql.com/doc/refman/5.1/en/events.html

Re: Resources update

Posted: Fri Feb 01, 2013 11:06 pm
by Jackolantern
Very nice! I actually had no clue that MySQL had something like that built-in. :D

Re: Resources update

Posted: Mon Feb 04, 2013 10:35 pm
by hallsofvallhalla
very nice info. Thanks