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

    }

}