0 Favourites

Random loot drops

  • Hi all! First post from a newbie here and really hoping you can help.

    I've tried doing this myself but don't seem to be making headway. I try to do as much as I can before bothering anyone else but this really has me stuck.

    I have 2 Families:

    1) Monsters

    2) Loot

    Goal:

    When a Monster dies, it creates Loot from a "loot table". Different Monsters will create different loot and some loot will be rarer than others.

    Of course, I could do it like this (in pseudo code):

    ON DEATH: Goblin

    IF Random = 1-10 ----> loot: gold (1-5)

              = 11-15 ----> loot: gold (5-10)

              = 16-17 -----> loot: dagger

              = 18 ----> loot: potion

    ON DEATH: Orc

    IF Random = 1-5 ----> loot: gold (5-10)

              = 6-10 ----> loot: sword

              = 11-15 -----> loot: armor

              = 16-20 ----> loot: shield

    But as you can see, with a lot of Monster and Loot types, the event list will get really long!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Just use a function:

    ON DEATH: call function "functionLoot"

    And inside FUNCTIONLOOT run the random numbers

  • Hi ghost, thanks for the reply!

    Wouldn't that function have the same problem of not having a loot table though? I mean, the loot should be different for each Monster type e.g. an Orc will not have the same loot as a goblin. It's my fault for not clarifying that. I hope this clarifies things a bit:

    Example:

    Possible Loot:

    1) Gold

    2) Dagger

    3) Boots

    4) Pelt

    5) Potion

    Thus Monster types like the orc and goblin can choose from any of the list but a Wolf Monster can't have daggers or potions. The chances for getting a particular item will also differ whereas my understanding is doing it through a function like you suggested will have similar results and I will end up with all Monsters being able to give all kinds of loot (such as a wolf giving a dagger) with the same chances regardless of monster type.

  • I don't see a problem here, what do you need help with? Just keep the functions tidy and all is good!

  • plinkie

    If I have 20 different Monsters who can spawn different Loot combos, won't I eventually have a very long event list? Would seem to be quite redundant too.

    Thanks for taking the time to reply! :)

  • If Goblin dies set Goblin_Died to true > Run rand

    Function rand

    If rand = 1-10 > Function Loot_Common

    If rand = 11-15 > Function Loot_Rare

    If rand = 16-17 > Function Loot_VeryRare

    If rand = 18 > Function Loot_ UltraRare

    Function Loot_Common

    If Goblin_Died OR

    If Orc_Died > Spawn Gold

    If ???

    Function Loot_Rare

    If Goblin_Died > Spawn Gold

    If Orc_Died > Spawn Sword

    If ???

    Function Loot_VeryRare

    If Goblin_Died > Spawn Dagger

    If Orc_Died > Spawn Armor

    If ???

    lots of ways..

  • Or put instance variables in a family that contains all the monsters.

    each monster would have it's ranges, and the function could read the list off the family.

    (unless you are using the free version, which doesn't have families.)

  • plinkie

    I will try that but it really seems to me that will still give me a very long list of events. The examples I gave are very basic and simple but the aim is many more Monster and Loot types.

    Paradox

    Can you give pseudo code examples for that? I do have instance variables in the families. The way I have it now is something like:

    Monster family with instance var LootMin and LootMax

    Loot Family with Instance var LootType (e.g. Gold is type 1, dagger is 2, etc)

    I'm aiming for (but not getting <img src="smileys/smiley9.gif" border="0" align="middle" />):

    If Monster with instance vars: LootMin 1 and LootMax 4 dies

    set "bootyVar" to random between LootMin and LootMax

    create Loot with LootType "bootyVar"

  • Couldn't you use an array to hold the list?

  • Hi ghost, thanks for the reply!

    Wouldn't that function have the same problem of not having a loot table though? I mean, the loot should be different for each Monster type e.g. an Orc will not have the same loot as a goblin. It's my fault for not clarifying that. I hope this clarifies things a bit:

    Example:

    Possible Loot:

    1) Gold

    2) Dagger

    3) Boots

    4) Pelt

    5) Potion

    Thus Monster types like the orc and goblin can choose from any of the list but a Wolf Monster can't have daggers or potions. The chances for getting a particular item will also differ whereas my understanding is doing it through a function like you suggested will have similar results and I will end up with all Monsters being able to give all kinds of loot (such as a wolf giving a dagger) with the same chances regardless of monster type.remember than functions can pass parameters, (you could pass parameter "monsterType" for example)

  • Ok, here is a capx that does it in one event.

    https://dl.dropboxusercontent.com/u/85412219/forumposts/RandomLoot.capx

    I was going to get fancy with ranges for the random values but did it the quick way, so the instance variable for the choice is like:

    "0,0,0,0,0,1,1,1,2,2,2,2,2,3,3,3,3,4"

    it grabs one of those numbers and uses it to grab that number out of a string of loots:

    "gold (5-10),sword,armor,shield,diamond"

    so there is one out of 18 chance for a diamond.

    You can change the amount of numbers to increase odds, it counts how many are there before choosing.

    The number of loots is determined by the number it pulls, so if you have a 5, there should be 5 loots, or it will grab number 4 instead.

    Edit: if you don't want to download, the event:

    On Touched Monsters | Set Text to tokenat(Monsters.loottype,int(tokenat(Monsters.Chance,random(tokencount(Monsters.Chance,",")+1),",")),",")

    You mentioned a loot table, if you want to point at those directly, you could drop the loot string, and put the numbers for your loot table instead.

    I.E. Monsters.loot="21,21,21,21,21,34,34,34,8,8,8,8,8,36,36,36,36,36"

    loot = int(tokenat(Monsters.Chance,random(tokencount(Monsters.Chance,",")+1),","))

  • Ok, here is a capx that does it in one event.

    https://dl.dropboxusercontent.com/u/854 ... mLoot.capx

    I was going to get fancy with ranges for the random values but did it the quick way, so the instance variable for the choice is like:

    "0,0,0,0,0,1,1,1,2,2,2,2,2,3,3,3,3,4"

    it grabs one of those numbers and uses it to grab that number out of a string of loots:

    "gold (5-10),sword,armor,shield,diamond"

    so there is one out of 18 chance for a diamond.

    You can change the amount of numbers to increase odds, it counts how many are there before choosing.

    The number of loots is determined by the number it pulls, so if you have a 5, there should be 5 loots, or it will grab number 4 instead.

    Edit: if you don't want to download, the event:

    On Touched Monsters | Set Text to tokenat(Monsters.loottype,int(tokenat(Monsters.Chance,random(tokencount(Monsters.Chance,",")+1),",")),",")

    You mentioned a loot table, if you want to point at those directly, you could drop the loot string, and put the numbers for your loot table instead.

    I.E. Monsters.loot="21,21,21,21,21,34,34,34,8,8,8,8,8,36,36,36,36,36"

    loot = int(tokenat(Monsters.Chance,random(tokencount(Monsters.Chance,",")+1),","))Paradox2013-08-29 09:31:21

    How would I make this spawn an item?

    I tried using compare instance variables and setting the LootType to numbers so if "1" then spawn another object but it didn't work. :/

  • I don't even remember making that complicated string.

    Here is something using that to grab the name from the Instance variable, and then use that same number to set the frame number of a spawned sprite.

    edit: to those wondering what it is without downloading, it's still one event, just more actions and a global variable to hold the random choice for more uses. It still uses the instance for the list of loots, which match up to the frames of the loot sprite.

    I suppose I could have made each Loot an animation and named each animation to match the name, and called them by name, but I didn't think of that until writing this.

  • I don't even remember making that complicated string.

    Here is something using that to grab the name from the Instance variable, and then use that same number to set the frame number of a spawned sprite.

    Thanks!

    I'll try this when I get home. I've been thinking about this for a few days and couldn't figure it out. I love the idea of having a mob drop standard items and limited health potions or power-ups. This makes it simple.

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