DMH-Online

Dungeon Masters Helper · Est. 2005

Items Scripts

NWN Script: clear_inventory.htm

Author Sticky: Post Working Scripts Here
Astaroth76 Posted: Sunday, 23 June 04:32AM
As per a forum user's request, here is a script that clears a PCs inventory. Careful with it, though. PCs might not be happy with their entire inventory being wiped out.

NWScript:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Created By: Astaroth
* Created On: 6/22/2002
* Clears a PC's inventory when he/she first enters the trigger.
* Only runs once, when CLEAR_INV_SCENE variable equals 0.
* After running, CLEAR_INV_SCENE is set to 1 so PC's
* inventory isn't cleared again should he/she walk back into
* the trigger for whatever reason.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void main()
{
    object oEnteringPC;
    object oInvItem;
    // Get the object that last entered this area
    oEnteringPC = GetEnteringObject();
    // Make sure the object is a PC
    if (GetIsPC(oEnteringPC))
    {
        // Only clear inventory if we haven't already done it before
        if (GetLocalInt(oEnteringPC, "CLEAR_INV_SCENE1") == 0)
        {
            oInvItem = GetFirstItemInInventory(oEnteringPC);
            while (oInvItem != OBJECT_INVALID)
            {
                //ActionTakeItem(oInvItem, oEnteringPC);
                DestroyObject(oInvItem);
                oInvItem = GetNextItemInInventory(oEnteringPC);
            }
            // Since GetNextItemInInvetory() seems to not return equipped items,
            // we need to manually remove them one by one.
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_ARMS, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_ARROWS, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BELT, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BOLTS, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BOOTS, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_BULLETS, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CLOAK, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_L, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_CWEAPON_R, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_HEAD, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_LEFTRING, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_NECK, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oEnteringPC))  )
                DestroyObject(oInvItem);
            if ( OBJECT_INVALID != (oInvItem = GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oEnteringPC))  )
                DestroyObject(oInvItem);
            // Make sure this script doesn't run anymore for the current PC
            SetLocalInt(oEnteringPC, "CLEAR_INV_SCENE1", 1);
        }
    }
}



Now could someone from Bioware explain to me why NWN crashes when the above code is attached to an Area's "OnEnter" event? I find it hard to believe that any of the above functions call data that hasn't been initialized by the time an Area's "OnEnter" even is fired.
 

 

⌂ All Scripts ← PreviousNext → 👁 Category List

All Items Scripts

📄 aquire_time 📄 bead_of_force 📄 book_of_inf_spells 📄 clear_inventory 📄 clear_inventory_002 📄 clear_inventory_003 📄 clear_inventory_004 📄 cursed_items 📄 cursed_items_002 📄 cursed_potion 📄 give_xp 📄 glow_when_mob 📄 healing_belt 📄 helm 📄 hurled_weapons 📄 item_weight 📄 key_rental 📄 lore_items 📄 npc_owners 📄 random_magic 📄 retrieve_ammo 📄 scimitar_of_dancing 📄 scroll_creation 📄 spawn_item 📄 spawn_item_002 📄 spawn_item_004 📄 stone_of_recall 📄 stone_of_recall_002 📄 summon_creature 📄 teleport_item 📄 torch 📄 weapon_upgrade