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].
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
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