Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2008, 4:17 PM   #1
Apophis
Newbie
 
Join Date: Apr 2008
Posts: 16
Rep Power: 0 Apophis is on a distinguished road
PHP browser game resource question

How could i make a php browser game add resources on to every player per minute or hour.
So if they had money as a resource. how could i make it so that every hour they get 5 more money or something like that.

Thank you
Apophis.
Apophis is offline   Reply With Quote
Old May 22nd, 2008, 4:39 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: PHP browser game resource question

In general, there are two ways to do this:
  1. Set a cron job on your server to run a php script every 60 minutes which adds resources to all players.

    Advantages:
    • Easy to code
    • Very extendable

    Disadvantages:
    • If your server goes down during the time the cron job should occur, everyone misses the update
    • Not portable between all servers
    • Requires some degree of maintenance
    • Server stress is less uniformly distributed (peaks every hour)


  2. In every location where a user could possibly see someone's gold (or resources, or whatever you need to update), call a common function which checks how many hours ago the last update for this player was. Then make a number of updates equal to the amount of hours passed.

    Advantages:
    • Better integrated with the rest of your code
    • Becomes very simple to code if you already have a common function that returns the amount of gold someone has (simply place the check inside the common function)
    • Portable between all servers
    • Updates will still occur even if the server goes down momentarily
    • Server stress is more uniformly distributed (no abnormal peaks)

    Disadvantages:
    • Often more difficult to code
    • Potentially buggy if not done correctly
    • Any bugs can lead to very bad exploits and even necessary database restorations

Picking your weapon will completely depend on the server you're running, your long term plans for the project, and the amount of time and effort you want to commit.
Sane is offline   Reply With Quote
Old May 22nd, 2008, 5:15 PM   #3
Apophis
Newbie
 
Join Date: Apr 2008
Posts: 16
Rep Power: 0 Apophis is on a distinguished road
Re: PHP browser game resource question

A cron job sounds the best but how could i set one up?
Apophis is offline   Reply With Quote
Old May 22nd, 2008, 6:24 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: PHP browser game resource question

You will have to check your hosting plan's FAQ or talk to customer support. If they are a good hosting service, they should give you some from of cron setup in your control panel. If you're on a $3/month plan, then it's not so likely.
Sane is offline   Reply With Quote
Old May 22nd, 2008, 11:32 PM   #5
Apophis
Newbie
 
Join Date: Apr 2008
Posts: 16
Rep Power: 0 Apophis is on a distinguished road
Re: PHP browser game resource question

Thank you- i have now set one up
Apophis is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
installing php (beginners question) spekkio7 PHP 4 Jan 11th, 2008 10:06 AM
Hardware hacking question - Game ports mackenga Coder's Corner Lounge 1 Jun 11th, 2007 11:37 AM
Multiplayer Game Question Duck Existing Project Development 7 Jan 2nd, 2007 12:19 PM
Conflict Online (Browser Game) JavaMan Existing Project Development 7 Apr 28th, 2006 12:02 PM
Game Development question n3o_X Coder's Corner Lounge 0 Aug 5th, 2005 11:57 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC