Author Topic: Death Penalty  (Read 925 times)

Offline Sweet

  • Level 3
  • *
  • Posts: 9
  • Reputation: +0/-0
    • View Profile
Death Penalty
« on: July 11, 2010, 02:22:54 PM »
I am making a mmo browser, and I want to make a death penalty for my players, one where they have to wait 2 minutes before they can continue playing. Can someone show me some code as to how to do this?

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,128
  • Reputation: +26/-1
    • View Profile
Re: Death Penalty
« Reply #1 on: July 11, 2010, 02:29:00 PM »
Put it at the top of each page, below header display and database conection.

if(time()<$player->deathpenaltyexpiration) {echo"Death penalty"; exit();}


function death($playerid)
{
$t=time()+2*60;
myqsl_query("UPDATE players SET deathpenaltyexpiration=$t WHERE id=$playerid);
}


Note: this code will stop working in year 2038 :)
« Last Edit: July 11, 2010, 02:30:50 PM by Chris »

Offline Sweet

  • Level 3
  • *
  • Posts: 9
  • Reputation: +0/-0
    • View Profile
Re: Death Penalty
« Reply #2 on: July 11, 2010, 03:00:22 PM »
what should i add to players in the database?

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,128
  • Reputation: +26/-1
    • View Profile
Re: Death Penalty
« Reply #3 on: July 11, 2010, 03:04:26 PM »
a 32bit signed integer to store the deathpenaltyexpiration value. You could also go for 64bit integer if you are paranoid and start making protections against Y2K38 bug right now :)

Offline Sweet

  • Level 3
  • *
  • Posts: 9
  • Reputation: +0/-0
    • View Profile
Re: Death Penalty
« Reply #4 on: July 11, 2010, 03:11:36 PM »
so when my players die they go to gameover.php, should i post this line in the gameover.php script?

Offline Sweet

  • Level 3
  • *
  • Posts: 9
  • Reputation: +0/-0
    • View Profile
Re: Death Penalty
« Reply #5 on: July 11, 2010, 03:54:42 PM »
Here is my code where should the script go?

Code: [Select]

<?php
include_once 'connect.php';
  
session_start();
  include_once 
'logo.php';

?>

 <?php

if (isset($_SESSION['player']))
{
  
$player=$_SESSION['player'];
}  
else
{
  echo 
"Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>

</div>
<?php
 $playerinfo
="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid $playerinfo3['id'];


 
?>


 <?php

$firstmod 
= (int)($playerinfo3['exper'] * .07);
          
$totalexper =$playerinfo3['exper'] - $firstmod;
          
$totalexper $totalexper;
                     echo 
"<br><b><big>You died, you lost " $firstmod " experience.</b></big><br>";
      
$updateplayer="update players set exper='$totalexper' where name = '$player'";
  
mysql_query($updateplayer) or die("Could not update player");
  echo 
"<br><br><a href='index.php'>Go back to town";
  
  
$updateplayer="update players set hpoints='1' where name='$player'";
  
mysql_query($updateplayer) or die("Could not update player");
  
?>


Offline bbgames

  • Level 16
  • *
  • Posts: 138
  • Reputation: +1/-0
    • View Profile
    • Building Browsergames
Re: Death Penalty
« Reply #6 on: July 11, 2010, 08:04:51 PM »
so when my players die they go to gameover.php, should i post this line in the gameover.php script?

No - otherwise, if they die and are supposed to get sent to gameover.php, gameover.php will do the same check and then...redirect them to gameover.php (causing an infinite loop, and confusing your players).

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Death Penalty
« Reply #7 on: July 12, 2010, 03:15:32 AM »
Chris why not store as some of the column type that is designed to hold time data (datetime)?

Sweet there is Modify link in the upper right corner of your posts
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,128
  • Reputation: +26/-1
    • View Profile
Re: Death Penalty
« Reply #8 on: July 12, 2010, 04:28:56 AM »
Chris why not store as some of the column type that is designed to hold time data (datetime)?

Yes, DATETIME uses only 64bit (I thought it was more inefficient, sorry for doubting you, my dear MySQL dev team :D) so it is very reasonable (but I still will stick to 32bit since I use realative times in games and it still uses half the space :))

More importantly, he is having trouble with basics, so while not everyone would understand date conversion functions, absolutely everyone can understand meaning of "time()+2*60".

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Death Penalty
« Reply #9 on: July 12, 2010, 04:48:04 AM »
In case of datetime it would be "NOW() + INTERVAL 2 MINUTE".... I think that is even more newbie-friendly, nevermind, just saying
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal