How to get Time to affect the database?

Location of the Videos
Post Reply
Parisij
Posts: 22
Joined: Thu Oct 29, 2009 3:32 pm

How to get Time to affect the database?

Post by Parisij »

Okay here is what I want to do.

My goal is to have the player need to eat daily the day ending at 12am.

i made a hungry value in the database under player. and i think what needs to be done is have a code that alters this value at say 12am everyday to hungry then when the player uses say steak... this moves the value to not hungry?

but I have no idea how to have this value alter at the designated time everyday...

any ideas?

this is how it would look if this was a change from hungry to not hungry i think.

Where i would be using 0 and 1 to differ between hunger and not hungry.

Code: Select all

<?php
 if (isset($_GET['randid']))
    {
       $randid=$_GET['randid'];
       $iteminfo="SELECT * from inventory where randid='$randid'";
    $iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
    $iteminfo3=mysql_fetch_array($iteminfo2);

    if (!$iteminfo3['name'])
    {
    }
    else
    {

    $name = $iteminfo3['name'];
    $stats = $iteminfo3['stats'];
    $statadd = $iteminfo3['statadd'];
    $type = $iteminfo3['type'];

    if ($type == "food")
    {
       $newhunger = $statadd + $playerhunger;
       if ($newhunger > $playerinfo3['maxhunger'])
       {
        $newhunger = $playerinfo3['maxhunger'];
       }
        $updateplayer="update players set hunger='$newhunger' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");

        $updateitem="DELETE from inventory where name='$name' AND randid='$randid' limit 1";
      mysql_query($updateitem) or die("Could not delete item");
       
       $playerhunger = $newhunger;
     
      echo "Used " . $name . " and recovered " . $statadd . ".<br>";
    }

    }}

  ?>
<?php



User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: How to get Time to affect the database?

Post by hallsofvallhalla »

use crons, i have a video in the video section on how to use them, you can set it to run a script everyday at 12. Then just make a query that updates the updates all players and changes value of hunger.

you could also set it hourly for more realism ;)
Parisij
Posts: 22
Joined: Thu Oct 29, 2009 3:32 pm

Re: How to get Time to affect the database?

Post by Parisij »

Thanks...\

DIdnt actually watch that one... didnt know what crons was...

But thanks Ill watch that asap
Post Reply

Return to “Older Browser MMO Videos”