Using Modules to determine resistances

  1. What do you want to achieve? Different damage “types,” similar to Pokémon, within a ModuleScript that can be referenced as a cross-sectional table. For example: if the damage is fire, what is it strong against?

  2. What is the issue?
    I’m not sure where to begin.

  3. What solutions have you tried so far? I have laid out a few variables in a ModuleScript but cannot figure out a way to get the information I want. It could be that my approach is just way off.

Currently, when an entity is damaged, the server script checks a Module for the damage type to see if it exists.

local CMod = require(CombatModule)

—when the damage event is fired by client, a variable is sent called “dmgtype” which is a StringValue like “Normal”

print(CMod.dmgtype)

Here’s an example of what I have in CombatModule:

local AttackStrengths = {
         Normal = {WeakAgainst = “Ice”, StrongAgainst = “Thunder”},
}

return AttackStrengths

Is my approach completely wrong? Also, I apologize for any mistakes, I’m on mobile and cannot actually paste my codes here.

1 Like

It’s a good idea. You’ll want each element to be strong or weak against several elements though, so set WeakAgainst and StrongAgainst to tables instead of strings:

AttackStrengths = {
         Normal = {WeakAgainst = {“Ice”, "Water"}, StrongAgainst = {“Thunder”}},
}
1 Like

Thanks, but how do I actually pull and compare weaknesses to the type of the enemy? Currently, printing CMod.dmgtype returns an error.

I suppose the question is how do I check that table of weaknesses and strengths to see if the damage value should be increased or lowered?

Something like

function isStrongAgainst(element)
    return table.find(CMod.AttackStrengths[element].StrongAgainst) ~= nil
end

function isWeakAgainst(element)
    return table.find(CMod.AttackStrengths[element].WeakAgainst) ~= nil
end
1 Like