Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

New Premium Module: Tyrants of the Moonsea! Read More
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Destroy Inventory along with Creature

IronActualIronActual Member Posts: 24
edited May 2018 in Builders - Scripting
What's the best way to clear a creature's inventory along with the following script?
object oObject = GetFirstObjectInArea(oTarget); while (oObject != OBJECT_INVALID) { if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE) DestroyObject(oObject); oObject = GetNextObjectInArea(oTarget); }
I've tried a few different things, but keep getting the too many instructions error.

Post edited by IronActual on

Comments

  • ProlericProleric Member Posts: 557
    For each creature, GetFirstItemInInventory. While item is valid, delete it with DestroyObject, GetNextItemInInventory. Then DestroyObject on the Creature as before.

    MermutIronActual
  • IronActualIronActual Member Posts: 24
    Tried doing this, but still getting the error too many instructions.

    object oObject = GetFirstObjectInArea(oTarget); while (oObject != OBJECT_INVALID) { if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE) { object oGear = GetFirstItemInInventory(oObject); while (oGear != OBJECT_INVALID) { DestroyObject(oGear); oGear = GetNextItemInInventory(oObject); } DestroyObject(oObject); oObject = GetNextObjectInArea(oTarget); } }

  • OldFriendlyFireOldFriendlyFire Member Posts: 4
    edited May 2018
    I've changed your code slightly:

    Defined object oArea at the start of the script is such a way as to be able to assign the script to a placeable OnClick event to make testing easy.

    Moved the declaration of object oGear outside of the while loop as it is generally better coding practice to to not repeatedly re-declare an object as you loop.

    Moved your line oObject = GetNextObjectInArea(oArea); outside of the conditional (this was causing your tmi error).

    Re-structured the code for readability (to each their own, or perhaps your formatting was lost in the posting process).

    void main(){ object oArea = GetArea(OBJECT_SELF); object oObject = GetFirstObjectInArea(oArea); object oGear; while (oObject != OBJECT_INVALID) { if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE){ oGear = GetFirstItemInInventory(oObject); while (oGear != OBJECT_INVALID){ DestroyObject(oGear); oGear = GetNextItemInInventory(oObject); } DestroyObject(oObject); } oObject = GetNextObjectInArea(oArea); } }

    This will delete all objects in creature inventories in an area (including PCs and DMs etc). I assume you already have that covered. HTHs.

    IronActual
  • IronActualIronActual Member Posts: 24
    Thanks for these scripting tips! Good info to know!

  • ShadowMShadowM Member Posts: 504
    You forgot equipped items and you do not have to worry about DM they cannot be killed by scripts. You also did not mention if you want to destroy plot items/cursed, plot creatures. This custom function will destroy all equipment on creatures and kill the creatures, excluding plot item/no drops. It goes off the tag of the area.

    void DestroyAllEquipment(object oTarget) { int nSlot; object oGear; int iO_Type =GetObjectType(oTarget); if(iO_Type==OBJECT_TYPE_CREATURE) { for (nSlot = 0; nSlot <= NUM_INVENTORY_SLOTS; nSlot++) { // if(nSlot == INVENTORY_SLOT_CHEST)nSlot++; if (nSlot != INVENTORY_SLOT_CARMOUR && nSlot != INVENTORY_SLOT_CWEAPON_B && nSlot != INVENTORY_SLOT_CWEAPON_L && nSlot != INVENTORY_SLOT_CWEAPON_R) { oGear = GetItemInSlot(nSlot, oTarget); if (GetIsObjectValid(oGear) && !GetPlotFlag(oGear) && !GetItemCursedFlag(oGear)) { DestroyObject(oGear); } } } } // Removing Target's inventory. oGear = GetFirstItemInInventory(oTarget); while (GetIsObjectValid(oGear)) { if(!GetPlotFlag(oGear) && !GetItemCursedFlag(oGear)) { DestroyObject(oGear); oGear = GetNextItemInInventory(oTarget); } if(GetPlotFlag(oGear) || GetItemCursedFlag(oGear)) { oGear = GetNextItemInInventory(oTarget); } } } void DestroyAllCreaturesInArea(string sArea) { object oTargetA = GetObjectByTag(sArea); object oObject = GetFirstObjectInArea(oTargetA); while(GetIsObjectValid(oObject)) { int oO_Type =GetObjectType(oObject); int iPC= GetIsPC(oObject); if(oO_Type ==OBJECT_TYPE_CREATURE && !iPC) { AssignCommand(oObject,DestroyAllEquipment(oObject)); AssignCommand(oObject,SetIsDestroyable(TRUE,FALSE,FALSE)); DestroyObject(oObject); } oObject = GetNextObjectInArea(oTargetA); } } void main() { DestroyAllCreaturesInArea("Start"); }</code>

  • IronActualIronActual Member Posts: 24
    edited May 2018
    I'm doing something wrong, I'm still getting the too many instructions error.

    Here's the original script, maybe seeing all of it will help solve the problem.

    Creatures won't have plot items, or cursed items and I don't need to worry about creature items.

    The only items the creatures will have on them, that need to be destroyed along with the creature itself, are melee weapons, ranged weapons, shields and chest armor.

    In addition to destroying the creatures (and hopefully their items with some help), I'm also destroying any items left on the ground and also traps (triggers) that I spawn from another script.
    void main() { object oTarget = GetArea(OBJECT_SELF); object oObject = GetFirstObjectInArea(oTarget); while (oObject != OBJECT_INVALID) { if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE) DestroyObject(oObject); oObject = GetNextObjectInArea(oTarget); } object oTrap = GetFirstObjectInArea(oTarget); while (oTrap != OBJECT_INVALID) { if (GetObjectType(oTrap) == OBJECT_TYPE_TRIGGER) DestroyObject(oTrap); oTrap = GetNextObjectInArea(oTarget); } object oItem = GetFirstObjectInArea(oTarget); while (oItem != OBJECT_INVALID) { if (GetObjectType(oItem) == OBJECT_TYPE_ITEM) DestroyObject(oItem); oItem = GetNextObjectInArea(oTarget); } }

  • ShadowMShadowM Member Posts: 504
    void DestroyAllEquipment(object oTarget) { int nSlot; object oGear; int iO_Type =GetObjectType(oTarget); if(iO_Type==OBJECT_TYPE_CREATURE) { for (nSlot = 0; nSlot <= NUM_INVENTORY_SLOTS; nSlot++) { // if(nSlot == INVENTORY_SLOT_CHEST)nSlot++; if (nSlot != INVENTORY_SLOT_CARMOUR && nSlot != INVENTORY_SLOT_CWEAPON_B && nSlot != INVENTORY_SLOT_CWEAPON_L && nSlot != INVENTORY_SLOT_CWEAPON_R) { oGear = GetItemInSlot(nSlot, oTarget); if (GetIsObjectValid(oGear) && !GetPlotFlag(oGear) && !GetItemCursedFlag(oGear)) { DestroyObject(oGear); } } } } // Removing Target's inventory. oGear = GetFirstItemInInventory(oTarget); while (GetIsObjectValid(oGear)) { if(!GetPlotFlag(oGear) && !GetItemCursedFlag(oGear)) { DestroyObject(oGear); oGear = GetNextItemInInventory(oTarget); } if(GetPlotFlag(oGear) || GetItemCursedFlag(oGear)) { oGear = GetNextItemInInventory(oTarget); } } } //Destroy all object type and equipment on target and if DestroyTrap = 1 then destroy the trap on object void DestroyAllObjectsTypesInArea(string sArea, int ObjectType, int DestroyTrap) { object oTargetA = GetObjectByTag(sArea); object oObject = GetFirstObjectInArea(oTargetA); while(GetIsObjectValid(oObject)) { int oO_Type =GetObjectType(oObject); int iPC= GetIsPC(oObject); int iTrapD; int iTrapped =GetIsTrapped(oObject); if(DestroyTrap && iTrapped)iTrapD=1; if(oO_Type ==ObjectType && !iPC && !iTrapD) { AssignCommand(oObject,DestroyAllEquipment(oObject)); AssignCommand(oObject,SetIsDestroyable(TRUE,FALSE,FALSE)); DestroyObject(oObject); } if(oO_Type ==ObjectType && !iPC && iTrapD) { SetTrapDisabled(oObject); } oObject = GetNextObjectInArea(oTargetA); } } void main() { //Destroy all triggers with traps DestroyAllObjectsTypesInArea("Area001",OBJECT_TYPE_TRIGGER,1); //destroy all traps on placables DestroyAllObjectsTypesInArea("Area001",OBJECT_TYPE_PLACEABLE,1); //destroys all placables and their content DestroyAllObjectsTypesInArea("Area001",OBJECT_TYPE_PLACEABLE,0); //destroy all items DestroyAllObjectsTypesInArea("Area001",OBJECT_TYPE_ITEM,0); }</code>

Sign In or Register to comment.