How do I randomize loot?

0 favourites
  • 4 posts
From the Asset Store
Perfect, complete, easy to use to use, out-of-the-box inventory system
  • Hello!

    I would really need your help as a beginner, even though my question is similar with those in forums. I can't find an answer to my actual question.

    I want to create:

    When clicked > ex: 75% chance to drop boots and 25% chance to drop armor.

    and example: If u buy chance it'll increase, and it can be 50% armor and 50% boots.

    So could anyone please help me? Thanks a lot

  • Use a variable. Variable loot = 0

    -on click > set loot = int(random(101)) // this will set a variable between 0-100 without float variable

    • if loot < 75 then drop boot
    • if loot >= 75 then drop armor
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I made a system where I did the following:

    For each enemy I would assign a number for each drop item (I stored in XML, but you could do instance variables or straight in the events if you don't have different enemy types). So for example it would look like:

    Nothing: 6

    Coin:4

    Heart: 2

    Then I would use a local variable to store a random number between zero and total of those numbers -> random(0, 12) in this case. Then cycle through the drop items:

    If random <= nothing amount( 6) then drop is nothing

    elseIf random <= nothing amount plus coin amount (10) then drop is coin

    Else drop is heart

    I'm sure there is a way to do this with less events but it works. Was my first time creating this. Can see it in action in Ninja game linked in my signature. I like it because you can change one number and not have to change the rest so it will equal 100% each time; I feel like that could get really annoying.

  • Search functions could have been of great help here.

    Searching the tutorials for example would have given "How to code monster loot drops" as a result which is exactly what you are looking to do.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)