SilverFox1405241541 0 Report post Posted May 23, 2007 okay I'm finally going to add my first timer into the game. So I'll read it and edit this post with any feedback.Thanks. Share this post Link to post Share on other sites
miCRoSCoPiC^eaRthLinG 0 Report post Posted May 24, 2007 Ahm. Yes, I also have this question in mind. I have a beta-game (not yet finished) and I'm planning on making a mana system (simillar to Marcoland.com) wherein the mana refreshes every day. I'm not sure how to set it like that. (Am I allowed to ask questions as well?)The Mana refreshing is probably done through a cron job.. i.e. a separate SQL script that executes at a prefixed time (say 12:00am / 0:00 hours) and simply stuffs the mana field in the character stats table with the full value. I don't see any other easy way of doing it with PHP. If it's a function built into the game - I don't see how it'll execute on the exact time...Do I put a time stamp with the now() function that m^e has said and put an if statement when the time is equal?Yeah. Pretty much so. NOW() will automatically insert the current timestamp (the moment NOW() is executed) of the server into the DB. To calculate whether the user really waited out the required time... you can always use another call to NOW() and use the timestamp you get to perform a difference with the old timestamp stored in the databse. Then simply use an if statement to compare the differential value with the desired result and act accordingly. Share this post Link to post Share on other sites
lonelym 0 Report post Posted May 24, 2007 So... I will create an insert to table query, wherein the data's value is now(). I then create a javascript that would show the time remaining. What I don't understand is the part where you explain calling the new now() and comparing it to the old one. Would the code be something like: $timenow = now();$query = "SELECT tablename refreshtime where columnid = 1";$result = mysql_query($query);if ($result) { $row = mysql_fetch_assoc($result); $timetorefresh = $row['columnname']; if ($timenow => $timetorefresh){ $query1 = "UPDATE tablename SET mana = maxmana"; $result1 = mysql_query($result1); if ($result1){ print "Mana is restored."; } }}First, I don't know where to put this code. If I did know where to put it, their mana will refresh again and again unless I change the value of the time in the column refreshtime. I'm so confused, I'm trying to learn so many stuff. T__TAnother question,Would the if statement work even if the page is not executed because no one is online?I'm really sorry for the bother, it's just that I enjoy learning to script so much. I enjoy seeing people having fun in the games that I play, and I like it when my parents approve with what I do. Just tell me if I'm asking too much and I will zip my lips. Share this post Link to post Share on other sites
SilverFox1405241541 0 Report post Posted May 24, 2007 (edited) time1 = now(); // this is the time at th beginning of the execution $result = mysql_query("SELECT * where columnid =' 1'"); // always enclose queries in (). Also for now since your a starter use * for all. $r= mysql_fetch_array($result); $timetorefresh = $r['columnname']; if ($time1 == $timetorefresh) { $query2 = ("UPDATE tablename SET manafield = maxmanavalue"); if ($query1){ echo "Mana is restored. Current mana".$manavalue."; // use echo in php } } } else {} _linenums:0'>$timenow1 = now();$time1 = now(); // this is the time at th beginning of the execution$result = mysql_query("SELECT * where columnid =' 1'"); // always enclose queries in (). Also for now since your a starter use * for all.$r= mysql_fetch_array($result);$timetorefresh = $r['columnname'];if ($time1 == $timetorefresh){$query2 = ("UPDATE tablename SET manafield = maxmanavalue"); if ($query1){ echo "Mana is restored. Current mana".$manavalue."; // use echo in php }}}else {} That code probably has errors but I hope you get the point. Also you don't need to do the changing of names from query to result or result to r. As well NEVER use $_GET, $_POST or $_COOKIE. $_REQUEST can do all those in one. The field for refresh time could be an INT. If you've figured out the JS congratz, that's half the hard part. Below are some general codes that you an edit to fit your needs (comes in handy epically with my slap job above ) $now = time('now'); $difference = intval(($now - $jdate)/86400); // is an example of comparing how many days ago someone joined. $player = mysql_query("SELECT * FROM table WHERE ID_MEMBER='$id'") or die(mysql_error()); // example for mysql query $us = mysql_fetch_array( $player ); // example for the $r thinggy but I used us. You need only show the fetch_array thing in one name no need for // $us=blah blah or $reulst=$query. linenums:0'>$jdate = $us['dateRegistered'];$now = time('now');$difference = intval(($now - $jdate)/86400);// is an example of comparing how many days ago someone joined.$player = mysql_query("SELECT * FROM table WHERE ID_MEMBER='$id'")or die(mysql_error()); // example for mysql query$us = mysql_fetch_array( $player ); // example for the $r thinggy but I used us. You need only show the fetch_array thing in one name no need for // $us=blah blah or $reulst=$query.As for qhere to place it, I can't help other than in some file that is executed as possibly an url var (like file.php?action=mana). I'll be able to help more when I finish my timer Edited May 24, 2007 by SilverFox (see edit history) Share this post Link to post Share on other sites