RPG-like Monster and party setup - how to do that?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LucaJunge

Hello,

I am currently trying to setup a monster mechanic similar to Pokémon with different monsters that have different stats and attacks.

The problem is I can’t figure out what is the best way to set this up.

I basically need a main definition for a monster from which I can extend different monsters. I tried doing it with Resource files, but I can’t create instances with separate values and save and load them via JSON, right? I can only create resources that share the defined stats like level, health, attack values it seems. That is problematic if my monster is the same type as an other encountered monster but differs in the level and other stats.

How would I create such a system that is easy to extend and load /save?

:bust_in_silhouette: Reply From: SnapCracklins

Arrays are your friend, as are dictionaries. After you learn how to put all that data you need into these structures, it’s just how you program afterwards.

Godot Docs - Array

So it could be something like this:

var _FirebirdDictionary = {
        "Max health" : 100
        "Max skill points" : 20
        "Element" : "Fire"
        "Flying" : true
        "Health Level Up" : (randi()10)+3
        "Skill Level Up" : (randi()3)+2)
        "Level" : 1

So that holds your data. Then you tuck that into a dictionary:

var _Bestiary = [_FirebirdDictionary, _WaterTurtleDictionary....]

And pull that for fights. If it were me, hold the base stats and then have stats for how much each stat increases per level. So compare the level data with the dictionary, and after that it’s a bunch of math. But hopefully that is good source material?

   

Thanks for your answer, SnapCracklins!
I tried your approach before, but found a caveat that didn’t really look solvable with arrays or dictionaries for me.

So I opted for creating classes for a base monster, that gets initialized with base values (in the _init() method from tres reference files). The reason also was that I want to define functions for attacking, getting damage, levelling up etc, right inside one specific monster instance and having the ability to change that aswell.
That did not seem possible with just base values like in dictionaries (or is there a way to save instances of custom classes in dictionaries)?

e.g. I currently save my monster party of 6 monsters in an array of Monster classes and initialize them based on the inst2dict() values in my savegame when loading the game.
That way I have differing values from the base class and can override stuff inside there.

Thats seems to be a plausible and extendable way for me, but let’s see when I see a downside of this approach as well :slight_smile:

LucaJunge | 2022-09-12 13:56

Yeah i have seen the resource method in a lot of tutorials. For the record, you can save objects and data structures in dictionaries. But glad you got it worked out. That’s the great thing about programming - there’s always more than one way to build something.

SnapCracklins | 2022-09-12 20:16