Jump to content

SELECTING A random Value but with a Percentage.


Monkuar

Recommended Posts

Okay, I have a table called: "monsters" and it has 5 mobs. (rows)

 

Only 1 is a Unique mob with a grade column set to "Unique".

 

The following query will select a random mob (someone entered the dungeon for their specific zone (map))

SELECT * from nrpg_monsters WHERE level >= 1 AND zone = '.$zone_id.' ORDER BY RAND() LIMIT 1

But the problem is, By this logic query, the UNIQUE mob has the same chance to spawn as all the others, lol.  How would I make, let's say the unique mob spawn < 10% with this query? his id is 5.

 

The point im trying to make is,  I use this info to insert it into a monster_active table, so users can actually kill their own mobs and level up/gain exp on my game..   I dont want users to have the same chance to spawn a unique mob as a Normal or Magic mob...

Don't know if this is a very intuitive approach to this issue but it seems to work fine?

//Unique Bosses/etc....
$randmobchance = mt_rand(0, 100); 
if ($randmobchance <= 5) //5% to Grab a Unique mob...
{ 
$spawnmobs = $db->query('SELECT * from nrpg_monsters WHERE level >= 1 AND zone = '.$zone_id.' AND grade="Unique" ORDER BY RAND() LIMIT 1')
}else{
$spawnmobs = $db->query('SELECT * from nrpg_monsters WHERE level >= 1 AND zone = '.$zone_id.' AND grade!= "Unique" ORDER BY RAND() LIMIT 1')
}

Archived

This topic is now archived and is closed to further replies.

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