Random loot drops

Get help using Construct 2

Post » Thu Aug 29, 2013 4:43 am

[QUOTE=Norbingel] 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.[/QUOTE] remember than functions can pass parameters, (you could pass parameter "monsterType" for example)
B
12
S
3
G
1
Posts: 347
Reputation: 2,866

Post » Thu Aug 29, 2013 9:05 am

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),","))Paradox2013-08-29 09:31:21
B
226
S
60
G
33
Posts: 902
Reputation: 39,989

Post » Tue Apr 01, 2014 2:00 am

Paradox wrote: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. :/
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Post » Tue Apr 01, 2014 9:03 am

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.
You do not have the required permissions to view the files attached to this post.
Last edited by Paradox on Wed Apr 02, 2014 6:15 pm, edited 1 time in total.
B
226
S
60
G
33
Posts: 902
Reputation: 39,989

Post » Tue Apr 01, 2014 8:26 pm

Paradox wrote: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. :D
B
12
S
4
G
2
Posts: 132
Reputation: 1,749

Previous

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, DrKoala and 9 guests