This question might seem a bit bizarre, but…
I run a mafia style game site scripted in PHP. When players do crimes, theres a chance they’ll get a ‘drop’, lets say a new weapon.
How I have it working at the moment is each crime they do, I run a rand() out of 10, and if it hits 10 then I randomly select a row from the firearms_db table, and give them that.
What I’d like to do though, is make it so each weapon has a different percentage rate of ‘dropping’- so the more powerful and expensive ones will drop less, and the cheap ones will drop frequently. At the moment you’ve got just as much chance of getting a cheap one as you are an expensive one.
Does anyone have any ideas how I could go about adding this? Would I need to add another field to the firearms_db with a drop rate value and then work with that?
You could try adding a column to the table that ranks the weapons some way. For example, you could have a
rocket_launcherrated at 10, while atoothpickis rated as 2.The database table could look like this:
You could do a
rand()out of ten. Let’s say you store the result in res. Then, query the database:If res is 7, then you will only get
toothpick. If res is 10, you will get bothtoothpickandrocket_launcher.You could then randomly pick the weapon to give, out of the ones from the query.