Look in nwnx_defenses for GetEffectDamageResistance. It can be done via nwscript as well, though the nwnx function is faster. It also, I believe, allows for stacking damage resistances and debuffs of them, though I don't recall offhand if our ability to do that comes from that plugin or elsewhere, and you don't need that to do what you want.
GetTrueDamageImmunity, also in nwnx_defenses, essentially gets their total immunity to the specified element. It handles stacking errors in nwscript, or did - I don't remember if they were all fixed in 1.69 or not, and they're pretty uncommon scenarios either way (iirc bugged when stacking past 255, though I could be misremembering). The main thing it does that you can't easily do otherwise in nwscript is to check for absolute damage immunity ala RDD. Again, not something mission-critical for most applications. We rely on it mainly because we like to do partial absolute immunity for some situations - immunity that can be dubuffed by stacking vulns, but down to a minimum value greater than 0 (like 50%).
Funky