//Script Name: onunaquireitem
//////////////////////////////////////////
//Created By: Genisys (Guile)
//Created On: 3/05/08 (Update 8/10/08)
/////////////////////////////////////////
/*
This script goes in the OnUnAquireItem
Module Event in the Module Properties

This script accurately nails a player
for pick pocketing another player.
It doesn't fire if they are pick
pocketing anything but a player.

The Tag Standard Bioware Tag-Based
Scripting will still fire reguardless.
*/
////////////////////////////////////////

//Required Include
#include "x2_inc_switches"
void main()
{

//IMPORTANT THIS MUST BE IN YOUR OnUnAcquireItem Module Event Script
     //This is a fix for the Inventory Organizing System!
     object oPC = GetModuleItemLostBy();
     if(GetLocalInt(oPC, "ORGANIZING")==1)
     { return; }

object oItem = GetModuleItemLost();

object oRobbed;
oRobbed = GetModuleItemLostBy();
object oThief;
oThief = GetModuleItemAcquiredBy();
object oLost;
oLost = GetModuleItemLost();
object oFound;
oFound = GetModuleItemAcquired();

string sMsg;
sMsg = "You can't pick player's pockets, it's not permitted!";

 //Let's make sure the thief is a PC, or continue on to the tag based scripting
 if (GetIsPC(oThief))
 {

  //Lets see if they have Pick Pocket Skills
  if(GetSkillRank(SKILL_PICK_POCKET, oThief, TRUE)>0)
  {
   //Lets make sure they took it from a PC and not an NPC or Monster.
   if(GetIsPC(oRobbed))
   {
   //Let's make sure the thief isn't crafting.
   if(oRobbed != oThief)
    {
    //Lets make sure the the thief is the one who disturbed the inventory
    //of the person who lost the item. (This needs to be tested thoroughly)
    // if(GetLastDisturbed()== oThief)
    //Delete the // Below and the //  where } appears below as well to activate.
    // {

    //Give the item back, destroy the one they took, and kill the thief.
        ActionTakeItem(oFound, oThief);
        ActionGiveItem(oFound, oRobbed);
        SendMessageToPC(oThief, sMsg);
        effect eEffect;
        eEffect = EffectDeath();
        eEffect = SupernaturalEffect(eEffect);
        DelayCommand(2.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oThief));
        AssignCommand(oThief, SpeakString("I'm a thief!!", TALKVOLUME_SHOUT));

   //}
    }
   }
  }
 }

//This script destroys all items dropped if not in combat (disarmed)
//or if the item is put into a container in the module.
//Simply place // before Execute to turn off.
ExecuteScript("trashem",OBJECT_SELF);

///////////////////////////////////////////////////////////////////////////


//Your Code Goes here...


///////////////////////////////////////////////////////////////////////////

///////////STANDARD XP2 TAG BASED SCRIPTING CODE///////////////////////////

     //Tag Based Scripting Check
     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_UNACQUIRE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }

     }

//Main Script End
}