0 votes

Making a stat system and i wanna make it so it add a certain points to all stats and not randomly pick one as all other tutorials show it.

example 1-9 add 10 points to one stat and 5 to the others and increase it slightly 10 -19 and so on.

Sorry for the bad grammar!

And this is how the code looks like.

  extends Node
 # Character stats
export (int) var max_hp = 10
export (int) var max_mana = 10
export (int) var strength = 1
export (int) var dexterity = 1
export (int) var agility = 1
export (int) var magic = 1
export (int) var defence = 1
export (int) var speed = 1
export (int) var wisdom = 1
 # Leveling system
export (int) var level = 1
var experience = 0
var experience_total = 0
var experience_required = get_required_experience(level + 1)
func get_required_experience(level):
    return round(pow(level, 1.6) + level * 4)
func gain_experience(amount):
    experience_total += amount
    experience += amount
    while experience >= experience_required:
        experience -= experience_required
        level_up()
func level_up():
    level += 1
    experience_required = get_required_experience(level + 1)

Edit: Sorry for the not so good explaining
level 2 add 10 to all var exept maxhp and maxmana
add 5 maxhp and maxmana

level 3 same as level 2 all the way to level 9
and from level 10 add 15 to all var exept maxhp and maxmana
and repete that type of pattern all the way until max level that is not decided yet

hops this explains it better

Godot version v3.4.4.stable.official
in Engine by (12 points)
edited by

Not sure what are you asking. If you want to add predetermined values to specific stats, just do it. Like so:

magic += 2
speed +=1
max_hp += 14
etc...

Since I guess this isnt what you are asking for, try to be more specific with what you want to achieve (since I cant understand the example you gave, 1-9 what?, do you want the stat that gets 10 to be picked at random and give 5 to all others? even the max_hp ones? etc...)

Sorry for the not so good explaining
level 2 add 10 to all var exept maxhp and maxmana
add 5 maxhp and maxmana

level 3 same as level 2 all the way to level 9
and from level 10 add 15 to all var exept maxhp and maxmana
and repete that type of pattern all the way until max level that is not decided yet

hops this explains it better

2 Answers

0 votes

While there are likely more concise ways to do this, without more specifics on the value increases through level progressions, it's hard to say. A simple way to accomplish this would be to just brute-force it. So, something like:

func update_stats(level):
    if level >= 2 && level <= 9:
        max_hp += 5
        max_mana += 5
        strength += 10
        dexterity += 10
        # ...
    elif level >= 10 && level <= 20
        max_hp += 5
        max_mana += 5
        strength += 15
        dexterity += 15
        # ...

Then, at the point where you advance your level, just call update_stats() and pass in the new level. That function will than make the necessary stat adjustments.

Again, there are likely better ways to accomplish this, but without understanding exactly how each value should progress throughout the game, it's hard to provide more info...

by (16,664 points)
0 votes

There are 2 ways of doing this.
1.
Introducing stats grouped in a dictionaries, and iterating them on level up :

    export var stats = {"agility" : 1,"magic" : 3, "speed" : 4}
    export var otherstats = {"maxhp" : 10, "maxmana" : 15}
    for key in stats.keys() :
          if level < 10:
                stats[key] += 15
          else:
                stats[key] +=10
   for key in otherstats.keys():
          thesame

2.
Leaving stats like You introduced them and designing temporary indicator arrays

for stat in ["magic","speed","agility"] :
        if level < 10:
               set(stat,get(stat) + 15)
        esle:
               set(stat,get(stat)+10)
for stat in ["maxmana","maxhp"] :
        thesame
by (7,742 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.