DMH-Online

Dungeon Masters Helper · Est. 2005

Items Scripts

NWN Script: weapon_upgrade.htm

Author: Taroticum
Author Website: n/a
Script Name: Weapon Upgrade
Description: With this script in the OnOpen of an object such as a chest. When the PC opens this object, *if* the PC is wielding a normal non magical weapon this script will spawn in the object they open a +1 version of that weapon.
Instructions on Use: Simply pace the script in the OnOpen of a container.

Script 1 (OnOpen):

// Spawn an Upgrade of the standard weapon that PC is wielding to a +1 version
// Put this script in the OnOpen of the object that the PC will open to upgrade
// Written by Taroticum - 07/13/2002 - zombie@ev1.net
void main()
{
object oPC = GetLastOpenedBy();     // Get the PC that opened the chest
object oPrimary = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);     // Get what weapon the PC is wielding
string sWeapon = GetTag(oPrimary);    // Get the Tag of the PC's weapon
string sCheck = GetStringRight(sWeapon, 1);     // Get the rightmost digit of the Tag
if (sCheck == "1")     // Get if the rightmost digit of the Tag is 1 then its a normal weapon so do the upgrade, if not don't spawn anything
    {
    string s1 = GetStringLeft(sWeapon, 6);     // Get 1st 6 characters of the Tag
    string s2 = "M";                           // This is in all weapons tags that are magical such as the +1 weapon we are creating
    string s3 = GetSubString(sWeapon, 6, 4);   // Get the 7th - 10th digits of the Tag
    string s4 = "2";                           // This is the universally used last digit of the Tag that designates a +1 weapon
    string sNewWeapon = (s1 + s2 + s3 + s4);   // Put all of the above 4 strings together into the new Tag for the +1 weapon
    // Example: Bastard Sword Tag = NW_WSWBS001 so if PC weilding this weapon then when they open the chest
    // the above code would get the first 6  NW_WSW then add M then add the 7th-10th BS00 then adds a 2
    // to make the new Tag NW_WSWMBS002 which is the Tag for a Bastard Sword +1
    CreateItemOnObject(sNewWeapon, OBJECT_SELF, 1);  // Puts the new +1 weapon into the chest
    // Next 2 lines are optional - they prevent the PC from exploiting the use of the chest easily
    // Or you can implement any code you want to control abuse of this
    ActionTakeItem(oPrimary, oPC);     // Take the weapon the PC was weilding
    DestroyObject(oPrimary, 0.0);      // Instantly destroy the weapon just taken
    }
}
⌂ All Scripts ← Previous 👁 Category List

All Items Scripts

📄 aquire_time 📄 bead_of_force 📄 book_of_inf_spells 📄 clear_inventory 📄 clear_inventory_002 📄 clear_inventory_003 📄 clear_inventory_004 📄 cursed_items 📄 cursed_items_002 📄 cursed_potion 📄 give_xp 📄 glow_when_mob 📄 healing_belt 📄 helm 📄 hurled_weapons 📄 item_weight 📄 key_rental 📄 lore_items 📄 npc_owners 📄 random_magic 📄 retrieve_ammo 📄 scimitar_of_dancing 📄 scroll_creation 📄 spawn_item 📄 spawn_item_002 📄 spawn_item_004 📄 stone_of_recall 📄 stone_of_recall_002 📄 summon_creature 📄 teleport_item 📄 torch 📄 weapon_upgrade