Harvest Moon scripts (door, trap, and container)
This scripting forum is to discuss scripting and for those needing help scripting to get help from others.

Moderators: Mermut, rdjparadis

Post Reply
User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Harvest Moon scripts (door, trap, and container)

Post by Winterhawk99 »

Harvest Moon had many great scripts and script sets made by several people. Mostly Mermut and I. I recieved her permission to post them up on the scripting forum and will add some of my own scripts to it too. In my days as an admin, Dm, and builder for both Anchorome and Harvest Moon there were two really good scripters I worked with

I could not have created Harvest Moon without either one, Mermut and RDJparadis. Both are exceptional scripters and people. So I will add many of these scripts to this forum so Other PW and mod builders may use and perhaps refine them (especially my own scripts) For those that dont know scripting the scripts should work in a pw you are making if you do not have a scripter.

I have to first finish a dungeon I promised for Netheril: The Age of magic then I will start putting the scripts here.
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

The next scripts are for Doors, locks, and traps. These scripts were created by Mermut. She really did great with them being they are very efficient and make some sense when it comes to persistent worlds. The first is her bash lock script. Instead of destroying a treasure chest in our world. We made it so you could smash the lock so that you did not have to recreate it via script.

Here is her documentation on the script:

mer_bash_lock

Placement and Usage:
Place in the OnDamaged event of doors or placeables to prevent them from being destroyed when damaged.

Set Up:
Set the resistance of the door to the amount of damage you want cut off the top of every hit the PC does to the object. Keep in mind that non-strength characters may not be able to do any damage if you set the resistance much above 8.
Set the HitPoints of the door up to max (1000) so the PCs doesn't destroy the object in one hit.
Variables:
int iHP: The total amount of damage that needs to be done to the object to 'break the lock'. If it is left at 0 the object cannot be bashed open. This is also useful for objects that are NOT locked to make them just non-destroyable.

Notes:
If the object is not locked, this script will merely make it so the door/placeable can be beat upon, but not destroyed.
If the door is locked, you need to set the iHP variable to allow PCs to bash the lock open.
180 second (3 minutes) after the lock is based open, it will relock.

The instructions should be pretty simple and direct. Now here is the script:

Code: Select all

//::///////////////////////////////////////////////
//:: Name mer_bash_lock
//:://////////////////////////////////////////////
/*
    Place in the OnDamaged event of a placeable
        to allow PCs to 'bash open' the lock without destroying
        said placeable

    Set an integer variable, iHP, on the placeable.
        This value determines how many hp worth of damage
        the PC had to do to the lock to 'break the lock' open
*/
//:://////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: March 29, 2005
//:://////////////////////////////////////////////
void Bash_Lock(object oPlaceable, int iDamageDealt)
{
    effect eHeal = EffectHeal(GetMaxHitPoints(oPlaceable));
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oPlaceable);
    int iHP = GetLocalInt(oPlaceable, "iHP");

    if (!GetLocked(oPlaceable) || GetLockKeyRequired(oPlaceable) || iHP == 0)
        return;

    int iDamage = GetLocalInt(oPlaceable, "iDamage") + iDamageDealt;

    if (IntToFloat(iDamage) < iHP * 0.3) // 0 - 30%
    {
        SpeakString("The lock still looks strong.");
        SetLocalInt(oPlaceable, "iDamage", iDamage);
    }
    else if (IntToFloat(iDamage) < iHP * 0.9) // 31 - 90%
    {
        SpeakString("The lock looks damaged.");
        SetLocalInt(oPlaceable, "iDamage", iDamage);
    }
    else if (iDamage < iHP) // 91 - 99%
    {
        SpeakString("The lock is breaking.");
        SetLocalInt(oPlaceable, "iDamage", iDamage);
    }
    else
    {
        DeleteLocalInt(oPlaceable, "iDamage");
        object oPC = GetLastDamager(oPlaceable);
        AssignCommand(oPC, ClearAllActions(TRUE));
        SpeakString("The lock is broken.");
        SetLocked(oPlaceable, FALSE);
        DelayCommand(180.0, SetLocked(oPlaceable, TRUE));
    }
}

void main()
{
    object oPC = GetLastAttacker();

    int iDamageDealt = GetTotalDamageDealt();
    Bash_Lock(OBJECT_SELF, iDamageDealt);
}
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

The second script of Mermut's is about closing and relocking doors that pcs have opened. It's a need to have script for those persistent worlds that do not have it.

This is her documentation and how toos:

mer_door_clslock

Placement and Usage:
Put in the OnOpen event of doors that start locked. Unless a different delay is specified, the door will close and relock itself in 70.0 seconds.

Set Up:
Set your door locked to whatever DC you desire.
Variables:
float fDelay: Optional variable to change the default relock/reclose time from 70 seconds to whatever you wish.

Notes:
You will almost certainly want to put the mer_bash_lock script in the door's OnDamaged event for anything you put this script on to allow players to bash the lock open.
If the door is a transition door, you need to put mer_door_clslock (or mer_door_onopen) on the other door for it to function properly.
If you put this on a door that doesn't have a lock set orginally, this will still cause it to be locked after the script fires.

And here is the script:

Code: Select all

//:://///////////////////////////////////////////////
//:: Name mer_door_clslock
//:://///////////////////////////////////////////////
/*
    Place in the OnOpen event of a door
    Closes the door and relocks after 70 seconds
        unless a different delay is specified
*/
//:://///////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: August 29, 2007
//:://///////////////////////////////////////////////
void main()
{
    object oDoor = OBJECT_SELF;
    float fDelay = GetLocalFloat(oDoor, "fDelay"); // allow for custom delay
    if (fDelay < 1.0)
        fDelay = 70.0;

    DelayCommand(fDelay, ActionCloseDoor(oDoor));
    DelayCommand(fDelay, SetLocked(oDoor, TRUE));
}
Its a very simple script but one I think everyone will like.
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

Sometimes you need an open door script too for special circumstances. Mermut provided it for us on Harvest Moon.

Her documentation:

mer_door_onopen

Placement and Usage:
Place in the OnOpen event of any door you wish to autoclose. By default the door will reclose in 70 seconds.

Set Up:
No additional setup is required.
Variables:
float fDelay: Optional variable to change the default relock/reclose time from 70 seconds to whatever you wish.

Notes:
If the door is a transition door, you need to put mer_door_onopen (or mer_door_clslock) on the other door for it to function properly.
Top

And this is her script: Also very simple and direct that can be added to if the circumstances on your world are different:

Code: Select all

//:://///////////////////////////////////////////////
//:: Name mer_door_onopen
//:://///////////////////////////////////////////////
/*
    Place in the OnOpen event of a door
    Closes the door after 18 seconds

    Knocks PCs out of stealth mode
*/
//:://///////////////////////////////////////////////
\//:: Created By: Mermut
//:: Created On: September 2, 2002
//:://///////////////////////////////////////////////
void main()
{
    object oPC = GetLastOpenedBy();
    float fDelay = GetLocalFloat(OBJECT_SELF, "fDelay"); // allow for custom delay
    if (fDelay < 1.0)
        fDelay = 70.0;

    if (GetStealthMode(oPC) == STEALTH_MODE_ACTIVATED)
        SetActionMode(oPC, ACTION_MODE_STEALTH, FALSE);

    DelayCommand(fDelay, ActionCloseDoor(OBJECT_SELF));
}
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

We never used this script in Harvest Moon so Mermut made no documentation for it. You place this script on a door where you want the players to speak a specific password to open it. You should be able to use this on placeables or chests too. Like if you have a wizard locked chest that needs a spoken word to open. If not I'm sure a decent scripter can convert the script to be used on placeables. The downside to this script is that it is a heartbeat script. So you may not want to use it liberally.

Code: Select all

//::///////////////////////////////////////////////
//:: Name mer_door_passwrd
//:://////////////////////////////////////////////
/*
    Sets the door to unlock and open when the correct
        password is spoken

    The door should be set key unlock only without a keytag entered
    Set the door so it cannot be bashed open
    Then put this script in the doors heartbeat event

    Set the string variable sPassword on the door to be the password
        or phrase that opens the door
*/
//:://////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: September 27, 2007
//:://////////////////////////////////////////////
void main()
{
    object oDoor = OBJECT_SELF;

    // if the door is currently open, don't do anything
    if (GetIsOpen(oDoor))
        return;

    string sPassword = GetStringLowerCase(GetLocalString(oDoor, "sPassword"));

    if (!GetLocalInt(oDoor, "SetUp"))
    {
        SetListening(oDoor, TRUE);
        SetListenPattern(oDoor, "**", 9001);
        SetLocalInt(oDoor, "SetUp", TRUE);
    }

    int iMatch = GetListenPatternNumber();
    string sSpoken;

    if (iMatch == 9001)
    {
        sSpoken = GetStringLowerCase(GetMatchedSubstring(0));
        // if the spoken text contains the password
        if (FindSubString(sSpoken, sPassword) >= 0)
        {
            SetLocked(oDoor, FALSE);
            DelayCommand(0.1, ActionOpenDoor(oDoor));
        }
    }
}
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

The next script is a really really good script. it gives a pc xp points for disarming a trap but not recovery. Recovery has its own reward (You get the trap). It also places a new trap on the door or placeable after a delay

Here is Mermuts documentation:
mer_dsrm_xp

Placement and Usage:
Put in the OnDisarmed event on the Trap tab of the door or placeable.
The script will give the PC who disarms the trap some xp based on the DC of the disarm.
After 180 seconds the trap will reset itself.

Set Up:
Give the object a unique tag. This is necessary because the script is set to only give the PC xp once per object for disarming (to prevent players from farming the same item for xp simply by letting it reset and disarming it again.)
Variables:
int iLevel: The maximum level a PC can be to get xp from disarming this object. If this is unset, all level PCs can get xp for disarming it.
int iTrapLevel: This determines the 'level' of the trap that will be reset on the object.
0 = minor, 1 = average, 2 = strong, 3 = deadly, 4 = epic, 99 = random
int iTrapType: This determines the 'type' of tradp that will be reset on the object.
0 = spike, 1 = holy, 2 = tangle, 3 = acid, 4 = fire, 5 = electrical, 6 = Gas, 7 = frost, 8 = negative, 9 = sonic, 10 = splash, 99 = random
int iRecoverable: Determines if the PC can retrieve the trap (and get the resulting trap as an inventory item).
0 = not recoverable, 1 = recoverable
int iRandomDelay: Allows you to introduce some randomness into how long it will take for the trap to reset itself.
0 = fixed delay of 180 seconds, 1 = add some randomness to the retrapping delay
float fDelay: and a number of seconds between 0 and fDelay to the retrapping time.

Notes:
If you do not set the trap type and size, the retrap version will a minor spike trap.
The amount of xp awarded for disarming the trap is equal to the DC of the trap.


Here is the script that makes all this work:

Code: Select all

//::///////////////////////////////////////////////
//:: Name mer_dsrm_xp
//:://////////////////////////////////////////////
/*
    Give xp for disarming traps on placeables
    Set object to retrap itself

    Put in the OnDisarm event of a placeable
*/
//:://////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: July 6, 2006
//:://////////////////////////////////////////////
#include "rand_trap_inc"

void main()
{
    object oChest = OBJECT_SELF;
    int iLevel = GetLocalInt(oChest, "iLevel");
    int iTrapLevel = GetLocalInt(oChest, "iTrapLevel");
    int iTrapType = GetLocalInt(oChest, "iTrapType");
    int iRecoverable = GetLocalInt(oChest, "iRecoverable");
    float fDelay = GetLocalFloat(oChest, "fDelay");
    if (fDelay < 360.0)
        fDelay = 360.0;
    int iRandomDelay = GetLocalInt(oChest, "iRandomDelay");
    int iDisarm = GetTrapDisarmDC(oChest);
    int iDetect = GetTrapDetectDC(oChest);
    if (iLevel < 1)
        iLevel = 41;

    // Gives PC xp award if a henchie/familar/etc disarms
    object oPC = GetLastDisarmed();
    if (GetIsPC(GetMaster(oPC)))
    {
        oPC = GetMaster(oPC);
    }

    string sTag = GetTag(oChest) + "t";

    // make sure the PC isn't to high a level to get xp for disarming this trap
    // make sure PC hasn't already gotten xp for disarming this trap
    if (GetLocalInt(oPC, sTag) != 1 && GetHitDice(oPC) < iLevel)
    {
        SetXP(oPC, GetXP(oPC)+GetTrapDisarmDC(oChest));
        SetLocalInt(oPC, sTag, 1);
        object oPal = GetFirstFactionMember(oPC);
        while (GetIsObjectValid(oPal))
        {
            SetLocalInt(oPal, sTag, 1);
            oPal = GetNextFactionMember(oPC);
        }
    }

    if (iRandomDelay)
    {
        fDelay = IntToFloat(Random(FloatToInt(fDelay))) + 180.0;
    }

    // kick PC out of stealth mode
    if (GetStealthMode(oPC) == STEALTH_MODE_ACTIVATED)
        SetActionMode(oPC, ACTION_MODE_STEALTH, FALSE);

    DelayCommand(fDelay, taa_CreateTrapOnObject(iTrapLevel, iTrapType, oChest, iDisarm, iDetect, iRecoverable));
}
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

Along the same lines this script gives pcs experience points for picking locks specifically on doors.

Documentation:

mer_pklock_xp

Placement and Usage:
Put in the OnUnLock event of the locked door or placeable. It gives the person who unlocks the object some xp based on the DC of the lock.

Set Up:
Give the object a unique tag. This is necessary because the script is set to only give the PC xp once per object for unlocking it (to prevent players from farming the same item for xp simply by letting it reset and unlocking it again.)
Variables:
int iLevel: The maximum level a PC can be to get xp from unlocking this object. If this is unset, all level PCs can get xp for disarming it.
int iUnlock: The DC of the lock. If it is unset, the DC of the orginal lock is used.

Notes:
The amount of xp for unlocking is equal to the DC of the lock.

And here is Mermut's script for it:

Code: Select all

//::///////////////////////////////////////////////
//:: FileName mer_pklock_xp
//:://////////////////////////////////////////////
/*
    Give xp for picking locks on placeables
    Set object to relock itself

    Put in the OnUnlocked event of a placeable
*/
//:://////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: July 6, 2006
//:://////////////////////////////////////////////
void main()
{
    object oChest = OBJECT_SELF;
    int iLevel = (GetLocalInt(oChest, "iLevel"));
    if (iLevel < 1)
        iLevel = 41;

    object oPC = GetLastUnlocked();
    string sTag = GetTag(oChest) + "l";

    // Gives PC xp award if a henchie/familar/etc unlocks
    if (GetIsPC(GetMaster(oPC)))
    {
        oPC = GetMaster(oPC);
    }

    // make sure the PC isn't to high a level to get xp for picking this lock
    // make sure PC hasn't already gotten xp for picking this lock
    if (GetLocalInt(oPC, sTag) != 1 && GetHitDice(oPC) < iLevel)
    {
        SetXP(oPC, GetXP(oPC)+GetLockUnlockDC(oChest));
        SetLocalInt(oPC, sTag, 1);
        object oPal = GetFirstFactionMember(oPC);
        while (GetIsObjectValid(oPal))
        {
            SetLocalInt(oPal, sTag, 1);
            oPal = GetNextFactionMember(oPC);
        }
    }

    // kick PC out of stealth mode
    if (GetStealthMode(oPC) == STEALTH_MODE_ACTIVATED)
        SetActionMode(oPC, ACTION_MODE_STEALTH, FALSE);

    // randomize the Disarm DC a bit
    // First check to see if the DC is set on the object
    int iUnlock = GetLocalInt(oChest, "iUnlock");
    if (iUnlock == 0) // if 0, get DC from the object and set it as var
    {
        iUnlock = GetLockUnlockDC(oChest);
        SetLocalInt(oChest, "iUnlock", iUnlock);
    }

    // Rand(3)-1: -1 lower, 0 stays same, 1 raises
    // (iLevel+1)*d4(): raise/lower d4 per 'level' of trap
    int iExtra = (Random(3)-1) * (iLevel+1)*d4();

    // make sure the unlock reduction isn't too big
    if (iExtra < 0 && abs(iExtra) >= (iUnlock/3))
        iExtra = -(iUnlock/3);

    if (iUnlock + iExtra < 22) // make sure the Unlock isn't 'assured'
        iExtra = Random((iUnlock-22)+d4());

    SetLockUnlockDC(oChest, iUnlock + iExtra);

    DelayCommand(180.0, ActionLockObject(oChest));
}
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

The last script of this comprehensive Mermut invented for us is a traptrigger respawning script. It completes the system to give you a well rounded system for your traps, doors and placeables that can be used for treasure chests. It is a traptrigger respawning script:

Here is Her documentation:

mer_trptrig_rspn

Placement and Usage:
Put in the TrapTriggered event on the Trap tab of the door or placeable.
Set object to retrap itself after trap is triggers

Set Up:
Give the object a unique tag. This is necessary because the script is set to only give the PC xp once per object for disarming (to prevent players from farming the same item for xp simply by letting it reset and disarming it again.)
Variables:
int iLevel: The maximum level a PC can be to get xp from disarming this object. If this is unset, all level PCs can get xp for disarming it.
int iTrapLevel: This determines the 'level' of the trap that will be reset on the object.
0 = minor, 1 = average, 2 = strong, 3 = deadly, 4 = epic, 99 = random
int iTrapType: This determines the 'type' of tradp that will be reset on the object.
0 = spike, 1 = holy, 2 = tangle, 3 = acid, 4 = fire, 5 = electrical, 6 = Gas, 7 = frost, 8 = negative, 9 = sonic, 10 = splash, 99 = random
int iRecoverable: Determines if the PC can retrieve the trap (and get the resulting trap as an inventory item).
0 = not recoverable, 1 = recoverable
int iRandomDelay: Allows you to introduce some randomness into how long it will take for the trap to reset itself.
0 = fixed delay of 180 seconds, 1 = add some randomness to the retrapping delay
float fDelay: and a number of seconds between 0 and fDelay to the retrapping time.

Notes:
If you do not set the trap type and size, the retrap version will a minor spike trap.
The amount of xp awarded for disarming the trap is equal to the DC of the trap.
Top

And her script for doing this:

Code: Select all

//::///////////////////////////////////////////////
//:: Name mer_trptrig_rspn
//:://////////////////////////////////////////////
/*
    Set object to retrap itself after trap is triggers

    Put in the TrapTriggered event of a placeable
*/
//:://////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: July 27, 2006
//:://////////////////////////////////////////////
#include "nw_i0_spells"
#include "rand_trap_inc"

void main()
{
    object oPC = GetEnteringObject();
    object oChest = OBJECT_SELF;
    string sTrapScript;

    int iLevel = GetLocalInt(oChest, "iLevel");
    int iTrapLevel = GetLocalInt(oChest, "iTrapLevel");
    int iTrapType = GetLocalInt(oChest, "iTrapType");
    int iRecoverable = GetLocalInt(oChest, "iRecoverable");
    float fDelay = GetLocalFloat(oChest, "fDelay");
    if (fDelay < 360.0)
        fDelay = 360.0;
    int iRandomDelay = GetLocalInt(oChest, "iRandomDelay");
    int iDisarm = GetTrapDisarmDC(oChest);
    int iDetect = GetTrapDetectDC(oChest);
    if (iLevel < 1)
        iLevel = 41;

    // Get the appropriate trap script
    sTrapScript = GetTrapScript(GetTrapBaseType(oChest));

    // Fires the appropriate Trap Script based on value of nTtype
    ExecuteScript(sTrapScript, oChest);

    // Set the trap to reset itself
    if (iRandomDelay)
    {
        fDelay = IntToFloat(Random(FloatToInt(fDelay))) + 180.0;
    }
    DelayCommand(fDelay, taa_CreateTrapOnObject(iTrapLevel, iTrapType, oChest, iDisarm, iDetect, iRecoverable));
}
All the above scripts were created by Mermut for the Persistent world Harvest Moon. She has given me express permission to post them. Like me she loves to contribute to the community. She is a good friend that I have worked with for years on NWN with.
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

User avatar
Winterhawk99
Posts: 1619
Joined: Thu Oct 08, 2009 12:00 am
ctp: Yes
nwnihof: Yes
Location: Pa.
Contact:

Re: Harvest Moon scripts

Post by Winterhawk99 »

Here is the custom include for the mer_dsrm_xp script and mer_trptrig_rspn scripts

Here is the include:

Code: Select all

//::///////////////////////////////////////////////
//:: Name rand_trap_inc
//:://////////////////////////////////////////////
/*
    Functions for random traps
*/
//:://////////////////////////////////////////////
//:: Created By: Mermut
//:: Created On: May 15, 2006
//:://////////////////////////////////////////////

// return the appropriate base item constant for trap
// iLevel: 0 = minor, 1 = average, 2 = strong, 3 = deadly, 4 = epic, 99 = random
// iType: 0 = spike, 1 = holy, 2 = tangle, 3 = acid, 4 = fire,
//        5 = electrical, 6 = Gas, 7 = frost, 8 = negative, 9 = sonic,
//        10 = splash, 99 = random
int GetTrapInt(int iLevel, int iType = 99);

// return the trap script for the trap base item type
//  iTrapBaseType = TRAP_BASE_TYPE_* constant
string GetTrapScript(int iTrapBaseType);

// Creates a Trap on the object specified.
// iLevel: 0 = minor, 1 = average, 2 = strong, 3 = deadly, 4 = epic
// iType: 0 = spike, 1 = holy, 2 = tangle, 3 = acid, 4 = fire,
//        5 = electrical, 6 = Gas, 7 = frost, 8 = negative, 9 = sonic,
//        10 = splash, 99 = random
// oObject: The object that the trap will be created on. Works only on Doors and Placeables.
// iDisarm: Disarm DC
// iDetect: Detect DC
// iRecoverable: Set if the trap can be recovered, defaults to FALSE
// nFaction: The faction of the trap (STANDARD_FACTION_*).
// sOnDisarmScript: The OnDisarm script that will fire when the trap is disarmed.
//                  If "" no script will fire.
// sOnTrapTriggeredScript: The OnTrapTriggered script that will fire when the
//                         trap is triggered.
//                         If "" the default OnTrapTriggered script for the trap
//                         type specified will fire instead (as specified in the
//                         traps.2da).
void taa_CreateTrapOnObject(int iLevel, int iType, object oObject, int iDisarm, int iDetect, int iRecoverable = FALSE, int nFaction=STANDARD_FACTION_HOSTILE, string sOnDisarmScript="", string sOnTrapTriggeredScript="");

int GetTrapInt(int iLevel, int iType)
{
    int iTrap;
    // if level is set to random, pick one before the switch
    if (iLevel == 99 || iLevel > 4)
        iLevel = Random(5);
    // if type is set to random, pick one before the switch
    if (iType == 99 || iType > 10)
        iType = Random(11);
    switch (iType)
    {
        case 0:  // Spike Traps
            if (iLevel > 3) // Spike traps do not have an epic level
                iLevel = 3;
            iTrap = iLevel;
        break;
        case 1: // Holy Traps
            if (iLevel > 3) // holy traps do not have an epic level
                iLevel = 3;
            iTrap = 4 + iLevel;
        break;
        case 2: // Tangle Traps
            if (iLevel > 3) // tangle traps do not have an epic level
                iLevel = 3;
            iTrap = 8 + iLevel;
        break;
        case 3: // Acid Traps
            if (iLevel > 3) // acid traps do not have an epic level
                iLevel = 3;
            iTrap = 12 + iLevel;
        break;
        case 4: // Fire Traps
            if (iLevel < 4) // epic traps are tacked on at the end
                iTrap = 16 + iLevel;
            else
                iTrap = 45;
        break;
        case 5: // Electrical Traps
            if (iLevel < 4) // epic traps are tacked on at the end
                iTrap = 20 + iLevel;
            else
                iTrap = 44;
        break;
        case 6: // Gas Traps
            if (iLevel > 3) // gas traps do not have an epic level
                iLevel = 3;
            iTrap = 24 + iLevel;
        break;
        case 7: // Frost Traps
            if (iLevel < 4) // epic traps are tacked on at the end
                iTrap = 28 + iLevel;
            else
                iTrap = 46;
        break;
        case 8: // Negative Traps
            if (iLevel > 3) // negative traps do not have an epic level
                iLevel = 3;
            iTrap = 32 + iLevel;
        break;
        case 9: // Sonic Traps
            if (iLevel < 4) // epic traps are tacked on at the end
                iTrap = 36 + iLevel;
            else
                iTrap = 47;
        break;
        case 10: // Splash Traps
            if (iLevel > 3) // gas traps do not have an epic level
                iLevel = 3;
            iTrap = 40 + iLevel;
        break;
    }
    return iTrap;
}

string GetTrapScript(int iTrapBaseType)
{
    string sTrapScript;
    switch (iTrapBaseType)
    {
        case TRAP_BASE_TYPE_MINOR_SPIKE:
            sTrapScript = "nw_t1_spikeminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_SPIKE:
            sTrapScript = "nw_t1_spikeavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_SPIKE:
            sTrapScript = "nw_t1_spikestrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_SPIKE:
            sTrapScript = "nw_t1_spikedeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_HOLY:
            sTrapScript = "nw_t1_holyminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_HOLY:
            sTrapScript = "nw_t1_holyavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_HOLY:
            sTrapScript = "nw_t1_holystrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_HOLY:
            sTrapScript = "nw_t1_holydeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_TANGLE:
            sTrapScript = "nw_t1_tangminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_TANGLE:
            sTrapScript = "nw_t1_tangavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_TANGLE:
            sTrapScript = "nw_t1_tangstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_TANGLE:
            sTrapScript = "nw_t1_tangdeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_ACID:
            sTrapScript = "nw_t1_acidminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_ACID:
            sTrapScript = "nw_t1_acidavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_ACID:
            sTrapScript = "nw_t1_acidstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_ACID:
            sTrapScript = "nw_t1_aciddeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_FIRE:
            sTrapScript = "nw_t1_fireminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_FIRE:
            sTrapScript = "nw_t1_fireavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_FIRE:
            sTrapScript = "nw_t1_firestrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_FIRE:
            sTrapScript = "nw_t1_firedeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_ELECTRICAL:
            sTrapScript = "nw_t1_elecminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_ELECTRICAL:
            sTrapScript = "nw_t1_elecavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_ELECTRICAL:
            sTrapScript = "nw_t1_elecstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_ELECTRICAL:
            sTrapScript = "nw_t1_elecdeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_GAS:
            sTrapScript = "nw_t1_gasminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_GAS:
            sTrapScript = "nw_t1_gasavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_GAS:
            sTrapScript = "nw_t1_gasstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_GAS:
            sTrapScript = "nw_t1_gasdeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_FROST:
            sTrapScript = "nw_t1_coldminoc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_FROST:
            sTrapScript = "nw_t1_coldavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_FROST:
            sTrapScript = "nw_t1_coldstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_FROST:
            sTrapScript = "nw_t1_colddeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_NEGATIVE:
            sTrapScript = "nw_t1_negminc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_NEGATIVE:
            sTrapScript = "nw_t1_negavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_NEGATIVE:
            sTrapScript = "nw_t1_negstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_NEGATIVE:
            sTrapScript = "nw_t1_negdeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_SONIC:
            sTrapScript = "nw_t1_soncminc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_SONIC:
            sTrapScript = "nw_t1_soncavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_SONIC:
            sTrapScript = "nw_t1_soncstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_SONIC:
            sTrapScript = "nw_t1_soncdeadc";
        break;
        case TRAP_BASE_TYPE_MINOR_ACID_SPLASH:
            sTrapScript = "nw_t1_splshminc";
        break;
        case TRAP_BASE_TYPE_AVERAGE_ACID_SPLASH:
            sTrapScript = "nw_t1_splshavgc";
        break;
        case TRAP_BASE_TYPE_STRONG_ACID_SPLASH:
            sTrapScript = "nw_t1_splshstrc";
        break;
        case TRAP_BASE_TYPE_DEADLY_ACID_SPLASH:
            sTrapScript = "nw_t1_splshdeadc";
        break;
        case TRAP_BASE_TYPE_EPIC_ELECTRICAL:
            sTrapScript = "x2_t1_elecepicc";
        break;
        case TRAP_BASE_TYPE_EPIC_FIRE:
            sTrapScript = "x2_t1_fireepicc";
        break;
        case TRAP_BASE_TYPE_EPIC_FROST:
            sTrapScript = "x2_t1_coldepicc";
        break;
        case TRAP_BASE_TYPE_EPIC_SONIC:
            sTrapScript = "x2_t1_soncepicc";
        break;
    }
    return sTrapScript;
}

void taa_CreateTrapOnObject(int iLevel, int iType, object oObject, int iDisarm, int iDetect, int iRecoverable = FALSE, int nFaction=STANDARD_FACTION_HOSTILE, string sOnDisarmScript="", string sOnTrapTriggeredScript="")
{
    int iTrap = GetTrapInt(iLevel, iType);
    CreateTrapOnObject(iTrap, oObject, nFaction, sOnDisarmScript, sOnTrapTriggeredScript);
    object oTrap = GetNearestTrapToObject(oObject, FALSE);
    // determine what to add to the Disarm DC
    // Rand(3)-1: -1 lower, 0 stays same, 1 raises
    // (iLevel+1)*d4(): raise/lower d4 per 'level' of trap
    int iExtra = (Random(3)-1) * (iLevel+1)*d4();

    // make sure the disarm reduction/increase isn't too big
    if (iExtra < 0 && abs(iExtra) >= (iDisarm/3))
        iExtra = -(iDisarm/3);
    else if (iExtra >= (iDisarm/3))
        iExtra = (iDisarm/3);
    if (iDisarm + iExtra < 22) // make sure the Disarm isn't 'assured'
        iExtra = Random((iDisarm-22)+d4());

    SetTrapDetectDC(oTrap, iDetect);
    SetTrapDisarmDC(oTrap, iDisarm + iExtra);
    SetTrapRecoverable(oTrap, iRecoverable);
}
That should do it for this set of scripts
CTP team member
http://www.harvestmoonconsortium.com
Chief cook and bottle washer for Harvest Moon

Post Reply