// This will replace oItem with a new item.
object ReplaceItem(object oOwner, object oItem, string sNewItemResRef);

void main()
    {
    int i;
    object oItem = GetModuleItemAcquired();
    object oOwner = GetModuleItemAcquiredBy();
    object oFrom = GetModuleItemAcquiredFrom();
    object oPC;
    int iStack = GetModuleItemAcquiredStackSize();
    string sTag = GetTag(oItem);
    string sName = GetName(oItem);
    string sResRef = GetResRef(oItem);
    object oHench,oTemp;
    if (GetIsPC(oOwner))
        {
        // Notify party of aquiring.
        if (!GetLocalInt(GetArea(oOwner),"Town") && !GetIsPC(oFrom))
            {
            oPC = GetFirstFactionMember(oOwner);
            while(GetIsObjectValid(oPC))
                {
                if (oPC != oOwner)
                    {
                    if (!GetIsObjectValid(oItem)) // An object was aquired but is no longer valid assume gold since I havent destroyed any objects.
                        SendMessageToPC(oPC, GetName(oOwner) + " has acquired " +IntToString(iStack) + " Gold.");
                    else if (!GetIdentified(oItem))
                        SendMessageToPC(oPC, GetName(oOwner) + " has acquired a magic item.");
                    else if (iStack > 1)
                        SendMessageToPC(oPC, GetName(oOwner) + " has acquired " +IntToString(iStack) + " " + sName);
                    else
                        SendMessageToPC(oPC, GetName(oOwner) + " has acquired a " + sName);
                    }
                oPC = GetNextFactionMember(oOwner);
                }
            }
        // Handle aquire effects.
        if (sTag == "weeksrations")
            {
            DestroyObject(oItem);
            for (i = 1; i<= 7; i++)
                {
                oItem = CreateItemOnObject("food",oOwner);
                }
            }
        else if (sTag == "10sunrods")
            {
            DestroyObject(oItem);
            for (i = 1; i<= 10; i++)
                {
                CreateItemOnObject("sunrod",oOwner);
                }
            }
        else if (sTag == "10torches")
            {
            DestroyObject(oItem);
            for (i = 1; i<= 10; i++)
                {
                oItem = CreateItemOnObject("it_torch002",oOwner);
                }
            }
        else if (sTag == "misca059"
              || sTag == "miscb022"
              || sTag == "miscb027"
              || sTag == "miscb028"
              || sTag == "miscb032"
              || sTag == "miscb045"
              || sTag == "miscb055"
              || sTag == "miscb066"
              || sTag == "miscb067"
              || sTag == "miscb075"
              || sTag == "miscb098"
              )
            {
            oHench = GetAssociate(ASSOCIATE_TYPE_HENCHMAN ,oOwner,i=1);
            while (GetIsObjectValid(oHench))
                {
                if (GetTag(oHench) == sTag)
                    {
                    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_UNSUMMON),GetLocation(oHench),5.0);
                    RemoveHenchman(oOwner,oHench);
                    SetImmortal(oHench,FALSE);
                    SetPlotFlag(oHench,FALSE);
                    DelayCommand(3.0,DestroyObject(oHench));
                    }
                oHench = GetAssociate(ASSOCIATE_TYPE_HENCHMAN ,oOwner,i+=1);
                }
            }
        //LuckStone
        else if(sTag == "miscb031")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSavingThrowIncrease(SAVING_THROW_ALL,1)),oOwner));
        // Crystal Balls
        else if (sTag == "miscc041")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectLinkEffects(EffectSkillIncrease(SKILL_APPRAISE,10),EffectSkillIncrease(SKILL_PERSUADE,10))),oOwner));
        else if (sTag == "miscc038")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectLinkEffects(EffectLinkEffects(EffectSkillIncrease(SKILL_APPRAISE,5),EffectSkillIncrease(SKILL_PERSUADE,5)),EffectSeeInvisible())),oOwner));
        else if (sTag == "miscc032")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectLinkEffects(EffectSkillIncrease(SKILL_APPRAISE,5),EffectSkillIncrease(SKILL_PERSUADE,5))),oOwner));
        else if (sTag == "miscc057")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectLinkEffects(EffectSkillIncrease(SKILL_APPRAISE,15),EffectSkillIncrease(SKILL_PERSUADE,15))),oOwner));
        else if (sTag == "miscc063")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectLinkEffects(EffectLinkEffects(EffectSkillIncrease(SKILL_APPRAISE,5),EffectSkillIncrease(SKILL_PERSUADE,5)),EffectTrueSeeing())),oOwner));
        // End Crystal Balls
        else if (sTag == "miscc099")
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectLinkEffects(EffectSkillIncrease(SKILL_APPRAISE,15),EffectSkillIncrease(SKILL_PERSUADE,15))),oOwner));
        // Dwarven Thrower
        else if (sTag == "whammer601")
            {
            if (GetRacialType(oOwner) == RACIAL_TYPE_DWARF)
                ReplaceItem(oOwner,oItem,"whammer602");
            }
        else if (sTag == "whammer602")
            {
            if (GetRacialType(oOwner) != RACIAL_TYPE_DWARF)
                ReplaceItem(oOwner,oItem,"whammer601");
            }
        // End Dwarven Thrower
        // Belt of Dwarven Kind
        else if (sTag == "miscb046")
            {
            if (GetRacialType(oOwner) == RACIAL_TYPE_DWARF)
                ReplaceItem(oOwner,oItem,"miscb046b");
            }
        else if (sTag == "miscb046b")
            {
            if (GetRacialType(oOwner) != RACIAL_TYPE_DWARF)
                ReplaceItem(oOwner,oItem,"miscb046");
            }
        // End Belt of Dwarven Kind
        // Monks Belt
        else if (sTag == "miscb016")
            {
            if (GetLevelByClass(CLASS_TYPE_MONK,oOwner))
                ReplaceItem(oOwner,oItem,"miscb016b");
            }
        else if (sTag == "miscb016b")
            {
            if (!GetLevelByClass(CLASS_TYPE_MONK,oOwner))
                ReplaceItem(oOwner,oItem,"miscb016");
            }
        // Monks Belt
        else if (sTag == "ssword602")
            {
            if (GetLocalInt(oItem,"iUses") < 1
             && GetObjectType(oFrom) == OBJECT_TYPE_STORE)
                {
                SetLocalInt(oItem,"iUses",Random(6));
                }
            }
        else if (sTag == "miscb021")
            {
            if (!GetLevelByClass(CLASS_TYPE_BARD,oOwner)
             && !GetLevelByClass(CLASS_TYPE_SORCERER,oOwner)
             && !GetLevelByClass(CLASS_TYPE_WIZARD,oOwner))
                {
                if (!GetIsSkillSuccessful(oOwner,SKILL_USE_MAGIC_DEVICE,20))
                    AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(d6(5),DAMAGE_TYPE_NEGATIVE),oOwner));
                }
            }
        }
    }

object ReplaceItem(object oOwner, object oItem, string sNewItemResRef)
    {
    object oTemp = CreateItemOnObject(sNewItemResRef,oOwner);
    SetIdentified(oTemp,GetIdentified(oItem));
    DestroyObject(oItem);
    return oTemp;
    }
