#include "inc_item_tools"
void main()
    {
    object oItem = GetItemActivated();
    string sTag = GetTag (oItem);
    object oPC = GetItemActivator();
    object oTarget = GetItemActivatedTarget();
    location lLoc = GetItemActivatedTargetLocation();
    location lLoc2;
    int iType = GetBaseItemType(oItem);
    int i,iTemp,iTemp2,iAnim,iPassed,iSkill,iRoll;
    effect eTemp,eTemp2;
    object oTemp;
    string sResRef;
    talent tTalent;
    float fTemp;
            if (sTag == "thievestools"
                  || sTag == "mw_thievestools")
                {
                if (sTag == "mw_thievestools")
                    iTemp = 2;
                else
                    iTemp = 0;
                ClearAllActions();
                if (GetDistanceBetween(oTarget,oPC) >= 1.0)
                    ActionMoveToObject(oTarget);
                ActionDoCommand(ThiefTools(oPC,oTarget,iTemp));
                }
            else if (GetStringLeft(sTag,4) == "misc")
                {
                if (sTag == "misca004")
                    {
                    CreateObject(OBJECT_TYPE_PLACEABLE,"plc_tree",lLoc);
                    }
                else if (sTag == "misca006")
                    {
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSkillIncrease(SKILL_HIDE,5),oPC,HoursToSeconds(1));
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSkillIncrease(SKILL_MOVE_SILENTLY,5),oPC,HoursToSeconds(1));
                    }
                else if (sTag == "misca007")
                    {
                    oTemp = CreateObject(OBJECT_TYPE_CREATURE,"nw_raptor001",lLoc);
                    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectDominated()),oTemp);
                    }
                else if (sTag == "misca009")
                    {
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSkillIncrease(SKILL_HIDE,10),oPC,HoursToSeconds(1));
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSkillIncrease(SKILL_PERSUADE,10),oPC,HoursToSeconds(1));
                    }
                else if (sTag == "misca013")
                    {
                    int iTemp = d100();
                    if (iTemp <= 30) sResRef = "bagoftricks_bat";
                    else if (iTemp <= 75) sResRef = "bagoftricks_rat";
                    else  sResRef = "bagoftricks_badg";
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSummonCreature(sResRef),oPC,HoursToSeconds(1));
                    }
                else if (sTag == "misca014")
                    {
                    if ((GetAppearanceType(oTarget) == APPEARANCE_TYPE_ELEMENTAL_WATER
                     || GetAppearanceType(oTarget) == APPEARANCE_TYPE_ELEMENTAL_WATER_ELDER)
                     && GetRacialType(oTarget) == RACIAL_TYPE_ELEMENTAL)
                        {
                        iTemp = FortitudeSave(oTarget,18);
                        if (!iTemp)
                            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDeath(),oTarget);
                        else if (iTemp == 1)
                            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(d6(5)),oTarget);
                        }
                    }
                else if (sTag == "misca024")
                    {
                    AssignCommand(oPC,PlaySound("as_cv_flute1"));
                    iTemp = d100();
                    if (iTemp <= 80) {sResRef = "nw_ratdire001"; iTemp = d6(3);}
                    else {sResRef = "nw_rat"; iTemp = d6(6);}
                    if (SkillCheck(SKILL_PERFORM,10,oPC,TRUE)) iTemp2 = STANDARD_FACTION_DEFENDER;
                    else iTemp2 = STANDARD_FACTION_HOSTILE;
                    for (i = 1;i<=iTemp;i++)
                        {
                        oTemp = CreateObject(OBJECT_TYPE_CREATURE,sResRef,GetLocation(oPC));
                        ChangeToStandardFaction(oTemp,iTemp2);
                        if (iTemp == STANDARD_FACTION_HOSTILE)
                            AssignCommand(oTemp,ActionAttack(oPC));
                        AssignCommand(oTemp,DelayCommand(RoundsToSeconds(20),DestroyObject(oTemp)));
                        }
                    }
                else if (sTag == "misca029")
                    {
                    AssignCommand(oPC,PlaySound("as_cv_flute2"));
                    if (GetHasSkill(SKILL_PERFORM,oPC))
                        {
                        iTemp = 1;
                        oTemp = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE,lLoc,iTemp);
                        while (GetIsObjectValid(oTemp))
                            {
                            iTemp2 = GetRacialType(oTemp);
                            if (iTemp != RACIAL_TYPE_CONSTRUCT
                             && iTemp != RACIAL_TYPE_ELEMENTAL
                             && iTemp != RACIAL_TYPE_UNDEAD
                             && !GetIsPC(oTemp)
                             && !GetIsInCombat(oTemp))
                                {
                                AssignCommand(oTemp,ClearAllActions());
                                AssignCommand(oTemp,ActionMoveToLocation(lLoc,TRUE));
                                }
                            iTemp +=1;
                            oTemp = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE,lLoc,iTemp);
                            }
                        }
                    else
                        {
                        FloatingTextStringOnCreature("Maybe you should learn how to play.",oPC,FALSE);
                        }
                    }
                else if (sTag == "misca039")
                    {
                    AssignCommand(oPC,PlaySound("as_cv_eulpipe1"));
                    if (!GetHasSkill(SKILL_PERFORM,oPC))
                        {
                        lLoc = GetLocation(oPC);
                        iTemp = d20();
                        }
                    else
                        iTemp = GetSkillRank(SKILL_PERFORM,oPC) + d20();
                        eTemp = EffectDarkness();
                        eTemp = EffectLinkEffects(eTemp,EffectAreaOfEffect(AOE_PER_DARKNESS));
                    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY,eTemp,lLoc,RoundsToSeconds(iTemp));
                    }

                else if (sTag == "misca053")
                    {
                    int iTemp = d100();
                    if (iTemp <= 60) sResRef = "bagoftricks_wolf";
                    else if (iTemp <= 75) sResRef = "bagoftricks_boar";
                    else  sResRef = "bagoftricks_blac";
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSummonCreature(sResRef),oPC,HoursToSeconds(1));
                    }
                else if (sTag == "misca054")
                    {
                    AssignCommand(oPC,PlaySound("as_cv_bell1"));
                    if (GetLocked(oTarget)
                     && !GetLockKeyRequired(oTarget)
                     && !GetPlotFlag(oTarget))
                        SetLocked(oTarget,FALSE);
                    else
                        SendMessageToPC(oPC,"Chime failed to open this door.");
                    }
                else if (sTag == "misca064")
                    {
                    if  (FindEffect(oTarget,EFFECT_TYPE_POISON,OBJECT_INVALID,TRUE))
                        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_HEALING_M),oTarget,1.0);
                    else if  (FindEffect(oTarget,EFFECT_TYPE_DISEASE,OBJECT_INVALID,TRUE))
                        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_HEALING_M),oTarget,1.0);
                    else
                        {
                        ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(d8()+5),oTarget);
                        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_HEALING_M),oTarget,1.0);
                        }
                    }
                else if (sTag == "misca067")
                    {
                    if (!FindEffect(oTarget,EFFECT_TYPE_PETRIFY,OBJECT_INVALID,TRUE))
                        {
                        AssignCommand(oPC,ActionCastSpellAtObject(SPELL_STONESKIN,oTarget,METAMAGIC_ANY,TRUE,13,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
                        }
                    }
                else if (sTag == "misca082")
                    {
                    eTemp = EffectLinkEffects(EffectDarkness(),EffectAreaOfEffect(AOE_PER_DARKNESS));
                    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY,eTemp,lLoc,RoundsToSeconds(5));
                    }
                else if (sTag == "misca084")
                    {
                    CreateItemOnObject("murlyndssoup",oTarget);
                    }
                else if (sTag == "misca091")
                    {
                    AssignCommand(oPC,PlaySound("as_cv_eulpipe2"));
                    if (GetAlignmentGoodEvil(oPC) == ALIGNMENT_NEUTRAL)
                        return;
                    effect eAOE = EffectAreaOfEffect(AOE_MOB_CIRCGOOD);
                    effect eVis = EffectVisualEffect(VFX_DUR_PROTECTION_GOOD_MINOR);
                    effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
                    effect eVis2 = EffectVisualEffect(VFX_IMP_GOOD_HELP);
                    if (GetAlignmentGoodEvil(oPC) == ALIGNMENT_EVIL)
                        {
                        eAOE = EffectAreaOfEffect(AOE_MOB_CIRCEVIL);
                        eVis = EffectVisualEffect(VFX_DUR_PROTECTION_EVIL_MINOR);
                        eDur = EffectVisualEffect(VFX_DUR_CESSATE_NEGATIVE);
                        eVis2 = EffectVisualEffect(VFX_IMP_EVIL_HELP);
                        }
                    effect eLink = EffectLinkEffects(eAOE, eVis);
                    eLink = EffectLinkEffects(eLink, eDur);
                    int nDuration = GetSkillRank(SKILL_PERFORM,oPC);
                    //Make sure duration does no equal 0
                    if (nDuration < 1)
                        nDuration = 1;
                    //Fire cast spell at event for the specified target
                    SignalEvent(oPC, EventSpellCastAt(OBJECT_SELF, SPELL_MAGIC_CIRCLE_AGAINST_EVIL, FALSE));

                    //Create an instance of the AOE Object using the Apply Effect function
                    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oPC);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, TurnsToSeconds(nDuration));
                    }
                else if (sTag == "misca093")
                    {
                    int iTemp = d100();
                    if (iTemp <= 30) sResRef = "bagoftricks_jag";
                    else if (iTemp <= 60) sResRef = "bagoftricks_lion";
                    else if (iTemp <= 90) sResRef = "bagoftricks_brow";
                    else if (iTemp <= 90) sResRef = "bagoftricks_dwol";
                    else sResRef = "bagoftricks_pola";
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSummonCreature(sResRef),oPC,HoursToSeconds(1));
                    }
                else if (sTag == "misca059"
                      || sTag == "miscb022"
                      || sTag == "miscb027"
                      || sTag == "miscb028"
                      || sTag == "miscb032"
                      || sTag == "miscb045"
                      || sTag == "miscb055"
                      || sTag == "miscb066"
                      || sTag == "miscb067"
                      || sTag == "miscb075"
                      || sTag == "miscb098"
                      )
                    {
                    FigurineWonderousPower(oPC,oItem,sTag,lLoc);
                    }
                else if (sTag == "miscb037")
                    {
                    PlaySound("as_cv_pump1");
                    AssignCommand(oPC,HornOfBlasting(lLoc));
                    }
                else if (sTag == "miscb040")
                    {
                    if (!GetHasSkill(SKILL_PERFORM,oPC))
                        {
                        SendMessageToPC(oPC,"You can't hold a tune in a bucket. Well, maybe you can, but you don't have a bucket.");
                        }
                    AssignCommand(oPC,PlaySound("as_cv_eulpipe2"));
                    AssignCommand(oPC,PipesOfPain());
                    }
                else if (sTag == "miscb056")
                    {
                    AssignCommand(oPC,PlaySound("as_cv_belltower1"));
                    oTemp = GetFirstObjectInShape(SHAPE_SPHERE,30.0,lLoc,FALSE);
                    while(GetIsObjectValid(oTemp))
                        {
                        if (!WillSave(oTemp,15,SAVING_THROW_TYPE_MIND_SPELLS))
                            {
                            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectSilence(),oTemp,RoundsToSeconds(10));
                            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_SILENCE),oTemp,3.0);
                            }
                        oTemp = GetNextObjectInShape(SHAPE_SPHERE,30.0,lLoc,FALSE);
                        }
                    }
                else if (sTag == "miscc1039")
                    {
                    AssignCommand(oPC,Miscc039(d4(2)+2,sTag,TRUE));
                    }
                else if (sTag == "miscc2039")
                    {
                    if (GetLevelByClass(CLASS_TYPE_BARD) >= 2
                     || GetLevelByClass(CLASS_TYPE_CLERIC)
                     || GetLevelByClass(CLASS_TYPE_DRUID)
                     || GetLevelByClass(CLASS_TYPE_PALADIN) >= 4
                     || GetLevelByClass(CLASS_TYPE_RANGER) >= 4
                     || GetLevelByClass(CLASS_TYPE_SORCERER)
                     || GetLevelByClass(CLASS_TYPE_WIZARD))
                        iTemp = TRUE;
                    else
                        iTemp = FALSE;
                    AssignCommand(oPC,Miscc039(d4(2)+1,sTag,iTemp));
                    }
                else if (sTag == "miscc3039" || sTag == "miscc4039")
                    {
                    if (GetHasFeat(FEAT_WEAPON_PROFICIENCY_MARTIAL)
                     || GetHasSkill(SKILL_PERFORM))
                        iTemp2 = TRUE;
                    else
                        iTemp2 = FALSE;
                    if (sTag == "miscc3039")
                        iTemp = d4(2);
                    else
                        iTemp = d4()+1;
                    AssignCommand(oPC,Miscc039(iTemp,sTag,iTemp2));
                    }
                }
            }
