#1
  1. No Profile Picture
    XxX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Manchester, UK.
    Posts
    26
    Rep Power
    0

    Exclamation Online Game - Quick PHP/MySQL Question


    Hey there,

    I am quite desperate for help with this small PHP problem!

    I am creating an online game in PHP and have almost completed the script, although there are a few small things that I just can't seem to figure out.

    Within the game each user has a character, which is interactive (can be fed, played with, etc). Each character has it's own statistics (Hunger, Intelligence...).

    I have written the script that updates these stats if the user interacts with their character (feeds it) and that works great, but now I need to write the script that depreciates the stats regularly without the user logging in.

    To simplify, if the user does not log in for two weeks, their character will grow more and more hungry each day until it is starving.

    If anyone has any ideas on the best way to write this in php then I would be extremely grateful.

    I hope this makes sense...

    Thanks in advance,

    Ria x
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Horsham - England
    Posts
    303
    Rep Power
    28
    don't know exactly how to do them but could set up a cron job to run each day that does what you want. it can run a script to do this.

    or have a DB table that holds the last they feed their character and when they log back on update it then.
  4. #3
  5. No Profile Picture
    XxX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Manchester, UK.
    Posts
    26
    Rep Power
    0
    Originally Posted by twistedtwig
    don't know exactly how to do them but could set up a cron job to run each day that does what you want. it can run a script to do this.

    or have a DB table that holds the last they feed their character and when they log back on update it then.
    Thankyou for this - these are great ideas...you know what it's like when the answer is obvious but you have a coding overload...

    Thanks again
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    60
    Rep Power
    9
    you need a field in the database that records each time the user logs in

    then you need a php script to check if the user log in time is a long time ago(ask for help in php forum) and if so, increase their hunger etc


    mike
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Cumberland Md
    Posts
    4
    Rep Power
    0
    Just to throw this out there, as something i had done for my own game im working on, i had a page, that when i ran my website, i would open a sort of admin page for my site, this admin page had a feature that i had auto refresh that spot and run a certain script, i used javascript to do this to just simply refresh and keep rerunning the page. This allowed things to be incremented from time to time, such as if the page i have refreshes and increases a certain number by 1(or w/e) every hour, then have that effect things (such as in my case) i had it affect the amount of resources players generated useing buildings they had built. This allowed players to generate resources, while not being online to run the script.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    102
    Rep Power
    9
    For what he is asking doing it in PHP and then setting it up as a cron job would be the best thing. Unless you know another language like java or perl you could write a script to continually check, or just as a cron job.
    Don't forget you need to think about the future, so if you were to run checks on all your users through accessing a certain page it may time out or generate errors if you had tons of users. Or what happens if you go on vacation or get sick for a couple weeks? Then the "automation" won't happen.
    We Live; We Love. We Hate; We Die.

IMN logo majestic logo threadwatch logo seochat tools logo