Jump to content
MakeWebGames

Stop people clicking lots of crimes or refreshing


jaymo

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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 by Cronic
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?';
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...