Need Advice on Dropped Items

Wondering if someone can give me some advice… I have several enemies in one level, when you kill those enemies there is the chance that they will drop 1 of 3 items… In an XML document I have a max limit to how many of each of those items they can drop per level… Then how would you make sure that the enemies randomly drop 1 of the 3 items but also make sure that the player has the chance to get the maximum amount of pickups per item?

For instance I have defined…

100 Max Coins, 1 Max Health Boost, 1 Max Speed Boost…

When you kill an enemy how can I randomly drop one of the three items above and also make sure that 100 Coins are dropped, 1 Health boos and 1 Speed boost are all dropped.

Right now I am using a hack job probability script:

[lua]local prob = math.random(4); – 25% chance;
if(prob == 4)then
local prob_item = math.random(3); – will choose 1,2,or 3
if(prob_item == 1)then
if(totalsofar < maxallowed)then
dropMoney();
end
elseif(prob_item == 2)then
if(totalsofar < maxallowed)then
dropHealth();
end
elseif(prob_item == 3)then
if(totalsofar < maxallowed)then
dropBoost();
end
end
end[/lua]

All that does is randomly drop an item 25% of the time and ensures that it enemies do not drop more than the max allowed amount… It doesn’t make sure that it drops the max number and randomly… [import]uid: 63800 topic_id: 21294 reply_id: 321294[/import]

are you increasing the “totalsofar”?
like so

[lua]if(prob_item == 1)then
if(totalsofar < maxallowed)then
dropMoney();
totalsofar = totalsofar + 1
end[/lua]

and seeding random?

[lua]math.randomseed( os.time() )[/lua] [import]uid: 114118 topic_id: 21294 reply_id: 84340[/import]

Yes I am, on both accounts… And it works just fine now… However I am always getting a random number of dropped items… I’m not getting something consistent because when it decides if the enemy should drop something there is a 1 in 4 chance. So I can’t really plan the game out well regarding the cost of weapons, etc because I can’t control the amount of money that is available in each level. [import]uid: 63800 topic_id: 21294 reply_id: 84342[/import]

You could use a timer to check how much money the player has at 1/4, 1/2, 3/4, in the game - then if it’s below a certain amount ensure the next enemy drops coins. [import]uid: 52491 topic_id: 21294 reply_id: 84376[/import]