Jump to content

BG2 modder resource - providing immunities, elven sleep/charm resistance, and more

Recommended Posts

UPDATE: As of v11, more macros (and an extensible system) are available. This post provides the detail; all of the information provided below should be considered deprecated by the new how-to.


Attached to this post is a collection of macros, developed primarily for the BG2 Fixpack, to assist modders with item/spell/creature development. These were originally developed to fix a number of resources in the game that provided incomplete immunities--e.g. an item that provided immunity to sleep wouldn't prevent a sleep portrait icon, or a free action item would still allow strings such as 'held' to be applied. The macros are written such that you apply them to an item, creature, or spell and the macro will detect and adjust its patching accordingly.

All of the macros work in the same fashion. They will search through the effects on the target resource, find the relevant one, and then clone that effect into a full-fledged immunity. For example, the cd_immunity_charm macro will find the immunity to charm effect (opcode 101 with parameter2 equal to 5) and then duplicate that effect into everything that charm immunity should provide: prevent the portrait icons for charm, dire charm, and domination; prevent the strings 'Charmed', 'Dire Charmed', and 'Dominated'; prevent the visual effect spnwchrm.vvc; and display the mind shield portrait icon. Since these effects get cloned from the main immunity their timing, power, duration, saves, susceptibility to dispel/bypass magic resistance, targeting, etc. will match the original immunity. Because of this, any errors in the original immunity will be propagated into the other effects, so double-check your original effect before you run these macros.

These effects will only be added if they don't exist already, and some effects are ignored in special cases (i.e. only joinable NPCs have their portrait icons exposed, so monster weapons that can't drop don't care about preventing, removing, and/or setting portrait icons). While most of these address immunities, there are some other goodies included.

These macros can be used in two ways--you could include the library with your mod and then apply these as the mod gets installed, or you could run these on your mod items and use the now-patched files, eliminating the need for inclusion of the library with your mod. In both cases you'll need to at least include the effect that the macro needs to use as a key, e.g. running the cd_immunity_sleep on an item/spell/creature won't do anything if an immunity to sleep effect is not already present. These macros are relevant for BG2, Tutu, BGT, and (once released) BG2EE games. A typical usage would be something like:

INCLUDE ~MyMod/lib/bg2fp_effect_batches.tpa~

COPY ~MyMod/itm/item1.itm~ ~override~
LAUNCH_PATCH_MACRO ~cd_immunity_confusion~

Finally, the macro listing, and what existing effects they key off of:

This one is different from the rest in that it should only be run on items or spells which cause sleep or charm effects. This will add all of the effects needed to allow elves (90%) and half-elves (30%) their normal chance to resist charm or sleep. It will detect the sleep or charm effect and add effects to call the relevant EFFs, adjusted for the probabilities and targeting of the underlying charm/sleep effect. Please note that, while the effects are added, they will not actually provide immunity for elves and half-elves unless another source, such as the BG2 Fixpack, provides the EFF files. (You are welcome, of course, to include the EFF files in your own mod--grab all of the cdelfxxx.eff files from the bg2fixpack/copy folder.)

This removes all effects of fear, but does not provide an ongoing immunity to fear effects. This macro keys off of an effect with opcode 161 (fear removal) and adds a removal of the panic icon. On EE games, this macro will also add explicit removal of the Horror spell (spin105 and spwi205) to remove the spinny-head animation. For immunity to fear, see the cd_immunity_fear macro below.

This macro turns a blindness effect into full blindness by adding the blinded portrait icon and displays the 'blinded' string.

Items and spells that dispel magic often miss many of the subsidiary effects. This will key off of a dispel magic effect (opcode 58) and add cures for feeblemind and deafness, destruction of illusionary creatures, and will purge all of the redundant magical weapon destruction codes (these are destroyed by the main dispel effect).

This will key off of an immunity to the blindness effect and prevent the blind icon as well as the 'Blind' and 'Blinded' strings.

This will key off of an immunity to the charm effect and prevent charm, dire charm, and dominated icons; prevent 'Charmed', 'Dire Charmed', and 'Dominated' strings; prevent the common charm visual spnwchrm.vvc; and add a mind shield portrait icon.

This will key off of an immunity to the confusion effect and prevent rigid thinking, confused, and chaos icons; prevent 'Confused' and 'Rigid Thinking' strings; and prevent the common charm visual spconfus.vvc.

This will key off of an immunity to the deafness effect and prevent the deaf icon as well as the 'Deaf' string.


These three are listed together since there is an unfortunate amount of overlap between disease and poison. There are both poison (25) and disease (78) opcodes that provide damage over time, but there are also ways to inflict poison-type damage. As such, these three are meant to provide for three circumstances: something that protects against disease should just use the cd_immunity_disease macro, which will turn immunity to the disease opcode (78) into protection from the nauseated icon as well as the 'Diseased' and 'Stricken by a foul disease' strings. Items that just protect against poison (i.e. the Periapt of Proof against Poison) should just use the cd_immunity_poison macro, which keys off an immunity to poison and prevents the poison and bleeding icons, prevents the 'Poison' and 'Poisoned' strings, and uses the protection from poison icon. Items which protect against both disease and poison, such as the Ring of Gaxx, should run all three macros. The cd_immunity_poison_resistance simply adds 100% reduction from poison damage, but only if the item/spell/creature already has immunities to both disease (78) and poison (25).

This will key off of an immunity to the entangle effect and prevent the entangled icon. Since entanglement spells typically provide subsidiary penalties (i.e. movement rates and AC penalties) most entangle spells are explicitly blocked--otherwise the target would get immunity to entangle, but still get other penalties.

This will key off of an immunity to either horror (24), morale modifier (23), or morale break modifier (106). It will add immunities to all three of these as well as curing existing fear, prevent and remove the panic icon, display the resist fear icon, disable the 'Panic' string, prevent the horror spinny-head animation, and reset morale.

This will simply prevent the feeblemind icon if an immunity to the feeblemind effect is found.

Free action is complicated in the best of circumstances, requiring about 50 effects or so to get right. This macro keys off of an immunity to haste, slow, paralyzation, movement rate change, entangle, web, grease, or hold and will turn them into full blown free action: immunities to all of the above, curing existing hold/paralyzation/etc. and their related portrait icons, setting movement to normal, and adding a free action icon. This macro, in turn, will cycle through other relevant macros to fully flesh out its effects: cd_immunity_entangle, cd_immunity_grease, cd_immunity_haste, cd_immunity_hold, cd_immunity_slow, and cd_immunity_web. If the Fixpack's OBC 'Change Free Action to Protect Against Stun' component is installed, this will also extend free action to prevent stun and run the cd_immunity_stun macro. Otherwise, stun immunity will be removed.

This will simply prevent the grease icon if an immunity to the grease effect is found.

This will key off an immunity to the haste effect and will prevent the 'Hasted' string as well as the haste icon. Since most haste spells include other effects (i.e. fatigue), explicit spell protections against common haste spells are also added.

This will turn an immunity to one of the three hold effects (109, 175, or 185) into full-blown immunity. The macro will add immunities to hold (175) and paralyze (109); however, if there is not already an immunity to opcode 185 (special hold) one will not be added. Opcode 185 is generally used by spells for special situations and spells/items/creatures should, in general, not be immune. The macro will also prevent the hold icon, prevent the 'Held' string, and disable two common animations for hold effects, spmindat.vvc and spflayer.vvc.

This will simply prevent the 'Invisible' string if an immunity to invisibility effect is found.

This will simply prevent the 'Dispel Invisible' string if an immunity to detect invisibility effect is found.

This will simply prevent the 'Vorpal Hit' and 'Death' strings if an immunity to kill target (13) effect is found. Immunity to the slay effect (55) is handled by the cd_immunity_slay macro.

This will key off an an immunity to level drain effect and prevent the level drain icon, display a negative plane protection icon, and prevent the strings 'One Level Drained', 'Two Levels Drained', 'Three Levels Drained', 'Four Levels Drained', and 'Five Levels Drained'.

This will simply prevent the 'Petrified' string if an immunity to petrification (134) effect is found. Not that paralyze (109) is handled by the cd_immunity_hold macro.

This will add explicit protections from Polymorph Other, Sphere of Chaos, and wild surge: polymorph to any immunity to polymorph effects.

This macro will key off of an explicit immunity to any of the 17 psionic spells in BG2 and make sure that all 17 are covered: spin542 (psionic disintegrate), spin543 (psionic inflict pain), spin544 (psionic superior invisibility), spin545 (psionic life drain), spin546 (psionic inertial barrier), spin547 (psionic project force), spin774 (psionic maze), spin775 (psionic mind blast), spin804 (psionic emotion: kill), spin834 (psionic blast), spin909 (psionic ego whip), spin910 (psionic domination), spin911 (psionic ballistic), spin912 (psionic detonate), spin959 (ulitharid psionic blast), spin974 (psionic blast), and spin975 (mind flayer domination). There is one special psionic (spin727) that is used to provide a warning in the BG2 sewers that is excluded from protection.

This macro will key off an immunity to silence and prevent the silenced icon as well as the 'Silence' and 'Silenced' strings.

This will simply prevent the dying icon if an immunity to slay (55) effect is found. Immunity to the kill effect (13) is handled by the cd_immunity_kill_target macro.

This will key off of an immunity to either sleep (39) or the power word: sleep (217) opcodes. It will provide immunity to both as well as preventing the sleep icon and the 'Sleep' string.

This will key off an immunity to the slow effect and will prevent the slow icon. Since slow is generally accompanied by a lot of related effects, explicit immunities to common slow spells are also included.

This is a very broad macro. It will detect any sort of immunity to spell levels and add all relevant protections by level, so you could run this against an item that provides immunity to 1st level spells as well as something like globe of invulnerability and both will be patched correctly. This mainly addresses area-of-effect spells which typically bypass these immunities (skull trap working against globes of invulnerability is probably the best-known example of this) by adding explicit immunities to these spells.

This will key off an immunity to stun (45) or power word: stun (210). It will prevent both opcodes as well as prevent the stun icon and the 'Stun' and 'Stunned' strings.

This will key off an immunity to web and will prevent the webbed icon and the 'Held' string. Since web generally uses the paralyze opcode (109) to freeze its target, immunity to paralyze is also added.

Link to comment

WOW. Just stumbled on this while looking around for the best way to implement some immunity HLAs.


Is this stuff more or less up-to-date? Will this work with the newest versions of the EE games? Can we simply make a spell with, say, Hold immunity and then just

COPY ~mymod/immunities/d5freeac.spl~ ~override~
   LPM cd_immunity_free_action

...instead of mucking around forever in NI? Because, again... WOW.

Link to comment

I think I've written cd_immunity_casting_failure since, and I suspect the elven charm/sleep resistance is missing PW: Sleep protection, but otherwise these should be good. I should probably externalize the string protections so that these can be run against IWDEE and BGEE as well.

Link to comment


This topic is now archived and is closed to further replies.

  • Create New...