#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,oTemp2,oFall,oTrap,oRope,oWP;
    string sResRef,sTemp,sTemp2;
    itemproperty ipItem;
    float fTemp;
    if (sTag == "healersbag")
                {
                iTemp = GetCurrentHitPoints(oTarget);
                iPassed = SkillCheck(SKILL_HEAL,13,oPC,TRUE,TRUE);
                if (iPassed)
                    {
                    if (iTemp < 0 && iTemp > -10)
                        ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(1-iTemp),oTarget);
                    else if (HasEffect(oTarget,EFFECT_TYPE_POISON))
                        FindEffect(oTarget,EFFECT_TYPE_POISON,OBJECT_INVALID,TRUE);
                    else if (HasEffect(oTarget,EFFECT_TYPE_DISEASE))
                        FindEffect(oTarget,EFFECT_TYPE_DISEASE,OBJECT_INVALID,TRUE);
                    else
                        FloatingTextStringOnCreature("No effect.",oTarget);
                    }
                }
            else if (sTag == "misca030")
                {
                oTemp = CreateItemOnObject("arrow001",oPC,99);
                SetPlotFlag(oTemp,TRUE);
                }
            else if (sTag == "misca085" || sTag == "miscb043" || sTag == "miscc099")
                {
                // Create the doors
                oWP = DetermineDestination(FALSE,TRUE);
                sTemp = GetSecretDoorTag();
                sTemp2 = GetSecretDoorTag();
                oTemp = CreateObject(OBJECT_TYPE_PLACEABLE,"port_door",lLoc,FALSE, sTemp);
                oTemp2 = CreateObject(OBJECT_TYPE_PLACEABLE,"port_door",GetLocation(oWP),FALSE,sTemp2);
                SetPlotFlag(oTemp,TRUE);
                SetPlotFlag(oTemp2,TRUE);
                AssignCommand(oTemp,SetFacing(GetFacing(oPC)));
                // Create Transition Waypoints
                SetLocalString(CreateObject(OBJECT_TYPE_WAYPOINT,"transition",GetLocation(oTemp)),"Tag",sTemp);
                SetLocalString(CreateObject(OBJECT_TYPE_WAYPOINT,"transition",GetLocation(oTemp2)),"Tag",sTemp2);
                // Link the doors
                LinkTransitions(oTemp,oTemp2);
                }
            else if (sTag == "miscb002")
                {
                if (GetHasSkill(SKILL_PERFORM,oPC))
                    iRoll = d20() + GetSkillRank(SKILL_PERFORM,oPC);
                if (iRoll >= 15)
                    {
                    i = 1;
                    oTemp = GetNearestObject(OBJECT_TYPE_CREATURE,oPC,i);
                    while (GetIsObjectValid(oTemp))
                        {
                        if (WillSave(oTemp,14,SAVING_THROW_TYPE_MIND_SPELLS,oPC) == 0)
                            SetIsTemporaryFriend(oTarget,oPC,TRUE);
                        else
                            AssignCommand(oTemp,ActionAttack(oPC));
                        oTemp = GetNearestObject(OBJECT_TYPE_CREATURE,oPC,i+=1);
                        }
                    }
                else if (iRoll <= 1)
                    {
                    oTemp = GetNearestObject(OBJECT_TYPE_CREATURE,oPC,i);
                    while (GetIsObjectValid(oTemp))
                        {
                        AssignCommand(oTemp,ActionAttack(oPC));
                        oTemp = GetNearestObject(OBJECT_TYPE_CREATURE,oPC,i+=1);
                        }
                    }
                else
                    {
                    if (GetIsEnemy(oPC,oTemp))
                        AssignCommand(oTemp,ActionAttack(oPC));
                    }
                }
            else if (sTag == "miscb024")
                {
                iTemp = Random(34) +1;
                switch(iTemp)
                    {
                    case 1: {sResRef = "deck_drgred";break;}
                    case 2: {sResRef = "deck_bandit1";break;}
                    case 3: {sResRef = "deck_bandit2";break;}
                    case 4: {sResRef = "deck_bandit3";break;}
                    case 5: {sResRef = "deck_fgiant";break;}
                    case 6: {sResRef = "deck_ettin";break;}
                    case 7: {sResRef = "deck_bugbear";break;}
                    case 8: {sResRef = "deck_goblin";break;}
                    case 9: {sResRef = "deck_dragongold";break;}
                    case 10: {sResRef = "deck_elfmage";break;}
                    case 11: {sResRef = "deck_elfranger";break;}
                    case 12: {sResRef = "deck_cocktrice";break;}
                    case 13: {sResRef = "deck_bandit6";break;}
                    case 14: {sResRef = "deck_ogremage";break;}
                    case 15: {sResRef = "deck_gnoll";break;}
                    case 16: {sResRef = "deck_kobold";break;}
                    case 17: {sResRef = "deck_lich";break;}
                    case 18: {sResRef = "deck_humanmerc1";break;}
                    case 19: {sResRef = "deck_medusa";break;}
                    case 20: {sResRef = "deck_dwarfmerc1";break;}
                    case 21: {sResRef = "deck_frostg";break;}
                    case 22: {sResRef = "deck_troll";break;}
                    case 23: {sResRef = "deck_hobgoblin";break;}
                    case 24: {sResRef = "deck_goblin";break;}
                    case 25: {sResRef = "deck_goliron";break;}
                    case 26: {sResRef = "deck_humanmerc6";break;}
                    case 27: {sResRef = "deck_pixie";break;}
                    case 28: {sResRef = "deck_gypsy";break;}
                    case 29: {sResRef = "deck_hillgiant";break;}
                    case 30: {sResRef = "deck_ogre";break;}
                    case 31: {sResRef = "deck_orc";break;}
                    case 32: {sResRef = "deck_kobold";break;}
                    case 33: {sResRef = "copy";break;}
                    case 34: {sResRef = "copy";break;}
                    }
                iTemp = GetHitDice(oPC) + 3;
                if (sResRef != "copy")
                    {
                    eTemp = EffectSummonCreature(sResRef,VFX_FNF_SUMMON_MONSTER_1);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eTemp,oPC,RoundsToSeconds(iTemp));
                    }
                else
                    {
                    oTemp = CopyObject(oPC,lLoc);
                    ChangeFaction(oTemp,oPC);
                    AssignCommand(oTemp,ActionForceFollowObject(oPC));
                    DelayCommand(RoundsToSeconds(iTemp),DestroyObject(oTemp));
                    }
                }
            else if (sTag == "miscb050")
                {
                if (GetObjectType(oTarget) == OBJECT_TYPE_ITEM
                 || GetIsPC(oTarget))
                    {
                    if (GetIsPC(oTarget))
                        oTarget = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND ,oTarget);
                    if (!GetWeaponRanged(oTarget))
                        {
                        if (!GetWeaponBludgeoning(oTarget))
                            {
                            AddItemProperty(DURATION_TYPE_TEMPORARY,ItemPropertyKeen(),oTarget,TurnsToSeconds(10));
                            AddItemProperty(DURATION_TYPE_TEMPORARY,ItemPropertyVisualEffect(ITEM_VISUAL_SONIC),oTarget,TurnsToSeconds(10));
                            PlaySound("cb_sw_blade1");
                            }
                        else iTemp = TRUE;
                        }
                    else
                        iTemp = TRUE;
                    }
                else
                    iTemp = TRUE;
                if (iTemp)
                    FloatingTextStringOnCreature("Invalid target",oPC,FALSE);
                }
            else if (sTag == "miscb051")
                {
                Fly();
                }
            else if (sTag == "miscb077")
                {
                eTemp = EffectLinkEffects(EffectAreaOfEffect(AOE_MOB_PROTECTION,"****","miscb077","****"),EffectDamageResistance(DAMAGE_TYPE_COLD,100,100));
                eTemp = EffectLinkEffects(EffectVisualEffect(VFX_DUR_AURA_FIRE),eTemp);
                ApplyEffectToObject(DURATION_TYPE_PERMANENT,eTemp,oPC);
                }
            else if (sTag == "miscc006")
                {
                PlaySound("as_cv_drums2");
                oTemp = GetFirstObjectInShape(SHAPE_SPHERE,FeetToMeters(120.0),lLoc);
                while(GetIsObjectValid(oTemp))
                    {
                    if (GetDistanceBetween(oPC,oTemp) > FeetToMeters(20.0))
                        {
                        if (!WillSave(oTemp,16,SAVING_THROW_TYPE_FEAR,oPC))
                            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,EffectFrightened(),oTemp,RoundsToSeconds(GetSkillRank(SKILL_PERFORM,oPC)));
                        }
                    oTemp = GetNextObjectInShape(SHAPE_SPHERE,FeetToMeters(120.0),lLoc);
                    }
                }
            else if (sTag == "misca055")
                {
                oFall = GetNearestObjectByTag("Fall");
                oTrap = GetLocalObject(oFall,"Dest");
                if (GetLocalInt(oTrap,"Safe"))// This point already has a rope.
                    return;
                if (GetDistanceToObject(oFall) <= 5.0)
                    {
                    if (GetIsObjectValid(oTrap))
                        {
                        oRope = CreateObject(OBJECT_TYPE_PLACEABLE,"rdg_rope_used",GetLocation(oFall),TRUE);
                        SetLocalInt(oTrap,"Safe",TRUE);// Used in Pit conversation
                        LinkTransitions(oFall,oTrap); // Mark rope for destruction on dungeon reshuffle.
                        LinkTransitions(oTrap,oRope);
                        }
                    }
                }
            else if (sTag == "miscc074")
                {
                if (TouchAttackRanged(oTarget))
                    {
                    oTemp = CopyObject(oTarget,lLoc);
                    SetLocalInt(oTemp,"MirrorOfOppositionCopy",TRUE);
                    SetLocalObject(oTarget,"MirrorOfOpposition",oTemp);
                    AssignCommand(oTemp,ActionAttack(oTarget));
                    for (i = 0; i <= 17; i++)
                        {
                        SetDroppableFlag(GetItemInSlot(i,oTemp),FALSE);
                        }
                    oTemp2 = GetFirstItemInInventory(oTemp);
                    while(GetIsObjectValid(oTemp2))
                        {
                        SetDroppableFlag(oTemp2,FALSE);
                        oTemp2 = GetNextItemInInventory(oTemp);
                        }
                    TakeGoldFromCreature(GetGold(oTemp),oTemp,TRUE);
                    }
                }
            }
