#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,eEffect;
    object oTemp;
    string sResRef;
    talent tTalent;
    object oSkin = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
    float fTemp;
    int iHasEffect = FindEffect(oTarget,EFFECT_TYPE_INVALIDEFFECT,oItem,TRUE);
        if (sTag == "food")
                {
                SetLocalInt(oPC,"Food",TRUE);
                if (GetLocalInt(oPC,"Rest"))
                    ActionRest();
                else
                    SendMessageToPC(oPC,"Your hunger is abated. Now you only need to find someplace to safe to rest.");
                }
            else if (sTag == "misca012")
                {
                if (GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_FLESH
                 && GetRacialType(oTarget) == RACIAL_TYPE_CONSTRUCT)
                    GolemBane(GetItemInSlot(INVENTORY_SLOT_CARMOUR,oTarget));
                }
            else if (sTag == "misca022")
                {
                if (GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_CLAY
                 && GetRacialType(oTarget) == RACIAL_TYPE_CONSTRUCT)
                    GolemBane(GetItemInSlot(INVENTORY_SLOT_CARMOUR,oTarget));
                }
            else if (sTag == "misca023")
                {
                oPC = GetFirstFactionMember(oPC);
                while (GetIsObjectValid(oPC))
                    {
                    SetLocalInt(oPC,"Rest",TRUE);
                    oPC = GetNextFactionMember(oPC);
                    }
                }
            else if (sTag == "misca025")
                {
                if (GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_STONE
                 && GetRacialType(oTarget) == RACIAL_TYPE_CONSTRUCT)
                    GolemBane(GetItemInSlot(INVENTORY_SLOT_CARMOUR,oTarget));
                }
            else if (sTag == "misca027")
                {
                if (GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_IRON
                 && GetRacialType(oTarget) == RACIAL_TYPE_CONSTRUCT)
                    GolemBane(GetItemInSlot(INVENTORY_SLOT_CARMOUR,oTarget));
                }
            else if (sTag == "misca031")
                {
                if ((GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_FLESH
                 || GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_CLAY)
                 && GetRacialType(oTarget) == RACIAL_TYPE_CONSTRUCT)
                    GolemBane(GetItemInSlot(INVENTORY_SLOT_CARMOUR,oTarget));
                }
            else if (sTag == "misca034")
                {
                oTarget = GetFirstObjectInShape(SHAPE_SPHERE,5.0,lLoc,TRUE,OBJECT_TYPE_ALL);
                while(GetIsObjectValid(oTarget))
                    {
                    iTemp = GetReflexAdjustedDamage(d6(5),oTarget,16,SAVING_THROW_TYPE_SONIC);
                    if (iTemp > 0)
                        {
                        ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(iTemp,DAMAGE_TYPE_SONIC),oTarget);
                        if (!FortitudeSave(oTarget,16,SAVING_THROW_TYPE_SONIC))
                            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDeaf(),oTarget);
                        }
                    oTarget = GetNextObjectInShape(SHAPE_SPHERE,5.0,lLoc,TRUE,OBJECT_TYPE_ALL);
                    }
                }
            else if (sTag == "misca050")
                {
                if ((GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_FLESH
                 || GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_CLAY
                 || GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_STONE
                 || GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_IRON
                 || GetAppearanceType(oTarget) == APPEARANCE_TYPE_GOLEM_STONE)
                 && GetRacialType(oTarget) == RACIAL_TYPE_CONSTRUCT)
                    GolemBane(GetItemInSlot(INVENTORY_SLOT_CARMOUR,oTarget));
                }
            else if (sTag == "miscb004")
                {
                eTemp = EffectVisualEffect(VFX_IMP_RESTORATION_GREATER);
                ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eTemp,lLoc,3.0);
                eTemp2 = EffectVisualEffect(VFX_IMP_PULSE_HOLY);
                eTemp2 = EffectLinkEffects(eTemp2,EffectAttackIncrease(2));
                eTemp2 = EffectLinkEffects(eTemp2,EffectSkillIncrease(SKILL_ALL_SKILLS,2));
                eTemp2 = EffectLinkEffects(eTemp2,EffectSavingThrowIncrease(SAVING_THROW_ALL,2));
                oTemp = GetFirstFactionMember(oPC);
                while (GetIsObjectValid(oTemp))
                    {
                    if(GetDistanceBetween(oPC,oTemp) <= FeetToMeters(30.0))
                        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eTemp2,oTemp,HoursToSeconds(1));
                    oTemp = GetNextFactionMember(oPC);
                    }
                }
            else if (sTag == "miscb019")
                {
                CreateItemOnObject("murlyndssoup",oTarget);
                }
            else if (sTag == "miscb033")
                {
                oTemp = GetFirstFactionMember(oPC);
                while (GetIsObjectValid(oTemp))
                    {
                    AssignCommand(oTemp,JumpToLocation(lLoc));
                    oTemp = GetNextFactionMember(oPC);
                    }
                }
            // Ioun Stones
            else if (sTag == "misca063")
                {
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectACIncrease(1,AC_DEFLECTION_BONUS),oPC));
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectVisualEffect(VFX_DUR_IOUNSTONE_RED),oPC));
                }
            else if (sTag == "misca079"
                  || sTag == "miscb038"
                  || sTag == "miscb047")
                {
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectVisualEffect(VFX_DUR_IOUNSTONE),oPC));
                SetLocalInt(oSkin,"IounStones",TRUE);
                SetLocalInt(oSkin,sTag,1);
                }
            else if (sTag == "miscb007")
                {
                if (!GetHasFeat(FEAT_ALERTNESS,oPC))
                    {
                    AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectSkillIncrease(SKILL_LISTEN,2),EffectSkillIncrease(SKILL_SPOT,2)),oPC));
                    AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectVisualEffect(VFX_DUR_IOUNSTONE_BLUE),oPC));
                    }
                else
                    SendMessageToPC(oPC,"This item will not work for you.");
                }
            else if (sTag == "miscb008")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectAbilityIncrease(ABILITY_DEXTERITY,2),EffectVisualEffect(VFX_DUR_IOUNSTONE_RED)),oPC));
            else if (sTag == "miscb009")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectAbilityIncrease(ABILITY_WISDOM,2),EffectVisualEffect(VFX_DUR_IOUNSTONE_BLUE)),oPC));
            else if (sTag == "miscb010")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectAbilityIncrease(ABILITY_STRENGTH,2),EffectVisualEffect(VFX_DUR_IOUNSTONE_BLUE)),oPC));
            else if (sTag == "miscb011")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectAbilityIncrease(ABILITY_CONSTITUTION,2),EffectVisualEffect(VFX_DUR_IOUNSTONE_RED)),oPC));
            else if (sTag == "miscb012")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectAbilityIncrease(ABILITY_CHARISMA,2),EffectVisualEffect(VFX_DUR_IOUNSTONE_GREEN)),oPC));
            else if (sTag == "miscb013")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectAbilityIncrease(ABILITY_INTELLIGENCE,2),EffectVisualEffect(VFX_DUR_IOUNSTONE_BLUE)),oPC));
            else if (sTag == "miscb072")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectLinkEffects(EffectLinkEffects(EffectAttackIncrease(1,ATTACK_BONUS_MISC),EffectSavingThrowIncrease(SAVING_THROW_ALL,1)),EffectSkillIncrease(SKILL_ALL_SKILLS,1)),EffectVisualEffect(VFX_DUR_IOUNSTONE_GREEN)),oPC));
            else if (sTag == "miscb074")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectRegenerate(1,60.0),EffectVisualEffect(VFX_DUR_IOUNSTONE_YELLOW)),oPC));
            else if (sTag == "miscb073")
                {
                ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(eTemp = EffectSpellLevelAbsorption(4,20),EffectVisualEffect(VFX_DUR_IOUNSTONE_BLUE)),oPC);
                CreateItemOnObject("misca001",oPC);
                }
            else if (sTag == "miscc028")
                {
                ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectSpellLevelAbsorption(8,50),EffectVisualEffect(VFX_DUR_IOUNSTONE_GREEN)),oPC);
                CreateItemOnObject("misca001",oPC);
                }
    }
