Author Topic: Preventing Pickpocketing  (Read 7275 times)

Offline Ryu Hayabusa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • http://
Preventing Pickpocketing
« on: January 09, 2007, 10:27:53 AM »
I have this script assigned to the module's on_acquired slot to prevent pickpocketing:

Code: [Select]
// * This script prevents pickpocketing (and kills pickpocketer)

void main()
{
    object oItem = GetModuleItemAcquired();
    object oByPC = GetModuleItemAcquiredBy();
    object oFromPC = GetModuleItemAcquiredFrom();
    object oPC;
    string sMessage;

    // * If the item is aquired by a PC and is stolen
    if (GetIsPC(oFromPC) && GetStolenFlag(oItem))
    {
        // * Remove the stolen flag and return to the owner
        SetStolenFlag(oItem, FALSE);
        ActionTakeItem(oItem, oByPC);
        ActionGiveItem(oItem, oFromPC);

        // * Give warning to pickpocketer, or if warning was given, kill player
        if (GetLocalInt(oByPC, "CAUGHT_STEALING"))
        {
            FloatingTextStringOnCreature("Pickpocket warning ignored!  Killing Player!", oByPC, FALSE);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oByPC);
            sMessage = GetName(oByPC) + " has been executed for being a moron.";
            // * SetLocalInt(oByPC, "CAUGHT_STEALING", 0);
        }
        else
        {
            FloatingTextStringOnCreature("Pickpocket is not allowed!  Warning given!", oByPC, FALSE);
            sMessage = GetName(oByPC) + " tried to steal from " + GetName(oFromPC) + "!";
            SetLocalInt(oByPC, "CAUGHT_STEALING", 1);
        }

        // * Broadcast message to all
        oPC = GetFirstPC();
        while(GetIsObjectValid(oPC)){
            SendMessageToPC(oPC, sMessage);
            oPC = GetNextPC();
        }
    }
}

While the code does kill the pickpocketing player (after a warning is given), it fails to return the item.  I don't know why...

Thanks.

Offline 420

  • Hero Member
  • *****
  • Posts: 4087
    • View Profile
    • Email
Preventing Pickpocketing
« Reply #1 on: January 09, 2007, 12:30:53 PM »
Code: [Select]
       ActionTakeItem(oItem, oByPC);
        ActionGiveItem(oItem, oFromPC);
Try this, replace the above two lines with this one:

AssignCommand(oByPC, (ActionGiveItem(oItem, oFromPC)));

or possibly:

AssignCommand(oFromPC, (ActionTakeItem(oItem, oByPC)));

The main problem is that you are telling the module object (which is what executes that script)  to take an item, but since the module has no inventory it can't store the item anywhere.

Not sure if that will work though, also make sure to recheck the formatting (I'm typing all this from memory).

The other thing you can try is to copy the item into the PC's inventory then DestroyObject the old item.

I did a script similar to this a long time ago, if you can't get it to work I'll try to find my old anti-pickpocket script and post it.

-420

Offline Ryu Hayabusa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • http://
Preventing Pickpocketing
« Reply #2 on: January 09, 2007, 04:02:09 PM »
Quote
Code: [Select]
       ActionTakeItem(oItem, oByPC);
        ActionGiveItem(oItem, oFromPC);
Try this, replace the above two lines with this one:

AssignCommand(oByPC, (ActionGiveItem(oItem, oFromPC)));

or possibly:

AssignCommand(oFromPC, (ActionTakeItem(oItem, oByPC)));

The main problem is that you are telling the module object (which is what executes that script)  to take an item, but since the module has no inventory it can't store the item anywhere.

Not sure if that will work though, also make sure to recheck the formatting (I'm typing all this from memory).

The other thing you can try is to copy the item into the PC's inventory then DestroyObject the old item.

I did a script similar to this a long time ago, if you can't get it to work I'll try to find my old anti-pickpocket script and post it.

-420
[snapback]33433[/snapback]

Worked like a charm!  Thanks 420!