Author Sticky: Post Working Scripts Here
Skadus Posted: Saturday, 06 July 04:28PM
1. Script Name: Weapon Spawn Script for Martial Classes II

2. What it does: Spawns a nonmagic weapon in a container suited for the character opening the chest. If the character has a weapon focus (for example, in longswords), he gets that weapon. Otherwise, he gets a weapon suited to his class.

3. Notes: This is based on a script used in chapter 1, so I don't really deserve that much credit. I found out when I started a custom module that my character spawned with a weaker weapon that he didn't have a weapon focus in, which made him really weak in the dungeon I was play-testing. So I remembered the treasure chest in chapter 1 (mentioned in the Versus Books guide) and plugged in the script used in that chest in my module. Worked great, except I got a Longsword +1, unusable by a level 1 fighter. so I decided to edit the script to simplify it so it would only have nonmagic weapons. Works great now.

Just remember, according to the original, you have to use it in a container.

The only issue i can think of regarding the script is that in changing the tags to reflect nonmagic weapons, i may have made an error or two (i only tested for the longsword, because that's what i needed at the time). i didn't double check all of them because there's so many weapons in the list, and the script editor and weapon editor load slowly enough without me switching back and forth between them.

4. The Script itself

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

//:: Weapon Spawn Script for Martial Classes II

//:: Based on "Weapon Spawn Script for Martial Classes" By Bioware Corp.

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

/*

    Spawns in a specific nonmagical weapon suited for

    that class, or to character's weapon focus.

    If there is no weapon focus, then a generic weapon

    is given according to their class.

    NOTE: Only works on containers

*/

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

//:: Created By:   Andrew, Brent

//:: Created On:   February 2002

//:: Edited By:    Skadus Donovaine

//:: Edited On:    6/5/02

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

#include "NW_O2_CONINCLUDE"



void CreateBastardSword(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswbs001", oTarget, 1);

}

void CreateBattleAxe(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_waxbt001", oTarget, 1);

}

void CreateClub(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblcl001", oTarget, 1);

}

void CreateDagger(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswdg001", oTarget, 1);

}

void CreateDart(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wthdt001", oTarget, Random(40) + 1);

}

void CreateDireMace(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wdbma001", oTarget, 1);

}

void CreateDoubleAxe(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wdbax001", oTarget, 1);

}

void CreateGreatAxe(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_waxgr001", oTarget, 1);

}

void CreateGreatSword(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswgs001", oTarget, 1);

}

void CreateHalberd(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wplhb001", oTarget, 1);

}

void CreateHandAxe(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_waxhn001", oTarget, 1);

}

void CreateHeavyCrossbow(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wbwxh001", oTarget, 1);

}

void CreateHeavyFlail(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblfh001", oTarget, 1);

}

void CreateKama(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wspka001", oTarget, 1);

}

void CreateKatana(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswka001", oTarget, 1);

}

void CreateKukri(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wspku001", oTarget, 1);

}

void CreateLightCrossbow(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wbwxl001", oTarget, 1);

}

void CreateLightFlail(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblfl001", oTarget, 1);

}

void CreateLightHammer(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblhl001", oTarget, 1);

}

void CreateLightMace(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblml001", oTarget, 1);

}

void CreateLongSword(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswls001", oTarget, 1);

}

void CreateLongbow(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wbwln001", oTarget, 1);

}

void CreateMorningstar(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblms001", oTarget, 1);

}

void CreateRapier(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswrp001", oTarget, 1);

}

void CreateScimitar(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswsc001", oTarget, 1);

}

void CreateScythe(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wplsc001", oTarget, 1);

}

void CreateShortsword(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wswss001", oTarget, 1);

}

void CreateShortbow(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wbwsh001", oTarget, 1);

}

void CreateShuriken(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wthsh001", oTarget, Random(40) + 1);

}

void CreateSickle(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wspsc001", oTarget, 1);

}

void CreateSling(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wbwsl001", oTarget, 1);

}

void CreateSpear(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wplss001", oTarget, 1);

}

void CreateStaff(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wdbqs001", oTarget, 1);

}

void CreateThrowingAxe(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wthax001", oTarget, Random(40) + 1);

}

void CreateTwoBladedSword(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wdbsw001", oTarget, 1);

}

void CreateWarhammer(object oTarget, object oAdventurer)

{

          dbCreateItemOnObject("nw_wblhw001", oTarget, 1);

}

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

//:: Prefers

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

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

/*

    Returns true if oAdventurer prefers using

    this weapon.

    CRITERIA: They have Weapon Focus

    nFeatWeaponType: Uses the feat constants

    to differentiate the weapon types

*/

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

//:: Created By: Brent

//:: Created On: March 2002

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

int Prefers(int nFeatWeaponType, object oAdventurer)

{

    if (GetHasFeat(nFeatWeaponType, oAdventurer) == TRUE)

    return TRUE;

    else

    return FALSE;

}

void main()

{

    object oLastOpener = GetLastOpener();

    object oContainer = OBJECT_SELF;

    if (GetLocalInt(OBJECT_SELF, "NW_L_OPENONCE") > 0 || GetIsObjectValid(oLastOpener) == FALSE)

    {

        return; // * abort treasure if no one opened the container

    }

    SetLocalInt(OBJECT_SELF, "NW_L_OPENONCE",1);

    ShoutDisturbed();

    // * CHoose the weapon type to create

    if (Prefers(FEAT_WEAPON_FOCUS_BASTARD_SWORD, oLastOpener) == TRUE)

    {

        CreateBastardSword(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_BATTLE_AXE,oLastOpener))

    {

        CreateBattleAxe(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_CLUB,oLastOpener))

    {

        CreateClub(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_DAGGER,oLastOpener))

    {

        CreateDagger(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_DART,oLastOpener))

    {

        CreateDart(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_DIRE_MACE,oLastOpener))

    {

        CreateDireMace(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_DOUBLE_AXE,oLastOpener))

    {

        CreateDoubleAxe(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_GREAT_AXE,oLastOpener))

    {

        CreateGreatAxe(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_GREAT_SWORD,oLastOpener))

    {

        CreateGreatSword(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_HALBERD,oLastOpener))

    {

        CreateHalberd(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_HAND_AXE,oLastOpener))

    {

        CreateHandAxe(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_HEAVY_CROSSBOW,oLastOpener))

    {

        CreateHeavyCrossbow(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_HEAVY_FLAIL,oLastOpener))

    {

        CreateHeavyFlail(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_KAMA,oLastOpener))

    {

        CreateKama(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_KATANA,oLastOpener))

    {

        CreateKatana(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_KUKRI,oLastOpener))

    {

        CreateKukri(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_LIGHT_CROSSBOW,oLastOpener))

    {

        CreateLightCrossbow(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_LIGHT_FLAIL,oLastOpener))

    {

        CreateLightFlail(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_LIGHT_HAMMER,oLastOpener))

    {

        CreateLightHammer(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_LIGHT_MACE,oLastOpener))

    {

        CreateLightMace(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_LONG_SWORD,oLastOpener))

    {

        CreateLongSword(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_LONGBOW,oLastOpener))

    {

        CreateLongbow(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_MORNING_STAR,oLastOpener))

    {

        CreateMorningstar(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_RAPIER,oLastOpener))

    {

        CreateRapier(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SCIMITAR,oLastOpener))

    {

        CreateScimitar(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SCYTHE,oLastOpener))

    {

        CreateScythe(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SHORT_SWORD,oLastOpener))

    {

        CreateShortsword(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SHORTBOW,oLastOpener))

    {

        CreateShortbow(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SHURIKEN,oLastOpener))

    {

        CreateShuriken(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SICKLE,oLastOpener))

    {

        CreateSickle(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SLING,oLastOpener))

    {

        CreateSling(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_SPEAR,oLastOpener))

    {

        CreateSpear(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_STAFF,oLastOpener))

    {

        CreateStaff(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_THROWING_AXE,oLastOpener))

    {

        CreateThrowingAxe(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_TWO_BLADED_SWORD,oLastOpener))

    {

        CreateTwoBladedSword(oContainer, oLastOpener);

    }

    else if (Prefers(FEAT_WEAPON_FOCUS_WAR_HAMMER,oLastOpener))

    {

        CreateWarhammer(oContainer, oLastOpener);

    }

    else

    {

        // * if get to this point then the PC did not have Weapon Focus

        // * in anything then do additional logic to give an appropriate weapon

        if (GetLevelByClass(CLASS_TYPE_DRUID, oLastOpener) >= 1)

        {

            CreateSpecificDruidWeapon(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_WIZARD, oLastOpener) >= 1)

        {

            CreateSpecificWizardWeapon(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_SORCERER, oLastOpener) >= 1)

        {

            CreateDagger(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_PALADIN, oLastOpener) >= 1 || GetLevelByClass(CLASS_TYPE_FIGHTER, oLastOpener) >= 1 || GetLevelByClass(CLASS_TYPE_RANGER, oLastOpener) >= 1)

        {

            CreateLongSword(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_BARBARIAN, oLastOpener) >= 1 || GetLevelByClass(CLASS_TYPE_DRUID, oLastOpener) >= 1)

        {

            CreateClub(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_MONK, oLastOpener) >= 1)

        {

            CreateSpecificMonkWeapon(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_CLERIC, oLastOpener) >= 1)

        {

            CreateLightMace(oContainer, oLastOpener);

        }

        else

        if (GetLevelByClass(CLASS_TYPE_ROGUE, oLastOpener) >= 1 || GetLevelByClass(CLASS_TYPE_BARD, oLastOpener) >= 1)

        {

            CreateShortsword(oContainer, oLastOpener);

        }

    }

}