Author Sticky: Post Working Scripts Here
ShadeRaven Posted: Friday, 19 July 12:46AM
Proposed Addition

Name: Swimming
Author: ShadeRaven (Bret Davenport)
Funtion: I pseudo-swimming system for NWN. Non-animated (yet) but essentially works for what it's worth.

Here is an example script of how it is called. In this case, I called it from a dialogue stream (do you want to swim across this lake? Are you sure? You'll have to take off your equipment while swimming.) It could be called from a trigger or other event handler just as easily.

Here's the calling script (action taken):
NWScript:
#include "sr_swimming"

void main()

{

    object oPC = GetPCSpeaker();

    if (SwimCheck(oPC, 10, 1)) {

        location lSwimWP = GetLocation( GetObjectByTag( "Landing_WP2"));

        AssignCommand(oPC, ActionJumpToLocation( lSwimWP));

    }

}



The real code is found here, though. In the sr_swimming script. It could easily be put in one of the other core includes and used as a call to one of them.

sr_swimming:

NWScript:
// Swimming Code, Version 1.0 (by ShadeRaven)

// DC is passed.  This should be roughly the following:

//      Calm Water -   DC 10

//      Rough Water -  DC 15

//      Stormy Water - DC 20

// nChecks is the # of Checks (aka Distance) that should be made for a successful

//      swim to be returned.

// iCold defaults to FALSE, but if TRUE, Hypothermia damage is a possibility.

// iRough defaults to FALSE, with a 1 (or TRUE) being Normal Rough (d3 damage/round)

//      and a 2 being Rocky Rough (d6 damage/round).

// iDuress isn't used (yet) but will eventually reflect having to swim without preperation.

int SwimCheck(object oPC, int iDC, int nChecks, int iCold=FALSE, int iRough=FALSE, int iDuress=FALSE)

{

    // Character Strips off Equipment

    //   Note: Items should be destroyed if this is done under duress and the

    //         player had to strip equipment or drown.

    //   Alternative:  Give the player the option to remove items by slot and

    //         apply a penalty for each item the character doesn't strip.

    if (!iDuress) {

        AssignCommand(oPC, ActionUnequipItem( GetItemInSlot( INVENTORY_SLOT_CHEST)));

        AssignCommand(oPC, ActionUnequipItem( GetItemInSlot( INVENTORY_SLOT_LEFTHAND)));

        AssignCommand(oPC, ActionUnequipItem( GetItemInSlot( INVENTORY_SLOT_RIGHTHAND)));

        AssignCommand(oPC, ActionUnequipItem( GetItemInSlot( INVENTORY_SLOT_HEAD)));

        AssignCommand(oPC, ActionUnequipItem( GetItemInSlot( INVENTORY_SLOT_BOOTS)));

        AssignCommand(oPC, ActionUnequipItem( GetItemInSlot( INVENTORY_SLOT_CLOAK)));

    } else {

        // Future Code for Swimming under Duress

    }

    // Swimming Skill is Determined.

    //  a) Strength Modifier

    //  b) Barbarian, Druid, Ranger get their level added as skill ranks

    //  c) Bard, Fighter, Monk, Rogue get half their level as skill ranks

    //  d) Cleric, Sorcerer, and Wizard don't have Swim as a class skill so get 0 ranks

    //  e) Dwarves are -2 to Swimming (this is a RP racial bias - not a hardfast rule)

    int iSkill = GetAbilityModifier( ABILITY_STRENGTH, oPC);

    iSkill += GetLevelByClass( CLASS_TYPE_BARBARIAN, oPC);

    iSkill += GetLevelByClass( CLASS_TYPE_BARD, oPC)/2;

    iSkill += GetLevelByClass( CLASS_TYPE_DRUID, oPC);

    iSkill += GetLevelByClass( CLASS_TYPE_FIGHTER, oPC)/2;

    iSkill += GetLevelByClass( CLASS_TYPE_MONK, oPC)/2;

    iSkill += GetLevelByClass( CLASS_TYPE_RANGER, oPC);

    iSkill += GetLevelByClass( CLASS_TYPE_ROGUE, oPC)/2;

    if (GetRacialType(oPC) == RACIAL_TYPE_DWARF)

        iSkill -= 2;

    // Number of Round Drowning and Drowning DC

    int nDrowning = 0;

    int iDrownDC = 10;

    // Start the Checking Process

    int nTries = 0;

    while (nTries < nChecks)

    {

        // Rough Waters?  Take damage every round.

        int iRDam = d3();

        if (iRough==2)

            iRDam = d6();

        if (iRough>0) {

            SendMessageToPC( oPC, "You take rough water damage.");

            effect eDamage = EffectDamage( iRDam, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_PLUS_FIVE);

            ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);

        }

        int iResult = d20() + iSkill - iDC;

        // Success

        if (iResult >= 0) {

            nTries++;

            SendMessageToPC(oPC, "Successful swim of segment " + IntToString(nTries) + ".");

        // Failure

        } else {

            // Drowning

            /* MESSAGE removed because gets spammy

            SendMessageToPC( oPC, "Failed swim on length" + IntToString(nTries+1) +

                    " with a result of " + IntToString(iResult) + " versus DC: "+

                    IntToString(iDC) + " with a skill of " + IntToString(iSkill));

             */

            if (iResult < -4) {

                // The DC goes up by 1.

                iDC++;

                nDrowning++;

                // Hypothermia

                if (iCold) {

                    effect eDamage = EffectDamage(d6(), DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_PLUS_FIVE);

                    ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);

                }

                // Can hold breath for 2x Con Score

                if (nDrowning > GetAbilityScore(oPC, ABILITY_CONSTITUTION)*2) {

                    //Uh oh, time to make Con Checks

                    if ((d20()+GetAbilityModifier( ABILITY_CONSTITUTION, oPC)) < iDrownDC) {

                        // Drowned - R.I.P.

                        int iHPs = GetCurrentHitPoints(oPC);

                        effect eDamage = EffectDamage(iHPs+10, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_PLUS_FIVE);

                        ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);

                        return FALSE;

                    }

                    iDrownDC++;

                }

            }

        }

    }

    // Succeeded.

    return TRUE;

}



In testing, it worked quite well with different settings and DCs. I am going to add in a "menu" for Duress Swimming where a player can choose what he or she removes and have DC adjusted accordingly. Anything removed under duress will be destroy, but death by drowning isn't pleasant either (but for easier campaigns death is better than item loss).

Any addition, improvements, etc., to this, please feel free to email me (bretwd@attbi.com) or repost with improvements.

I have other scripts I am thinking of adding, but I thought this one might be one worth starting with.

_________________
Imitation is the sincerest form of imitation.

For good NWN information, visit Neverwinter Vault

For my Analyses/Guides visit: ShadeRaven's NWN Guides