Table for damage multipliers?

I’m looking for a way to create a table that’ll detect the Players typing as opposed to the rivals and apply multiplies accordingly?

I.e. Player = Water, Rival = Fire. Damage = x1.5
I.e. Player = Water, Rival = Water. Damage = x1
I.e. Player = Fire, Rival = Water. Damage =x0.5

1 Like

we’d need a lot more context than what you’re giving. also this is support not “do it for me”

1 Like

Hence the term “I’m looking for a way”.

Self explanatory, really - I’m looking for a methodology of comparing the Players typing to the Rivals typing and applying multiplies accordingly.

Another example being -
Fire vs Water : Multiplier = x0.5
Water vs Water : Multiplier = x0
Water vs Fire : Multiplier = x1.5

Attack : BaseDamage = 50 x Multiplier.

You could fit everything in a dictionary in which the keys store the player’s damage type and the corresponding value is another dictionary containing the rival type and damage multiplier to apply. Going off your example from your first post,

local damageMultipliers = {
	Fire = {
		Water = 0.5,
	},
	
	Water = {
		Fire = 1.5,
		Water = 1,
	}
}

So if the player’s type is “Water” and the rival’s type is “Fire,” the damage multiplier can be retrieved using damageMultipliers.Water.Fire, or more generally, damageMultipliers[playerType][rivalType].

1 Like

im going to assume you mean the player’s ‘type’ not ‘typing’ as typing is a verb and type is the noun you’re most likely referring to :nerd_face:

i’d make a comparator table that can be indexed with type 1 and provide a result

local comparing = {
Water = function(input)
if input == "Fire" then
return 1.5
elseif input == "Water" then
return 0
end
end,
Fire = function(input)
if input == "Water" then
return 0.5
elseif input == "Fire" then
return 0
end
end
}

call via local Multiplier = comparing[Plr1Type](Plr2Type) then do your damage math

this is even better if your logic is simple, I ignorantly used a function in case of special handling but I realize that isn’t even necessary, good code

Brilliant, thank you!
To add to this, if the Player has multiple types - For this case say Fire & Water type Vs Grass type how would a formula for that work?

If you want the multipliers to stack multiplicatively (e.g. x1.5 multiplier plus a x0.5 multiplier produces a x0.75 multiplier), you can use a for loop.

local currentDamageMultiplier = 1

-- Loop through all the player's types 
for i, playerType in player.Types do
	
	currentDamageMultiplier *= damageMultipliers[playerType][rivalType]
	
end
1 Like

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