Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /* */
- /* timestamp thingy */
- /*
- */
- mysql_query("SET AUTOCOMMIT = 0;");
- mysql_query("START TRANSACTION;");
- $sqlquery = mysql_query("SELECT timer FROM cu_users WHERE userid=$user FOR UPDATE");
- $lastarmourupdate = mysql_result($sqlquery , 0, 'timer');
- //echo " laupvar $lastarmourupdate "; //DEBUG!
- //if it's 0, do initial timestampupdate...
- if ($lastarmourupdate==0){
- //setting the timestamp from 0 to NOW, UNIX_TIMESTAMP transforms the date into seconds.
- $query=sprintf("UPDATE cu_users SET `timer` = UNIX_TIMESTAMP(NOW()) WHERE userid = '%s'",
- mysql_real_escape_string($user));
- mysql_query($query);
- mysql_query("COMMIT");
- } else {
- //querying database to see the difference between the current databasetime and the savedtimestamp
- //$timedifference returns the elapsed time in Seconds..
- $query=sprintf("SELECT UNIX_TIMESTAMP(NOW()) - '%s'", mysql_real_escape_string($lastarmourupdate));
- $timedifference = mysql_result(mysql_query($query),0);
- //echo "timedifference $timedifference"; //DEBUG!
- //check if timedifference is bigger than 1 hours (3600 seconds)
- if ($timedifference >= 300){
- //if so, calculate the amount of armour the player would recieve..
- $baseamount = 1+ floor($timedifference / 300); //1 + rounded down armour...
- $query=sprintf("UPDATE cu_users SET `uhealth`=`uhealth`+'%s',
- `uenergy`=`uenergy`+'%s'
- WHERE `userid`='%s'",
- mysql_real_escape_string($baseamount * 10),
- mysql_real_escape_string($baseamount),
- mysql_real_escape_string($user));
- // echo "Query $query" ; //DEBUG!
- mysql_query($query);
- //also calculate the time for the new timestamp using MODULA
- $left_over_time = ($timedifference % 300);
- //update players set a new timestamp
- $query = sprintf("UPDATE cu_users SET `timer`= '%s' WHERE `userid`='%s'",
- mysql_real_escape_string('UNIX_TIMESTAMP(NOW()' - '.$left_over_time'),
- mysql_real_escape_string($user));
- mysql_query($query);
- mysql_query("COMMIT");
- }
- else
- {
- mysql_query("ROLLBACK");
- }
- mysql_query("SET AUTOCOMMIT = 1;");
- }
- /* */
- /* end of timestamp thingy */
- /* */
- $result = mysql_query("SELECT uhealth, uenergy, umaxhealth, umaxenergy FROM `cu_users` WHERE `userid` = $user");
- $row = mysql_fetch_assoc($result);
- $thp = $row['uhealth'];
- $tmhp = $row['umaxhealth'];
- $ten = $row['uenergy'];
- $tmen = $row['umaxenergy'];
- if ($thp > $tmhp)
- {
- mysql_query("UPDATE cu_users SET uhealth = (umaxhealth) WHERE userid = $user");
- }
- if ($ten > $tmen)
- {
- mysql_query("UPDATE cu_users SET uenergy = (umaxenergy) WHERE userid = $user");
- }
Add Comment
Please, Sign In to add comment