Random Loot Treasure Chest

Hello!

I have made a treasure chest the player opens and loot pops out. This is cool but I would like the loot that spawns to be random or weighted on a list of possible items. I have tried a few ideas but none have worked. Does anyone have a suggestion or a tutorial that they could point me too? Specifically I would like advice on how this can be done within AGM.

Thank you for your time.

1 Like

This is one I found. It may get you started https://youtu.be/Pu-fK8pIeXc?si=BAlbIZSqhXv6tvyk

1 Like

I should make a visual script version of this.
:thinking:

2 Likes

Great resource @Stano! Highly recommended. I should have been clearer in that by saying “within AGM” I should have specified with VS. What I am attempting to do is recreate a game I had done in base Godot in GDScript with VS.

@Baz please? :smiley:

1 Like

Working on something!

2 Likes

@Locelaro try this out, I don’t have any instructions on using it, but it might be self explanatory enough.

baz_weighted_spawner.gd (19.0 KB)


2 Likes

Going to have a go with this. I will let you know how it turns out. Thanks!

1 Like

@Baz Played around with this for a few hours. Was able to replace the GenerateObject action in this instance to fantastic effect. The only thing that seemed to be a hitch is that it seemingly ignores a preceding “Wait” action. I will tinker with it a bit more later but so far its exactly what I was looking for. Thank you very much!

1 Like

That actually might be intentional with how InvokeScript works. Being OnEnter means it’s ran once when the state is entered. It doesn’t take into effect any other action.

I could have a delay for spawn on the node itself and you would set that with whatever wait time you were giving previously. Is that acceptable to add a Spawn Delay parameter on the node?

2 Likes

@Locelaro try this one, has a Spawn Delay on it. Set that to the wait time you use in the action.

baz_weighted_spawner.gd (19.8 KB)

2 Likes

@Baz Perfect it worked a treat! You did exactly what I was going to do and add a delay float :grinning_face_with_smiling_eyes: Thank you again!

1 Like