Jump to content

Stuck on chance script


DeanWhitehouse

Recommended Posts

There's really no way anybody can help you on this... first and foremost the formula is gonna have to be balanced with the rest of your game, which we know nothing about.  For instance, is the base (no xp) supposed to be a 50/50 coin flip? And how much more per xp do you want it to lean in favor? A basic formula could be like so:

 

start out with a 50/50 coin flip.  That means there's 50 "points" to lean in your favor.  Assuming xp goes from 0-100% you could do say, 0.5 points per xp % so if you had 10% xp the coin toss would be 55/45.  But does that throw off the balance in your game? Only way you're gonna be able to figure that out is trial and error and tweaking it based on observation of a live game (be it a beta or final or w/e).

Link to comment
Share on other sites

ok, this is the function i have made

<?php
  function crime_chance()
		{
		$userid = $_SESSION['userid'] ;
		$row = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE ID = '{$userid}'"));
		$chance = $row['crime_chance'];	
		$random_chance = rand(0,100);
		echo $random_chance."<br>";
		echo $chance;
					if ($chance >= $random_chance ) 
					{
					$success = 1; 
					}
				elseif($random_chance <= $chance)
				{
				$success = 0;
				}
					if($chance == 100)
					{
					$success = 1;
					}
						if($success == 1)
						{
						echo "<tr><td>Succeeded</td></tr>";
						}
					else
					{
					echo "<tr><td>Failed</td></tr>";
					}
					$add = rand(1,2);
					echo "<tr><td>Percent to add to exp ".$add. "</td></tr>";
		}
	?>

Explanation of the game , what it will be is each time you commit a crime you gain either 1 or 2 percent more experience, and the chance of succeeding is based on how much experience you have.

But the script we have i dont think it is very good, am i wrong ?

Link to comment
Share on other sites

Grab your percentages for your 2 crims...

 

then calculate the relative chance by what portion of their overall chance they possess. Pass the 2 users chances to the 'best_crim' function and then see how won by generating a random number between 0 and 1 and comparing to the LARGEST relative power - if its great then the less likely crim wins!!!

 

<?php
function best_crim($crim1per, $crim2per)
{
$crimpower['crim1'] = $crim1per/($crim1per + $crim2per); / relative power of crim 1.
$crimpower['crim2'] = 1 - $crimpower['crim1']; // relative power of crim 2.
$perpetrator = do_battle($crimpower);
return $perpetrator;
}

function do_battle($crimpower)
{
$prob = rand(0,1); // gen random criminality factor.
if ($prob > max($crimpower))
{
  // probability is higher than most powerful crims relative share - they lose.
  $winner = array_keys($crimpower, min($crimpower));
}
else
{
  // probability is less than or equal than most powerful crims relative share they win.
  $winner = array_keys($crimpower, max($crimpower));
}
return $winner[0];
}

// some query to grab crim power of crims
....
$crim1 = 0.23; //$crim1 = 23%
$crim1 = 0.17; //$crim1 = 17%

$the_crim = best_crim($crim1, $crim2);

echo 'Perpetrator is ' . $the_crim;

// add or remove % accordingly.
?>

 

You could take the call to do_battle out of best_crim if you need to calculate that kind of thing else where but this should fit your current requirement.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.