Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Chance? (http://www.alice.org/community/showthread.php?t=4573)

Watsamax1 06-10-2010 08:08 PM

Chance?
 
Is it possible to like have a chance at something like you kill something and it drops loot. Not just have a set number a possibility.
Not if killed 5 times drop this. have it a possibility like 10% possibility nothing or 40% a weapon, 20% coins.

Dameria 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. [u]This second method better programming and it would actually be easier to do, so just do it this way.[/u]

Need an example world? Just ask

DensetsuNoKaboom 06-11-2010 06:53 PM

Or you could use the chooseProbabilityOfTrue function. "When enemy = hit, do if chooseProbabilityOfTrue=40%, then drop weapon, else if chooseProbabilityOfTrue=20%, then drop coin..."
And so on.

Watsamax1 06-11-2010 07:06 PM

how do i use if statements cuz i must of forgot because i say if knight is within 10 meters of a boar, boar point at knight it does nothing.

DensetsuNoKaboom 06-11-2010 07:07 PM

I didn't understand a word of that, could you repost it with correct spelling and grammar?

Watsamax1 06-11-2010 07:25 PM

I make a method called like idk attack. i say when world starts (attack) in the method i have it if knight is within idk 15 meters of boar. boar point at knight and move to knight. but it only works if i make it exactly like 23 meters. even if i move to it it doesn't work.

Dameria 06-11-2010 10:00 PM

Inside the if statement you have to have a "a < b" statement (found in world.functions). Then for "a" you put distance between knight and boar (found in knight.functions) and for "b" you put the distance in meters (in this case 15). That should work as long as you put it in the correct place in the code (think out the steps in your head from when you press the button and what will happen in each code of the method, and place it in the correct order for it work properly for what you want it to do).


All times are GMT -5. The time now is 09:50 AM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.