jaymo Posted April 27, 2012 Share Posted April 27, 2012 I've seen this around on a few games but can't get my head around it, is there a way that the user can do crimes but if they keep clicking then it says a message or if you refresh? Ive seen games with a url with a hash or something like game.com/crime.php?id=4&hex=8b79c8a59b38e53cb51f53b181e1f27c I will pay back to the community by sharing some of my custom mods again soon as a thankyou. Thanks again Quote Link to comment Share on other sites More sharing options...
Kieran-R Posted April 27, 2012 Share Posted April 27, 2012 You could use timestamps. It would work like this: 1) User does crime, the time stamp is inserted to a field in db. 2) User does another crime. (New time stamp - time stamp in db). If it is below 2 (seconds), then update another field in db to 2. 3) Same as number 2, update teh second field in db to 3. If the value is over 2, then update the second db feild to 0 so it will reset. 4) If this value reaches for example 5, the user gets an error message. That's just a rough example of how it works. I don't have time to make a script for it, but I am sure it wouldn't be hard at all to implement to a game. Quote Link to comment Share on other sites More sharing options...
Cronic Posted April 27, 2012 Share Posted April 27, 2012 (edited) <?php include 'header.php'; $error = ($user_class->jail > 0) ? "You can't do crimes if your in prison!" : $error; $error = ($user_class->hospital > 0) ? "You can't do crimes if your in hospital!" : $error; if (isset($error)){ echo Message($error); include 'footer.php'; die(); } if ($_GET['spend'] == "nerve"){ if($user_class->points >= 10) { if($user_class->nerve == $user_class->maxnerve) { echo Message("Your nerve is already full up!"); } else { $newpoints = $user_class->points - 10; $newnerve = ($user_class->maxnerve > 100) ? $user_class->nerve + 100 : $user_class->maxnerve; $newnerve = ($newnerve > $user_class->maxnerve) ? $user_class->maxnerve : $newnerve; $result = mysql_query("UPDATE `grpgusers` SET `nerve` = '".$newnerve."', `points`='".$newpoints."' WHERE `id`='".$_SESSION['id']."'"); echo Message("You spent 10 points and refilled your nerve."); } } else { echo Message("You don't have enough points to do that."); } } $result = mysql_query("SELECT * FROM `grpgusers` WHERE `id`='".$user_class->id."'"); $worked = mysql_fetch_array($result); $currenthex = $worked['crimehex']; $crime = $_GET['id']; $hex = $_GET['hex']; if ($crime != ""){ if ($hex == $currenthex) { $updatehex = md5(uniqid(rand(), true)); $result = mysql_query("UPDATE `grpgusers` SET `crimehex` = '".$updatehex."' WHERE `id` = '".$user_class->id."'"); $result = mysql_query("SELECT * FROM `crimes` WHERE `id`='".$crime."'"); $worked = mysql_fetch_array($result); $nerve = $worked['nerve']; $time = floor(($nerve - ($nerve * 0.5)) * 6); $name = $worked['name']; $stext = 'You successfully managed to '.$name; $ftext = 'You failed to '.$name; $chance = rand(1,(((25 * $nerve) - $user_class->level)) - round($user_class->awakepercent / 2)); $chance = ($user_class->eqshoes == 73) ? $chance - floor(($chance / 100) * 10) : $chance; $randomize1 = rand(1,30); // get the crimes here $money = (50 * $nerve) + 15 * ($nerve - 1); $exp = (25 * $nerve) + 15 * ($nerve - 1); $rawexp = (25 * $nerve) + 15 * ($nerve - 1); if ($user_class->nerve >= $nerve) { if($randomize1 == 19) { echo Message($ftext.".<br /><br /><a href='crime.php?id=".$crime."&hex=".$updatehex."'>Retry</a> | <a href='crime.php'>Back</a>"); $crimefailed = 1 + $user_class->crimefailed; $nerve = $user_class->nerve - $nerve; $result = mysql_query("UPDATE `grpgusers` SET `crimefailed` = '".$crimefailed."', `nerve` = '".$nerve."' WHERE `id`='".$user_class->id."'"); } else { if($chance <= 75) { echo Message($stext.".<br />You received ".$exp." exp and $".$money.".<br /><br /><a href='crime.php?id=".$crime."&hex=".$updatehex."'>Retry</a> | <a href='crime.php'>Back</a>"); $exp = $exp + $user_class->exp; $crimesucceeded = 1 + $user_class->crimesucceeded; $crimemoney = $money + $user_class->crimemoney; $money = $money + $user_class->money; $nerve = $user_class->nerve - $nerve; $todaysexp = $user_class->todaysexp + $rawexp; $expcount = $user_class->expcount + $rawexp; $result = mysql_query("UPDATE `grpgusers` SET `exp` = '".$exp."', `crimesucceeded` = '".$crimesucceeded."', `crimemoney` = '".$crimemoney."', `money` = '".$money."', `nerve` = '".$nerve."', `todaysexp` = '".$todaysexp."', `expcount` = '".$expcount."' WHERE `id`='".$_SESSION['id']."'"); }elseif ($chance >= 250) { echo Message($ftext.".<br />You were hauled off to prison for " . $time . " minutes.<br /><br /><a href='crime.php?id=".$crime."&hex=".$updatehex."'>Retry</a> | <a href='crime.php'>Back</a>"); $crimefailed = 1 + $user_class->crimefailed; $jail = time() + ($time * 60); $nerve = $user_class->nerve - $nerve; $caught = $user_class->caught + 1; $result = mysql_query("UPDATE `grpgusers` SET `crimefailed` = '".$crimefailed."', `caught` = '".$caught."', `jail` = '".$jail."', `nerve` = '".$nerve."' WHERE `id`='".$_SESSION['id']."'"); }else{ echo Message($ftext.".<br /><br /><a href='crime.php?id=".$crime."&hex=".$updatehex."'>Retry</a> | <a href='crime.php'>Back</a>"); $crimefailed = 1 + $user_class->crimefailed; $nerve = $user_class->nerve - $nerve; $result = mysql_query("UPDATE `grpgusers` SET `crimefailed` = '".$crimefailed."', `nerve` = '".$nerve."' WHERE `id`='".$_SESSION['id']."'"); } } } else { echo Message("You don't have enough nerve for that crime.<br /><br /><a href='crime.php'>Go Back</a>"); } include 'footer.php'; die(); } else { echo Message("The page you requested has timed out. This may have been caused by refreshing the page or following an incorrect link.<br /><br /><a href='crime.php'>Go Back</a>"); include 'footer.php'; die(); } } ?> <div id="right_c"><div class="g_content"><h3> Crime</h3><div class="g_text"> <table width='100%'> <tr> <td><center><a href='crime.php?spend=nerve'>Refill Nerve</a></center></td> </tr></table> <table width='100%'> <tr> <td width='50%'><b>Name</b></td> <td width='25%'><b>Nerve</b></td> <td width='25%'><b>Action</b></td> </tr> <? $newhex = md5(uniqid(rand(), true)); $result = mysql_query("UPDATE `grpgusers` SET `crimehex` = '".$newhex."' WHERE `id` = '".$user_class->id."'"); $result = mysql_query("SELECT * FROM `crimes` ORDER BY `nerve` ASC"); while($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr><table width='100%'><td width='50%'>".$line['name']."</td><td width='25%'>".$line['nerve']."</td><td width='25%'>[<a href='crime.php?id=".$line['id']."&hex=".$newhex."'>do</a>]</td></tr></table>"; } ?> </table> </div> </div> </div> </td></tr> <?php include 'footer.php'; ?> Edited April 27, 2012 by Cronic Quote Link to comment Share on other sites More sharing options...
Cronic Posted April 27, 2012 Share Posted April 27, 2012 [ATTACH=CONFIG]359[/ATTACH] Add to grpgusers Quote Link to comment Share on other sites More sharing options...
Guest Posted April 27, 2012 Share Posted April 27, 2012 Captcha? Or am I getting the wrong idea of what your trying to do? Quote Link to comment Share on other sites More sharing options...
Ishraq Posted April 27, 2012 Share Posted April 27, 2012 Ive got something good. It doesnt require any any database insertions. Just a few codes controlled by session. And it works perfectly. Il post it up tommorow. Quote Link to comment Share on other sites More sharing options...
Cronic Posted April 28, 2012 Share Posted April 28, 2012 Captcha? Or am I getting the wrong idea of what your trying to do? Yeah, I am trying to fix it to the Captcha way, but haven't succeeded yet, once its done i'll update the code. Quote Link to comment Share on other sites More sharing options...
Guest Posted April 28, 2012 Share Posted April 28, 2012 Yeah, I am trying to fix it to the Captcha way, but haven't succeeded yet, once its done i'll update the code. Use PHPGD everytime they do a crime create a new random generated code and turn it into an image. Quote Link to comment Share on other sites More sharing options...
Michael Evans Posted April 28, 2012 Share Posted April 28, 2012 there is a good way to do this ehh my mind has gone blank and im getting mixed up but could you just not alow the same data sent twice simple bit like cross site forgery? not sure im no coder Quote Link to comment Share on other sites More sharing options...
Djkanna Posted April 28, 2012 Share Posted April 28, 2012 How about? /* Logically this would be placed, where you would put your links to do crimes */ $_SESSION['crimeCode'] = md5(uniqid(null, true)); echo '<a href="dosomecrime.php?crimeID=1&code='.$_SESSION['crimeCode'].'" title="Do Crime">Do it nao</a>'; /* Then this would be where you have your logic for the crimes. */ if (array_key_exists('code', $_GET) && is_string($_GET['code']) && $_GET['code'] == $_SESSION['crimeCode']) { //Do some crime stuff. echo 'Yay you did a crime, bet you feel proud.'; //Change the 'code'. $_SESSION['crimeCode'] = md5(uniqid(null, true)); } else { //Screw 'em. echo 'Eh, you hit refresh didn\'t you?'; } Quote Link to comment Share on other sites More sharing options...
grant Posted April 28, 2012 Share Posted April 28, 2012 aye would give you my crimes code works with tokens but mines have points and other stuff added to it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.