Cannot get a x% in 100% chance

Listed below is a formula i created by using my user-stats to form a "critical hit chance". As you can see it's supposed to be out of 100% chance..

If i had say 56% critical hit chance ($critting) then the forumla should, and does, read rand(56,100); but this doesn’t give me a chance out of 100… the chance $critting even at 56% is more like 4% chance.

Can anyone solve this?

        $luck2 = ceil($userrow["luck"]*9);
	$luck3 = ceil($luck2 / 100);
	$dex1 = ceil($userrow["dexterity"]*12);
	$dex2 = ceil($dex1 / 100);
	$int1 = ceil($userrow["intelligence"]*6);
	$int2 = ceil($int1 / 100);
	$timebased = ceil($userrow["turns"] * 10) / 3;
	$timecrit = ceil($timebased / 100);
	$critting = $dex2 + $luck3 + $int2 + $timecrit;
	$toblock = ceil(rand($monsterrow["armor"]*.75,$monsterrow["armor"])/3);
    $tocrit = rand($critting,100);
    if ($tocrit == 100) { $tohit = $tohit * 2; $pagearray["yourturn"] .= "Critical hit!<br />"; 
					$query = doquery("INSERT INTO {{table}} SET id='',time=NOW(),user='<font color=orange>".$userrow["charname"]."</font>',news='<font color=orange>Has critically hit $monstername for $tohit damage!</font>'", "events");
			}

What are you actually after?

I wrote this up rather quickly, but is the goal to increase the likelihood of a higher value?

So basically your character in my game has a set critical hit chance where damage will be doubled, or, higher than double sometimes.

This chance is supposed to be a set % out of 100… so like 56% or 4% (1% means 1 out of 100 attacks should crit one time and 56% out of 100 should mean that every time or every other time you attack you score a critical hit!)

But it’s not doing that… it’s calculating the chances just fine but it’s more like i wrote “$critting / 10 = $critting” which… obviously i haven’t.

What is a critical hit defined as?

Critting is defined by this formula

    $luck2 = ceil($userrow["luck"]*9);
$luck3 = ceil($luck2 / 100);
$dex1 = ceil($userrow["dexterity"]*12);
$dex2 = ceil($dex1 / 100);
$int1 = ceil($userrow["intelligence"]*6);
$int2 = ceil($int1 / 100);
$timebased = ceil($userrow["turns"] * 10) / 3;
$timecrit = ceil($timebased / 100);

$critting = $dex2 + $luck3 + $int2 + $timecrit; //your chance to score a critical hit

Let’s make this a working example…

Luck = 30
Dexterity = 65
intelligence = 30
Turns = 350

30 * 9 = 270 / 100 = 2.7
65 * 12 = 780 / 100 = 7.8
30 * 6 = 180 / 100 = 1.8
350 * 10 = 3,500 / 3 = 1,166.66 / 100 = 11.66

Add them all together and you’ll get $critting to be valued at 23.96 (24)

So you should now have 24% chance each time you click “attack” to score a critical hit…

That would look like this

$critting = $dex2 + $luck3 + $int2 + $timecrit;
$critting = 24;

$toblock = ceil(rand($monsterrow[“armor”]*.75,$monsterrow[“armor”])/3);

$tocrit = rand(24,100); if ($tocrit == 100) {
//24% chance to get 100?

$tohit = $tohit * 2; $pagearray[“yourturn”] .= “Critical hit!”;

$query = doquery(“INSERT INTO {{table}} SET id=’’,time=NOW(),user=”.$userrow[“charname”]."’,news=‘Has critically hit $monstername for $tohit damage’", “events”); }

Basically i’m not getting 24% as stated above, im really getting more like 2.4% but if I change the variable at all it gets 100% each time.

I honestly think if i make this change i will achieve what Iam askingfor
$tocrit = rand(1,100);
if ($tocrit <= $critting) {

So if the random number is 1-24 -> crit

Yep that was it!

/thread

Some times you just need to talk it out.

Sponsor our Newsletter | Privacy Policy | Terms of Service