Generate random number for loot drop

0 favourites
  • 10 posts
From the Asset Store
Perfect, complete, easy to use to use, out-of-the-box inventory system
  • I searched the forums/google and found several "advanced" examples, but none of them are written from a new user perspective.

    I would like to have an enemy die, then have a chance to drop an item.

    I was hoping this could be done at the local variable, so I set my enemy to have a LootVar of 0. When it is destroyed, I have it setting LootVar to round(random(1,3)).

    Now how can I add in the next step of checking IF LootVar is 1 then create Loot Item here?

  • Well there are many ways to do this. What I would suggest is that you set two variables. One could something like "ActionNeeded" and set it to true. So if "ActionedNeeded" is tru then check any other variables that may require attention.

    For example, "Loot", "SecretDoor" "UserMessage" etc

    if any action/event requires processing you set the variable "ActionNeeded" which gets check either, every tick or once every 0.5s3econds or whatever and then process accordingly.

  • Thanks for the fast response, CZAR.

    Having a hard time wrapping my brain around what you mean.

    Make a global variable named ActionNeeded (or something), then set that action to 0 when something dies?

    Then what?

    Is there no way to just check a local variable? In the SYSTEM actions it says global and local variables, but when you try to use it to call or check a variable it only allows you to select globals.

    It seems like an option within the "destroy" object action should have the loot roll and obj generation.

  • I am trying to do something along those lines OP. see: scirra.com/forum/topic75112.html where I try to get help. So far, I'm just using what seems to be an inefficient workaround.

    If you wanted a simple implementation, the way I would do it is like this:

    Trigger: On Death

    -> select DeadEnemy| Action: set lootVar to round(random(1,3)

            -> if lootVar = 1|Action: DeadEnemy: create Loot1

            -> if lootVar = 2|Action: DeadEnemy: create Loot2

            -> if lootVar = 3|Action: DeadEnemy: create Loot3

    As in my own problem however, the more Enemy types you have and the more Loot types you have, you'll have to find another way of doing it or you'll end up with a whole lot of events. Anything beyond the simplest Function is beyond me right now, so can't help there. Also when you want different chances for different loot (common, rare, etc), as I did, things become even more complicated.

  • Is there no way to just check a local variable? In the SYSTEM actions it says global and local variables, but when you try to use it to call or check a variable it only allows you to select globals.Something's wrong in your event sheet. Might want to share it?

    Here's an example using local variable:

    + System | On start of layout
        Local number lootVar = 0
        + (empty event)        -> System | Set lootVar to round(random(1, 3))
                                  Text   | Set text to lootVar
        + System | lootVar = 1 -> Text | Set text to "loot"
    

    If your event block doesn't look similar, you've done it wrong somehow.

  • Thanks for the replies, guys.

    Norbingle, where is there an option to set "IF" commands?

    Tulamide, I see no way for System to check local variables (as I said earlier). Could you elaborate your suggestion?

  • I did understand what you said earlier and therefor showed how local variables are used. The "check local variables" is the last line in my example (System | lotVar = 1). As soon as the local variable is created it can be used for comparison.

    But it is crucial to understand the "philosophy" (sorry, I lack the right words here) of variables.

    There are three different kinds of variables in C2. Global, local and instance. They differ mainly in their scope.

    A global variable is valid all over the layout, visible and usable for every event and object.

    An instance variable can be accessed from anywhere in the event sheet, but is not unique. It shares its name (and access rule) with all other instances, and lives with an object.

    A local variable is only generable within subevents and only lives for the time the subevent is executed. So to access it you need to create a subevent in the same subevent level, where the local variable was created.

    Start of layout

    Local variable

    Local variable = some value -> do something

    Trying something like this:

    Start of layout

    Local variable

    Enemy died

    local variable = some value -> do something

    is impossible. The local variable created in Start of layout doesn't exist anymore when "Enemy died" happens. Therefor you can't find any option to compare the local variable of "Start of layout" in the "enemy died" event.

  • Gagaween

    Within the sub-event where you're randomly creating LootVar, you can use System > Compare Variable and the Local Variable LootVar should be selectable.

  • I'm jealous now. All of my novel summed up in one sentence. <img src="smileys/smiley36.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • tulamide

    haha! we shall see. hopefully it's fixed now.

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