Resources update

Videos around the RTS tutorial series
Post Reply
willbill161
Posts: 4
Joined: Tue Aug 23, 2011 12:31 am

Resources update

Post 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?
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Resources update

Post 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.
willbill161
Posts: 4
Joined: Tue Aug 23, 2011 12:31 am

Re: Resources update

Post by willbill161 »

Do you have any tutorials showing a Cron, as I'll clueless with that...
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Resources update

Post by hallsofvallhalla »

willbill161
Posts: 4
Joined: Tue Aug 23, 2011 12:31 am

Re: Resources update

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Resources update

Post 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.
Briermay
Posts: 1
Joined: Fri Feb 01, 2013 5:55 am

Re: Resources update

Post 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
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Resources update

Post by Jackolantern »

Very nice! I actually had no clue that MySQL had something like that built-in. :D
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Resources update

Post by hallsofvallhalla »

very nice info. Thanks
Post Reply

Return to “Browser based RTS Videos”