currently i have the below function that works, but is quite long.
I was wondering if anyone would have done it differently, especially the if statements near the bottom, the ones starting with
if($num >= $common && $num <= $uncommon)
What they are simply doing is trying to get a possibility.
So:
To find a common you have an 80% chance
To find an uncommon you have an 10% chance
To find a rare you have a 6% chance
To find an Ultra-Rare you have a 4% chance
$uncommon = 80;
$rare = 90;
$urare = 96;
$string = '';
if(isset($_COOKIE['calona']))
{
$uid = $_COOKIE['calona'];
}
else
{
$uid = 0;
}
$uid = 1;
while($count < $amount)
{
$num = rand(1,100);
$type = '';
if($num >= $common && $num <= $uncommon) // Common
{
$type = 'Common';
}
elseif($num > $uncommon && $num <= $rare) // Uncomon
{
$type = 'Uncommon';
}
elseif($num > $rare && $num <= $urare) // Rare
{
$type = 'Rare';
}
elseif($num > $urare) // Ultra-Rare
{
$type = 'Ultra-Rare';
}
$sql = "SELECT c.url, c.sdesc
FROM creatures AS c
RIGHT JOIN user_access AS u ON u.cid = c.ID AND u.uid = '".$uid."'
WHERE c.rarity = 'common'
AND c.type = 'Egg'
ORDER BY RAND( )
LIMIT 1";
$result = mysql_query($sql) or die(sql_error($sql));
while($row = mysql_fetch_array($result))
{
$string .= '<p><img src="'.$row['url'].'" alt="'.$row['sdesc'].'" border="0"><br/>'.$row['sdesc']."</p>\n";
}
$count++;
}
return $string;
}