Author Sticky: Post Working Scripts Here
BPLlama Posted: Thursday, 25 July 08:22AM
The Simulated Respawning Bashable Door Script

After many attempts at healing a damaged door and making a bashed door respawn I realized that this was impossible using the NWN scripting language. This script is a workaround which simulates damage done to the door. Attacks and spells used on the door do virtual damage, and when enough virtual damage is built up the door unlocks itself and opens.

Features:
- Door takes "virtual" damage from melee attacks, ranged attacks, and spells.
- Damage done is displayed above the door (the door "speaks" when it takes virtual damage)
- Door opens/unlocks when virtual damage is high enough
- Can easily reset virtual damage and close/lock door from another script when I want the door to respawn.
- Records if the door has already been bashed open (so you can write scipts to make the bashed door open/unlock when someone tries to close the door.)
- Critical Attacks work
- Monk unarmed attacks work
- Weapon Specialization/Improved Criticals work
- Power Attack/Improved Power Attack work
- Strength damage bonus works
- Transition target door is also damaged/bashed open

Problems:
- Item properties, beneficial spells, and other things that increase attack damage have no effect.
- Since I do my own attack roll, the animations don't always match up.
- Can't get rid of the "Weapon Ineffective" and "0"'s that float up from the door as it is attacked.
- I want Knock to work, but it seems you can't cast Knock at plot objects.
- I can't access the door's hardness from the script. I use the fortitude save for damage resistance instead. (Considering a modification where I store the hardness in a local variable when the module initializes).
- Can't get creature weapon damage. The script assumes all creature attacks do 1d8.
- Not sure I'm calculating the damage correctly for all the spells, since all I have to go on are the descriptions in the game manual.
- Not sure if I'm applying critical damage correctly. I currently multiply by the critical damage multiplier for the weapon after adding all the various damage bonuses (strength, weapon specialization, power attack, etc)

Usage:
Create a plot door (or two identical plot doors transitioned together). Place the following scripts in the "OnPhysicalAttacked" and "OnSpellCastAt" slots. The respawn script can be triggered from anywhere when you want the door to heal itself and close/lock.

OnPhysicalAttacked script:
NWScript:
void main()

{

    object oPC = GetLastAttacker();

    object oTargetDoor = GetTransitionTarget(OBJECT_SELF);

    int nAttackRoll = 0;

    int nPhysicalDamage = 0;

    int nCritThreat = 20;

    int nCritMult = 2;

    object oWeapon;

    int nWeaponType;

    // Is transition target a door?

    if (GetObjectType(oTargetDoor) != OBJECT_TYPE_DOOR) {

        oTargetDoor = OBJECT_INVALID;

    }

    // Can't bash an already bashed door

    if (GetLocalInt(OBJECT_SELF,"Bashed") == TRUE) {

        return;

    }

    nAttackRoll = d20(1);

    // Miss on natural 1

    if (nAttackRoll == 1) {

        return;

    }

    // Determine door damage

    if (GetObjectType(oPC) == OBJECT_TYPE_CREATURE) {

        oWeapon = GetLastWeaponUsed(oPC);

        if (oWeapon != OBJECT_INVALID) {

            nWeaponType = GetBaseItemType(oWeapon);

            switch (nWeaponType) {

                // 2d6 weapons

                case BASE_ITEM_GREATSWORD:

                    nPhysicalDamage = d6(2);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_GREAT_SWORD, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_GREAT_SWORD, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                // 1d12 weapons

                case BASE_ITEM_GREATAXE:

                    nPhysicalDamage = d12(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_GREAT_AXE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_GREAT_AXE, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                // 1d10 weapons

                case BASE_ITEM_BASTARDSWORD:

                    nPhysicalDamage = d10(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_BASTARD_SWORD, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_BASTARD_SWORD, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_HALBERD:

                    nPhysicalDamage = d10(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_HALBERD, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_HALBERD, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_HEAVYCROSSBOW:

                    nPhysicalDamage = d10(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_HEAVY_CROSSBOW, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_HEAVY_CROSSBOW, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    break;

                case BASE_ITEM_HEAVYFLAIL:

                    nPhysicalDamage = d10(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_HEAVY_FLAIL, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_HEAVY_FLAIL, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_KATANA:

                    nPhysicalDamage = d10(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_KATANA, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_KATANA, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                // 2d4 weapons

                case BASE_ITEM_SCYTHE:

                    nPhysicalDamage = d4(2);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SCYTHE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SCYTHE, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 4;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                // 1d8 weapons

                case BASE_ITEM_LIGHTCROSSBOW:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_LIGHT_CROSSBOW, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_LIGHT_CROSSBOW, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    break;

                case BASE_ITEM_SHORTSPEAR:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SPEAR, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SPEAR, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_BATTLEAXE:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_BATTLE_AXE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_BATTLE_AXE, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_LIGHTFLAIL:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_LIGHT_FLAIL, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_LIGHT_FLAIL, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_LONGSWORD:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_LONG_SWORD, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_LONG_SWORD, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_MORNINGSTAR:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_MORNING_STAR, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_MORNING_STAR, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_WARHAMMER:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_WAR_HAMMER, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_WAR_HAMMER, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_DIREMACE:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_DIRE_MACE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_DIRE_MACE, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_TWOBLADEDSWORD:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_TWO_BLADED_SWORD, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_TWO_BLADED_SWORD, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_DOUBLEAXE:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_DOUBLE_AXE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_DOUBLE_AXE, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_LONGBOW:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_LONGBOW, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_LONGBOW, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    break;

                // 1d6 weapons

                case BASE_ITEM_KAMA:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_KAMA, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_KAMA, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_THROWINGAXE:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_THROWING_AXE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_THROWING_AXE, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_HANDAXE:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_HAND_AXE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_HAND_AXE, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_LIGHTMACE:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_LIGHT_MACE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_LIGHT_MACE, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_SICKLE:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SICKLE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SICKLE, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_SHORTSWORD:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SHORT_SWORD, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SHORT_SWORD, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_CLUB:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_CLUB, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_CLUB, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_QUARTERSTAFF:

                case BASE_ITEM_MAGICSTAFF:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_STAFF, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_STAFF, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_RAPIER:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_RAPIER, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_RAPIER, oPC)) {

                        nCritThreat = 16;

                    } else {

                        nCritThreat = 18;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_SCIMITAR:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SCIMITAR, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SCIMITAR, oPC)) {

                        nCritThreat = 16;

                    } else {

                        nCritThreat = 18;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_SHORTBOW:

                    nPhysicalDamage = d6(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SHORTBOW, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SHORTBOW, oPC)) {

                        nCritThreat = 19;

                    }

                    nCritMult = 3;

                    break;

                // 1d4 weapons

                case BASE_ITEM_DAGGER:

                    nPhysicalDamage = d4(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_DAGGER, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_DAGGER, oPC)) {

                        nCritThreat = 17;

                    } else {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_DART:

                    nPhysicalDamage = d4(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_DART, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_DART, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_LIGHTHAMMER:

                    nPhysicalDamage = d4(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_LIGHT_HAMMER, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_LIGHT_HAMMER, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                case BASE_ITEM_SLING:

                    nPhysicalDamage = d4(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SLING, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SLING, oPC)) {

                        nCritThreat = 19;

                    }

                    break;

                // 1 damage weapons

                case BASE_ITEM_SHURIKEN:

                    nPhysicalDamage = 1;

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_SHURIKEN, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_SHURIKEN, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

                // Creature attack.  Assume 1d8.

                case BASE_ITEM_CREATUREITEM:

                case BASE_ITEM_CBLUDGWEAPON:

                case BASE_ITEM_CPIERCWEAPON:

                case BASE_ITEM_CSLASHWEAPON:

                case BASE_ITEM_CSLSHPRCWEAP:

                    nPhysicalDamage = d8(1);

                    if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_CREATURE, oPC)) {

                        nPhysicalDamage += 2;

                    }

                    if (GetHasFeat(FEAT_IMPROVED_CRITICAL_CREATURE, oPC)) {

                        nCritThreat = 19;

                    }

                    nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

                    break;

            }

            // Now do item properties

        } else {

            // Unarmed strike

            int nMonkLevel = GetLevelByClass(CLASS_TYPE_MONK, oPC);

            if ((GetCreatureSize(oPC) == CREATURE_SIZE_SMALL) ||

                (GetCreatureSize(oPC) == CREATURE_SIZE_TINY)) {

                if (nMonkLevel <= 3) {

                    nPhysicalDamage = d4(1);

                } else if (nMonkLevel <= 7) {

                    nPhysicalDamage = d6(1);

                } else if (nMonkLevel <= 11) {

                    nPhysicalDamage = d8(1);

                } else if (nMonkLevel <= 15) {

                    nPhysicalDamage = d10(1);

                } else {

                    nPhysicalDamage = d6(2);

                }

            } else {

                if (nMonkLevel <= 3) {

                    nPhysicalDamage = d6(1);

                } else if (nMonkLevel <= 7) {

                    nPhysicalDamage = d8(1);

                } else if (nMonkLevel <= 11) {

                    nPhysicalDamage = d10(1);

                } else if (nMonkLevel <= 15) {

                    nPhysicalDamage = d12(1);

                } else {

                    nPhysicalDamage = d20(1);

                }

            }

            if (GetHasFeat(FEAT_WEAPON_SPECIALIZATION_UNARMED_STRIKE, oPC)) {

                nPhysicalDamage += 2;

            }

            if (GetHasFeat(FEAT_IMPROVED_CRITICAL_UNARMED_STRIKE, oPC)) {

                nCritThreat = 19;

            }

            nPhysicalDamage += GetAbilityModifier(ABILITY_STRENGTH,oPC);

        }

        // Now look for effects on the player

        // Now take power attacks into account

        if (GetLastAttackMode(oPC) == COMBAT_MODE_POWER_ATTACK) {

            nPhysicalDamage += 5;

        } else if (GetLastAttackMode(oPC) == COMBAT_MODE_IMPROVED_POWER_ATTACK) {

            nPhysicalDamage += 10;

        }

        // Critical hit?

        if (nAttackRoll >= nCritThreat) {

            nPhysicalDamage *= nCritMult;

        }

        // Take door hardness into account

        nPhysicalDamage -= GetFortitudeSavingThrow(OBJECT_SELF);

        if (nPhysicalDamage < 0) {

            nPhysicalDamage = 0;

        }

        // Retrieve existing damage, and add new damage to it.

        int nDoorDamage = GetLocalInt(OBJECT_SELF,"VDamage");

        nDoorDamage += nPhysicalDamage;

        SetLocalInt(OBJECT_SELF,"VDamage",nDoorDamage);

        if (oTargetDoor != OBJECT_INVALID) {

            SetLocalInt(oTargetDoor,"VDamage",nDoorDamage);

        }

        // Give damage report

        AssignCommand(OBJECT_SELF,ActionSpeakString(IntToString(nPhysicalDamage) + " damage",TALKVOLUME_TALK));

        if (oTargetDoor != OBJECT_INVALID) {

            AssignCommand(oTargetDoor,ActionSpeakString(IntToString(nPhysicalDamage) + " damage",TALKVOLUME_TALK));

        }

        SendMessageToPC(oPC,"You bashed the door for " + IntToString(nPhysicalDamage) + " damage.");

        // Open if door has taken too much damage

        if (nDoorDamage >= GetMaxHitPoints(OBJECT_SELF)) {

            SendMessageToPC(oPC,"You have bashed the door open.");

            SetLocked(OBJECT_SELF,FALSE);

            AssignCommand(OBJECT_SELF,ActionOpenDoor(OBJECT_SELF));

            SetLocalInt(OBJECT_SELF,"Bashed",TRUE);

            if (oTargetDoor != OBJECT_INVALID) {

                SetLocked(oTargetDoor,FALSE);

                AssignCommand(oTargetDoor,ActionOpenDoor(oTargetDoor));

                SetLocalInt(oTargetDoor,"Bashed",TRUE);

            }

            AssignCommand(oPC,ClearAllActions());

        }

    }

}



OnSpellCastAt script:

NWScript:
void main()

{

    object oPC = GetLastSpellCaster();

    if (GetObjectType(oPC) != OBJECT_TYPE_CREATURE) {

        return;

    }

    int nCastLevel = GetCasterLevel(oPC);

    int nSpell = GetLastSpell();

    object oTargetDoor = GetTransitionTarget(OBJECT_SELF);

    int nPhysicalDamage = 0;

    int nMagicalDamage = 0;

    // Is transition target a door?

    if (GetObjectType(oTargetDoor) != OBJECT_TYPE_DOOR) {

        oTargetDoor = OBJECT_INVALID;

    }

    // Do damage based on spell type & caster level

    switch (nSpell) {

        case SPELL_SOUND_BURST:

            nMagicalDamage = d8(1);

            break;

        case SPELL_ICE_STORM:

            nMagicalDamage = d6(2);

            nPhysicalDamage = d6(3);

            break;

        case SPELL_NEGATIVE_ENERGY_RAY:

            nMagicalDamage = d6(1);

            break;

        case SPELL_SEARING_LIGHT:

            nMagicalDamage = d8(nCastLevel / 2);

            break;

        case SPELL_FLAME_STRIKE:

            nMagicalDamage = d6(2 * nCastLevel);

            break;

        case SPELL_DESTRUCTION:

            nMagicalDamage = GetMaxHitPoints(OBJECT_SELF);

            break;

        case SPELL_FIRE_STORM:

            nMagicalDamage = d6(nCastLevel);

            break;

        case SPELL_SUNBEAM:

            nMagicalDamage = d6(3);

            break;

        case SPELL_STORM_OF_VENGEANCE:

            nMagicalDamage = d6(3);

            break;

        case SPELL_FLAME_LASH:

            nMagicalDamage = d6(2);

            if (nCastLevel > 3) {

                nMagicalDamage += d6(nCastLevel - 3);

            }

            break;

        case SPELL_HAMMER_OF_THE_GODS:

            nMagicalDamage = d8(nCastLevel / 2);

            break;

        case SPELL_WALL_OF_FIRE:

        case SPELL_SHADES_WALL_OF_FIRE:

            nMagicalDamage = d6(4);

            break;

        case SPELL_RAY_OF_FROST:

            nMagicalDamage = d4(1);

            break;

        case SPELL_BURNING_HANDS:

            nMagicalDamage = d4(nCastLevel);

            break;

        case SPELL_MAGIC_MISSILE:

            nMagicalDamage = d4(nCastLevel / 2 + 1) + (nCastLevel / 2 + 1);

            break;

        case SPELL_MELFS_ACID_ARROW:

            nMagicalDamage = d6(3);

            break;

        case SPELL_FIREBALL:

        case SPELL_SHADES_FIREBALL:

            nMagicalDamage = d6(nCastLevel);

            break;

        case SPELL_FLAME_ARROW:

            nMagicalDamage = d6(4) + d6(4 * (nCastLevel / 4));

            break;

        case SPELL_LIGHTNING_BOLT:

            nMagicalDamage = d6(nCastLevel);

            break;

        case SPELL_NEGATIVE_ENERGY_BURST:

            nMagicalDamage = d8(1) + nCastLevel;

            break;

        case SPELL_DELAYED_BLAST_FIREBALL:

            nMagicalDamage = d8(nCastLevel);

            break;

        case SPELL_HORRID_WILTING:

            nMagicalDamage = d8(nCastLevel);

            break;

        case SPELL_INCENDIARY_CLOUD:

            nMagicalDamage = d6(4);

            break;

        case SPELL_METEOR_SWARM:

            nMagicalDamage = d6(20);

            break;

        case SPELL_CALL_LIGHTNING:

            nMagicalDamage = d6(nCastLevel);

            break;

        case SPELL_CHAIN_LIGHTNING:

            nMagicalDamage = d6(nCastLevel);

            break;

        case SPELL_CONE_OF_COLD:

        case SPELL_SHADES_CONE_OF_COLD:

            nMagicalDamage = d6(nCastLevel);

            break;

    }

    // Reduce physical damage by door hardness

    nPhysicalDamage -= GetFortitudeSavingThrow(OBJECT_SELF);

    if (nPhysicalDamage < 0) {

        nPhysicalDamage = 0;

    }

    // Apply damage

    int nDoorDamage = GetLocalInt(OBJECT_SELF,"VDamage");

    nDoorDamage += nPhysicalDamage + nMagicalDamage;

    if (oTargetDoor != OBJECT_INVALID) {

        SetLocalInt(oTargetDoor,"VDamage",nDoorDamage);

    }

    // Report damage

    AssignCommand(OBJECT_SELF,ActionSpeakString(IntToString(nPhysicalDamage + nMagicalDamage) + " damage",TALKVOLUME_TALK));

    if (oTargetDoor != OBJECT_INVALID) {

        AssignCommand(oTargetDoor,ActionSpeakString(IntToString(nPhysicalDamage + nMagicalDamage) + " damage",TALKVOLUME_TALK));

    }

    SendMessageToPC(oPC,"You did " + IntToString(nPhysicalDamage + nMagicalDamage) + " to the door.");

    // Open door if enough damage is done

    if (nDoorDamage >= GetMaxHitPoints(OBJECT_SELF)) {

        SendMessageToPC(oPC,"You have bashed the door open.");

        SetLocked(OBJECT_SELF,FALSE);

        AssignCommand(OBJECT_SELF,ActionOpenDoor(OBJECT_SELF));

        SetLocalInt(OBJECT_SELF,"Bashed",TRUE);

        if (oTargetDoor != OBJECT_INVALID) {

            SetLocked(oTargetDoor,FALSE);

            AssignCommand(oTargetDoor,ActionOpenDoor(oTargetDoor));

            SetLocalInt(oTargetDoor,"Bashed",TRUE);

        }

        AssignCommand(oPC,ClearAllActions());

    }

}



Example Respawn script:

NWScript:
void main()

{

    object oDoor;

    object oPC;

    oDoor = GetNearestObject(OBJECT_TYPE_DOOR);

    if (oDoor != OBJECT_INVALID) {

        AssignCommand(oDoor,ActionCloseDoor(oDoor));

        SetLocked(oDoor,TRUE);

        SetLocalInt(oDoor,"VDamage",0);

        SetLocalInt(oDoor,"Bashed",FALSE);

    }

}



In my module I'm "healing" and closing/locking all doors in an arena between matches. I've personally added short scripts to the "OnLocked" and "OnClose" events of my doors as well, checking the "Bashed" local variable and refusing to let the door be closed or locked if "bashed" is true.

Feel free to E-mail me with any suggestions, complaints, ideas, or modifications that you come up with.

Later!

Jason Attard