I'm stuck on how to add this feature

Alright I’m making Pokémon in Godot and I’m on to type advantages and disadvantages and I’m a bit stuck on how I would add that I have here a Types.gd file

extends Control
class_name types
var Normal : Dictionary = {
   "a_rock": "neff",
   "a_steel": "neff",
   "a_ghost": "no",
   "d_ghost": "no",
   "d_fighting": "seff",
}
var Fire : Dictionary = {
   "a_grass": "seff",
   "a_ice": "seff",
   "a_bug": "seff",
   "a_steel": "seff",
   "a_fire": "neff",
   "a_water": "neff",
   "a_rock": "neff",
   "a_dragon": "neff",
   "d_fire": "neff",
   "d_grass": "neff",
   "d_ice": "neff",
   "d_bug": "neff",
   "d_steel": "neff",
   "d_fairy": "neff",
   "d_water": "seff",
   "d_ground": "seff",
   "d_rock": "seff",
}
var Water : Dictionary = {
   "a_fire": "seff",
   "a_ground": "seff",
   "a_rock": "seff",
   "a_water": "neff",
   "a_grass": "neff",
   "a_dragon": "neff",
   "d_fire": "neff",
   "d_water": "neff",
   "d_ice": "neff",
   "d_steel": "neff",
   "d_electric": "seff",
   "d_grass": "seff",
}

a_ type meaning attacking so for example type fire would be

"a_grass": "seff"

because fire is super effective against grass now that’s all good but now I added the class to my main battle scene with

var Type = types.new()

also works fine but now this is where I’m stuck super effective moves doing 2x the damage and not very effective moves doing .5x damage how would i add checking the types of two different Pokémon and doing damage multiplication

	data.Player = {
		"level" : randi_range(5,7),
		"hp" : randi_range(1,5),
		"spd" : randi_range(1,5),
		"atk" : randi_range(1,5),
		"def" : randi_range(1,5),
		"type": request_type(data.starter),
		"exp": 0,
		"max_exp": null
	}

code for the player with the type being let’s say the string "Fire"

	data.Enemy = {
		"level" : randi_range(5,7),
		"hp" : randi_range(1,5),
		"spd" : randi_range(1,5),
		"atk" : randi_range(1,5),
		"def" : randi_range(1,5),
		"move1": randmov(),
		"move2": randmov(),
		"move3": randmov(),
		"move4": randmov(),
		"current": null,
		"sprite" : get_random_mon(1),
		"type": set_enemy_type(),
	}

code for the enemy with the type being the string "Water"
now this is the attack code / damage function

func _on_moves_damage(entity, damage, text, effectivity, type):
	await get_tree().create_timer(.5).timeout
	if entity == "Enemy":
		match data.Enemy.type:
			"Normal":
				pass
		data.Player.hp -= damage
		disable_btns(false)
		if effectivity == "weak":
			$"SFX/weak attack".play()
		elif effectivity == "reg":
			$SFX/attack.play()
		var tween = get_tree().create_tween()
		tween.tween_property($Cast/Player/hpbar,"value",data.Player.hp,1).set_trans(Tween.TRANS_LINEAR)
	elif entity == "Player":
		data.Enemy.hp -= damage
		if effectivity == "weak":
			$"SFX/weak attack".play()
		elif effectivity == "reg":
			$SFX/attack.play()
		var tween = get_tree().create_tween()
		tween.tween_property($Cast/Enemy/hpbar,"value",data.Enemy.hp,1).set_trans(Tween.TRANS_LINEAR)
		if data.Enemy.hp <= 0:
			textedit(text)
			await get_tree().create_timer(1).timeout
			kill_enemy()
			return
		$"Timers/after_attack cooldown".start()
	textedit(text)

how would i add the multipliers without 1000 match statements?

actually quite ambitious, but i like it

make a table-like variable like this?


the data can be a json, or even csv. then tell the dictionary or even put it in multi array will do

ok this might work ill try to use a modified version to use both you 'res and bing ais idea

extends Node

# Define the type matrix (adjust values as needed)
var type_matrix = {
    "Normal": {"Normal": 0, "Fire": 0, "Water": 0, ...},
    "Fire": {"Normal": 0, "Fire": -1, "Water": 1, ...},
    # Add other types here...
}

# Function to calculate damage multiplier based on attacker and defender types
func getDamageMultiplier(attacker_type: String, defender_type: String) -> float:
    if attacker_type in type_matrix and defender_type in type_matrix[attacker_type]:
        return type_matrix[attacker_type][defender_type]
    else:
        return 1.0  # Default to neutral damage

# Example usage:
var attacker_type = "Fire"
var defender_type = "Grass"
var damage_multiplier = getDamageMultiplier(attacker_type, defender_type)
print("Damage multiplier:", damage_multiplier)

# Output:
# Damage multiplier: 2.0  # Fire is strong against Grass

yes, remember, this is just one type attacker skill vs one type defender. current pokemon game can have 2 type max, so having this “table” data will be useful long run
because you just need to multiply the value when an attack hitting pokemon with 2 types

ye ill prob add the two type as a one type like “Water-Ground” when i get to adding said Pokémon

that will be a long list , you can just take the effectiveness value of water and ground multiplied, as easy as that

1 Like

sounds good because there would be 171 total types :skull:

1 Like

All seems to work!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.