Author Sticky: Post Working Scripts Here
Koyasha Posted: Sunday, 07 July 07:54AM
Name: Take 20 bypassers.

What it does: These scripts replace some of the functions which the game automatically causes the player to take 20 on (without giving any of the appropriate penalties for taking 20, mind you, such as extra time passing). So the main purpose of these is to prevent the players from taking 20. Note that the locked item scripts need to have the items they're guarding tagged unpickable, so that the PC's can't bypass the script by just picking the lock normally.

Notes: The first script is for locked chests. It won't work on doors (don't ask me why, the GetLastUsed doesn't seem to work when it's put into a door's OnFailToOpen event).

The second script is for locked doors. It probably works on chests, but I include them both because the chest one is better, in that it doesn't check the nearest PC, but the PC that actually clicked on the chest (yeah, probably going to be the same one most of the time, but there's always a chance another PC is closer to the chest/door than the clicking PC).

The third script is for traps on the ground. It also requires a waypoint to be placed to shunt the player back to, should they fail to disarm the trap, and yet, not set it off.

The fourth script is for trapped doors. I have no idea why it doesn't work so well on trapped chests (it allows the chest to remain open even if the trap was only detected, not disarmed). I've tried ClearAllActions and a number of other things, but so far, nothing gets the chest to close itself so that the PC can't access it's inventory without actually disarming the trap.

The last script is complementary to the fourth, to make sure that PC's take the trap damage if they attack the trapped door.

This one is for chests. Put it in the OnUsed event of the chest and that's all you need. Set the DC for the lock normally in the chest's options. This script will probably work on any placeable object with an OnOpen that can be locked.
NWScript:
//::///////////////////////////////////////////////

//:: Name: Normal Unlock Skill Check

//:://////////////////////////////////////////////

//:://////////////////////////////////////////////

//:: Created By: Koyasha Jurai

//:: Created On: 06 July 2002

//:://////////////////////////////////////////////

//Notes: This script must be in the OnUsed of whatever object is locked (it will

//either do nothing, or crash the system if it is placed on something that cannot

//be locked).  In addition to this, the object must be set to unpickable when it

//is created in the toolset, this prevents the system from using the normal open

//locks routine to open the lock with a Take 20 roll.

void main()

{

    object oPC = GetLastUsedBy();

    int nSkill = GetSkillRank(SKILL_OPEN_LOCK, GetLastUsedBy());

    AssignCommand (oPC, ClearAllActions());

    if (GetLocked(OBJECT_SELF) == TRUE)

    {

        if (nSkill >= 1)

        {

            ApplyEffectToObject (DURATION_TYPE_TEMPORARY, EffectParalyze(), oPC, 6.0);

            ActionWait(6.0);

            if (d20(1) + nSkill >= GetLockUnlockDC(OBJECT_SELF))

            {

            SetLocked(OBJECT_SELF, FALSE);

            }

            else

            {

            SpeakString("You were unsuccessful in picking this lock.", TALKVOLUME_TALK);

            }

        }

        else

        {

        SpeakString("You have no lockpicking skill with which to open this lock.", TALKVOLUME_TALK);

        }

    }

}



This one is for locked doors. Put it in OnFailToOpen. Like the chest one, it'll get the DC of the lock normally, so just input the DC of the lock as usual when you create the door.

NWScript:
//::///////////////////////////////////////////////

//:: Name: Normal Unlock Skill Check for Doors

//:://////////////////////////////////////////////

//:://////////////////////////////////////////////

//:: Created By: Koyasha Jurai

//:: Created On: 06 July 2002

//:://////////////////////////////////////////////

//Notes: This script must be in the OnUsed of a locked door (it will

//either do nothing, or crash the system if it is placed on something that cannot

//be locked).  In addition to this, the door must be set to unpickable when it

//is created in the toolset, this prevents the system from using the normal open

//locks routine to open the lock with a Take 20 roll.

void main()

{

    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF);

    int nSkill = GetSkillRank(SKILL_OPEN_LOCK, GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF));

    AssignCommand (oPC, ClearAllActions());

    if (GetLocked(OBJECT_SELF) == TRUE)

    {

        if (nSkill >= 1)

        {

            ApplyEffectToObject (DURATION_TYPE_TEMPORARY, EffectParalyze(), oPC, 6.0);

            ActionWait(6.0);

            if (d20(1) + nSkill >= GetLockUnlockDC(OBJECT_SELF))

            {

            SetLocked(OBJECT_SELF, FALSE);

            }

            else

            {

            SpeakString("You were unsuccessful in picking this lock.", TALKVOLUME_TALK);

            }

        }

        else

        {

        SpeakString("You have no lockpicking skill with which to open this lock.", TALKVOLUME_TALK);

        }

    }

}



This is the trap script for floor traps. Lay down a generic trigger, and put this script in the OnEnter. Then make a waypoint matching the waypoint tag listed in the script, and put that just before the trap (doesn't work so well if the PC's could come at the trap from either side, so try to ensure the PC's can only approach the trap from the 'right' side). The other variables also have to be set in the script (DC of the search, disarm, and DC to keep from setting it off in a disarm attempt) so you'll need a different copy of the script for each trap you create. The parameters for the trap's effect should also be edited (currently 25 points of fire damage at normal power).

NWScript:
//::///////////////////////////////////////////////

//:: Name: Trap Script with failure set-off chance and no take 20.

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

This script must be attached to the OnEnter event of a generic trigger.  It requires

a waypoint placed 'before' the trap - a place where the character who detects, but

but cannot disarm or fails to disarm the trap will jump back to in order to avoid it

and in order to prevent the character from walking right over the trap area without

setting it off.  It also has a number of easily-adjustable variables, such as the

Search DC to detect it, the Disable Trap DC to disarm it, and the Disable Trap DC that

must be beat in order to avoid setting it off.  Flaws in this trap script are that

it must automatically assume that the player, if she posesses the Disable Trap skill,

wants to attempt to disarm the trap (this is particularly dangerous for players with

a very low Disable Trap skill, as they will automatically attempt to disable the trap,

probably fail, and set it off in the process).  It would be possible to add in the

various options through a dialogue menu, however, so that the character does not

attempt to disarm the trap unless they want to.

In order to cause the trap to infinitely repeat until it is disarmed, comment out or

remove the lines which I have indicated below, in the main body of the script.

*/

//:://////////////////////////////////////////////

//:: Created By: Koyasha Jurai

//:: Created On: 06 July 2002

//:://////////////////////////////////////////////

void main()

{

//The following line indicates the Search DC to detect the trap.

    int nSearchDC = 15;

//The following line indicates the Disable Trap DC to disarm the trap.

    int nDisarmDC = 20;

//The following line indicates the number which will set off the trap, if the Disable

//Trap roll is equal to or less than.

    int nDisarmSetOff = 15;

//The following line contains the effect of setting off the trap - currently 25 points

//of normal power fire damage.  Alter the number, damage type, and damage power to

//achieve different effects.

    effect eDamage = EffectDamage(25, DAMAGE_TYPE_FIRE, DAMAGE_POWER_NORMAL);

//The following line is the visual effect which accompanies the trap being set off.

//It's only purpose is to provide a visual display of the trap, and has no bearing on

//the actual functionality of the trap.

    effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);

//The following line contains the tag of the waypoint where the player will be jumped

//back to if they detect but cannot disarm the trap.

    object oTrapWP = GetObjectByTag("TrapWPJumpBack");

    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF);

    int nSearch = GetSkillRank(SKILL_SEARCH, oPC);

    int nDisarm = GetSkillRank(SKILL_DISABLE_TRAP, oPC);

    int nInstant = DURATION_TYPE_INSTANT;

    int nSearchCheck = d20(1);

    int nDisarmCheck = d20(1);



    if (GetLocalInt(OBJECT_SELF, "TrapSetOff") == FALSE)

    {

        AssignCommand(oPC, ClearAllActions());

        if (nSearchCheck + nSearch >= nSearchDC)

        {

            if (nDisarmCheck + nDisarm >= nDisarmDC && GetHasSkill(SKILL_DISABLE_TRAP, oPC))

            {

                AssignCommand(oPC, SpeakString("You have located a trap and disarmed it.", TALKVOLUME_TALK));

                SetLocalInt(OBJECT_SELF, "TrapSetOff", TRUE);

            }

            else

            {

                if (nDisarmCheck + nDisarm <= nDisarmSetOff && GetHasSkill(SKILL_DISABLE_TRAP, oPC))

                {

                AssignCommand(oPC, SpeakString("You have failed to disarm a trap and set it off in the attempt.", TALKVOLUME_TALK));

                ApplyEffectToObject(nInstant, eDamage, oPC);

                ApplyEffectToObject(nInstant, eVis, oPC);

                //Remove the following line in order to cause the trap to infinitely

                //repeat unless disarmed.

                SetLocalInt(OBJECT_SELF, "TrapSetOff", TRUE);

                }

                else

                {

                AssignCommand(oPC, SpeakString("You have located a trap and avoided it.", TALKVOLUME_TALK));

                AssignCommand(oPC, ActionJumpToLocation(GetLocation(oTrapWP)));

                }

            }

        }

        else

        {

        ApplyEffectToObject(nInstant, eDamage, oPC);

        ApplyEffectToObject(nInstant, eVis, oPC);

        //Remove the following line in order to cause the trap to infinitely repeat

        //unless disarmed.

        SetLocalInt(OBJECT_SELF, "TrapSetOff", TRUE);

        }

    }

}



Door trap script. Most of the variables are the same as for the floor trap one. It doesn't need a waypoint, obviously, it just re-closes the door instantly. Put this in the OnOpen of your trapped door.

NWScript:
//::///////////////////////////////////////////////

//:: Name: Door Trap Script with failure set-off chance and no take 20.

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

This script is to be attached to the OnOpen of a door.  It automatically does a search

check by rolling 1d20 and adding the character's search skill to it.  It compares this

roll to the DC of the search check, and if the search check is successful, it moves on

to the disarm stage.  If the character has any skill in Disable Trap, it automatically

does a disable trap check, again by rolling 1d20 and adding the disable trap skill.  If

the disable trap check is unsuccessful, or the character doesn't have enough skill, it

instantly re-closes the door and informs the character they detected and avoided a trap.

If the check is unsuccessful by too much (exactly how much is set below), the trap

goes off anyway.

In order to cause the trap to infinitely repeat until it is disarmed, comment out or

remove the lines which I have indicated below, in the main body of the script.

*/

//:://////////////////////////////////////////////

//:: Created By: Koyasha Jurai

//:: Created On: 06 July 2002

//:://////////////////////////////////////////////

void main()

{

//The following line indicates the Search DC to detect the trap.

    int nSearchDC = 15;

//The following line indicates the Disable Trap DC to disarm the trap.

    int nDisarmDC = 20;

//The following line indicates the number which will set off the trap, if the Disable

//Trap roll is equal to or less than.

    int nDisarmSetOff = 15;

//The following line contains the effect of setting off the trap - currently 25 points

//of normal power fire damage.  Alter the number, damage type, and damage power to

//achieve different effects.

    effect eDamage = EffectDamage(25, DAMAGE_TYPE_FIRE, DAMAGE_POWER_NORMAL);

//The following line is the visual effect which accompanies the trap being set off.

//It's only purpose is to provide a visual display of the trap, and has no bearing on

//the actual functionality of the trap.

    effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);

    object oPC = GetLastOpenedBy();

    object oTrapped = OBJECT_SELF;

    int nSearch = GetSkillRank(SKILL_SEARCH, oPC);

    int nDisarm = GetSkillRank(SKILL_DISABLE_TRAP, oPC);

    int nInstant = DURATION_TYPE_INSTANT;

    int nSearchCheck = d20(1);

    int nDisarmCheck = d20(1);



    if (GetLocalInt(oTrapped, "TrapSetOff") == FALSE)

    {

        AssignCommand(oPC, ClearAllActions());

        if (nSearchCheck + nSearch >= nSearchDC)

        {

            if (nDisarmCheck + nDisarm >= nDisarmDC && GetHasSkill(SKILL_DISABLE_TRAP, oPC))

            {

                SpeakString("You have located a trap and disarmed it.", TALKVOLUME_TALK);

                SetLocalInt(oTrapped, "TrapSetOff", TRUE);

            }

            else

            {

                if (nDisarmCheck + nDisarm <= nDisarmSetOff && GetHasSkill(SKILL_DISABLE_TRAP, oPC))

                {

                SpeakString("You have failed to disarm a trap and set it off in the attempt.", TALKVOLUME_TALK);

                ApplyEffectToObject(nInstant, eDamage, oPC);

                ApplyEffectToObject(nInstant, eVis, oPC);

                //Remove the following line in order to cause the trap to infinitely

                //repeat unless disarmed.

                SetLocalInt(oTrapped, "TrapSetOff", TRUE);

                //Also, un-comment the following line if you want the trap to infinitely

                //repeat.

                //ActionCloseDoor(oTrapped);

                }

                else

                {

                SpeakString("You have located a trap and avoided it.", TALKVOLUME_TALK);

                ActionCloseDoor(oTrapped);

                }

            }

        }

        else

        {

        ApplyEffectToObject(nInstant, eDamage, oPC);

        ApplyEffectToObject(nInstant, eVis, oPC);

        //Remove the following line in order to cause the trap to infinitely repeat

        //unless disarmed.

        SetLocalInt(oTrapped, "TrapSetOff", TRUE);

        //Also, un-comment the following line if you want the trap to infinitely repeat.

        //ActionCloseDoor(oTrapped);

        }

    }

}



Companion script for the door trap. Put it in the OnDamaged of the trapped door, to make sure the PC gets hit if she tries to bash down the door, too.

NWScript:
//:: Name: Sets off trap when object is damaged.

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

This goes with my trap scripts for doors.  It needs to be in the OnDamaged of the same

door that has the trap script on it.  It makes sure the PC's can't bash down the door

without taking the trap's effects.

*/

//:://////////////////////////////////////////////

//:: Created By: Koyasha Jurai

//:: Created On: 07 July 2002

//:://////////////////////////////////////////////

void main()

{

    object oPC = GetLastDamager();

    effect eDamage = EffectDamage(25, DAMAGE_TYPE_FIRE, DAMAGE_POWER_NORMAL);

    effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);

    int nInstant = DURATION_TYPE_INSTANT;

    ApplyEffectToObject(nInstant, eDamage, oPC);

    ApplyEffectToObject(nInstant, eVis, oPC);

    SetLocalInt(OBJECT_SELF, "TrapSetOff", TRUE);

}



And that's about it. If you find a way to improve on them, feel free to do so. Also if you find a way to fix my little glitches (particularly the door trap script not working on chests).

_________________
Well Met,
Koyasha Jurai