Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Just found a related topic but I have different/extended questions

I was wondering how the implement the drop system. I have to start designing the DB model for this so I was wondering whether what I am thinking is a good practice or not.

My game is like "City building" kind of browser based game (Flex/Flash app) with PHP and MySQL in the backend. In my game, like in any other games, there are chance based drop rate. I want to design the drop system such a way that I can easily configure

  • What item(s) can be dropped from which game element
  • What is the percent chance (probability) of getting a drop (a 100% meaning there will be some drop always)
  • What percent chance of getting a specific drop. Here I define for each item (if can drop various items) what is the chace of drop, 90% to very frequent, 5% to very rare

I am wondering how the probability is determined? It might sound very noobish but just want to confirm does it mean roll a random number and compare with the odds we defined? If I am not wrong this is good for determining "how much to drop" but not for "what to drop"

Example: If we say drop 1-10 coins or 20-50 coins. I will simply call a random() function and generate a random numbed from the desired range.

Now for other example: Drop one of Bullets (95%), Empty Gun (4%), Loaded Gun (1%)

If I roll a random number range from 1-100 and compare with probability I defined

so, a number between 1-95 drops bullet, and a number between 96-99 drops empty gun and a loaded gun when it generates 100?

Is this how it has to be done? or is there a better way?

Update:

Removed 2nd question about hack safety

share|improve this question
4  
You shouldn't ask multiple questions in one question. Protecting your game from hacks has been answered here. As for the random drops with different probabilities, this has been answered in this question. –  bummzack Jan 25 '12 at 8:56

1 Answer 1

up vote 4 down vote accepted

Let me try to go through all your questions in turn.

1. Checking whether or not a drop occurs given a certain drop chance

Just use a pseudo-random number generator and compare the result with the drop chance, just as you suggested in your question. For example, if you specify the drop chance in percentage points with up to two decimal places, you could ask

rand = generatePseudoRandomNumber(0, 10000) // between 0 and 10,000
if(rand <= dropChance * 100)

2. Checking which events happens given a set of possible events

Try to use a data structure that is more flexible than hard-coded switch expressions. I coded a basic version of a Lottery class here: https://gist.github.com/3368046. Lottery allows you to do stuff like this:

$Lottery = new Lottery();
$Lottery->addEntry($item1, $dropChanceOfItem1);
$Lottery->addEntry($item2, $dropChanceOfItem2);
$Lottery->addEntry($item3, $dropChanceOfItem3);
$drop = $Lottery->getWinner();

With my implementation, the drop chances do not even have to add up to 100%; the lottery determines the winner based on the number of lots that each participant has in relation to the other participants of the lottery.

3. When to check for drops and how to communicate the result to the player

I'd decide based on what the most critical bottleneck is: If bandwidth is expensive and if your service has a good latency (Amazon?), go for variant 1. If your service has latency issues, go for 2.

share|improve this answer
    
Referring to @BerndBrot's numbering: To point 2., I would also refer to that functionality as an "unfair/weighted die roll". For a real-life example, check out how Boost.Random handles it! –  ThePadawan Aug 16 '12 at 11:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.