A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: RPG - Random Chest Rewards

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Posts
    107

    RPG - Random Chest Rewards

    Greetings,

    I want to program a chest that gives a random reward (from a pool from 10 possible rewards). Which is the best way to program this function? If-else? Switch? Array?

    And more importantly, how can I define the chance of getting each reward?
    For example: The player has 50% of getting Reward1, 3% Reward2, 0.005% Reward3 and so on?

    Thanks.
    Last edited by Hurdarr; 08-05-2011 at 07:30 AM.

  2. #2
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Have an array with all the rewards, and then an array with the chances, that corresponds to the first array.

    Then generate a random number, and loop through the chances array, checking if the random number is lower then the chance you have assigned it (Instead of assigning each reward a chance, you need to alot it a chance range somewhere between 0-1, and then order the chances in ascending order.

    Example:

    rewards = [ new BaconStrip(), new EggMcMuffin(), new AK-47()];
    chances = [ 0.5, 0.8, 1];

    In this example, getting a bacon strip is a 0.5 chance, getting an egg mcmuffin is 0.3 chance ( 0.8 - 0.5), and getting a brand new AK-47 is a 0.2 chance ( 1 - 0.8).
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  3. #3
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    If you want to get really technical, look into Treasure Classes: Diablo II: Treasure Classes
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center