06-11-2010, 06:04 PM
Well you could always do the random number. Create a number variable in the method called "randomNum", and then set "randomNum" to a random number min: 1, Max: 100. Then you have have if/else statements saying "if(both(randomNum > 0 and randomNum <= 50), then itemDropped == coin" and then have another one except it would be randomNum > 50 and randomNum <= 100. You can add other quantities by just adding more of these, just make sure that the numbers are ranged to 100, or you will be able to drop more than one item at a time, or drop nothing at all sometimes.
Also, an easier way would be to make nested if/else, where you have "if(random <= 25), drop coin; [b]else[b] if(randomNum < 50), drop weapon; [b]else[b] if(randomNum < 100), give double experience". You would have every if statement within the else of the previous if/else statement. This would make it a 25% chance of getting coin, 25% chance of weapon, and 50% change of bonus XP. This second method better programming and it would actually be easier to do, so just do it this way.
Need an example world? Just ask
Check out my best projects so far and please comment:
Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
|