Resources update
-
- Posts: 4
- Joined: Tue Aug 23, 2011 12:31 am
Resources update
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?
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Resources update
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.
-
- Posts: 4
- Joined: Tue Aug 23, 2011 12:31 am
Re: Resources update
Do you have any tutorials showing a Cron, as I'll clueless with that...
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
-
- Posts: 4
- Joined: Tue Aug 23, 2011 12:31 am
Re: Resources update
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
I dont want to pay for hosting atm
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Resources update
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.
All a cron does is run a php file. Just find a way to auto run that file for now.
Re: Resources update
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
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
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Resources update
Very nice! I actually had no clue that MySQL had something like that built-in.
The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Resources update
very nice info. Thanks