Aller au contenu

Photo

Destroy contents of chest along with chest?


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
CPK87

CPK87
  • Members
  • 73 messages
I am using the ga_destroy script on a dialogue node to destroy a chest.  The problem is, the chest drops its contents on the ground, which I also want to destroy.  I tried modifying the section of the script as such:


while (GetIsObjectValid(oObject)){ if (GetHasInventory(oObject))        {        object oInvItem = GetFirstItemInInventory(oObject);        while(GetIsObjectValid(oInvItem)) {             DestroyObject(oInvItem,0.0);            oInvItem = GetNextItemInInventory(oObject);          }        } PrepForDestruction(oObject);        DestroyObject (oObject, fDelay);        iInst ++;        oObject = GetObjectByTag(sTagString, iInst);
}


Where the bolded section is the part I added.  Why wouldn't this clear the chest's inventory so that it doesn't drop on the ground?  

#2
kevL

kevL
  • Members
  • 4 070 messages
because of the way the engine finishes execution of certain functions. Eg, when an item is told to b Destroyed, it won't actually get destroyed *until the script is completed*

in other words, the command DestroyObject() is merely listing those items to be destroyed -- and due to the order of the Destroy container/items commands (which i'm not sure of) -- the items are considered to still be present in the container when the container is destroyed. Or something like that....


while (GetIsObjectValid(oObject))
{
    // has inventory, must be deleted after items inside are
    // destroyed, ie. after script completes.
    if (GetHasInventory(oObject))
    {
        DelayCommand(0.1, DestroyContainer(oObject));

        object oInvItem = GetFirstItemInInventory(oObject);
        while (GetIsObjectValid(oInvItem))
        {
            DestroyObject(oInvItem, 0.0);
            oInvItem = GetNextItemInInventory(oObject);
        }
    }
    else // no inventory, just destroy it.
    {
        PrepForDestruction(oObject);
        DestroyObject(oObject, fDelay);
    }

    iInst ++;
    oObject = GetObjectByTag(sTagString, iInst);
}

// helper function
void DestroyContainer(object oObject)
{
    DestroyObject(oObject);
}



this is the simple form, that ignores if a container is already empty, but it's the idea...

ps. untested.

#3
CPK87

CPK87
  • Members
  • 73 messages
Just ran it, didn't work... although the DestroyContainer() function did manage to destroy my creature spawns that were scripted to spawn at the same moment, haha. I'm not sure why it would do that.

#4
Dann-J

Dann-J
  • Members
  • 3 161 messages
There might be a function in ginc_item that does the trick.

#5
Loki_999

Loki_999
  • Members
  • 430 messages
Set the Droppable Flag on all items in the chest to zero before destroying the chest.... that should work i think.

#6
kevL

kevL
  • Members
  • 4 070 messages
this worked for me, even with Plot and Cursed items inside


// 'ga_destroycontainer'
//
// kevL, 2014 feb 10
//
// Destroys a container-item by destroying any items within first.
// Also works for destroying non-container items.

// sContainer: tag of container. Should be unique in the module.


void DestroyContainer(object oContainer)
{
    DestroyObject(oContainer);
}


void main(string sContainer)
{
    object oContainer = GetObjectByTag(sContainer);
    if (GetHasInventory(oContainer)
            && GetIsObjectValid(GetFirstItemInInventory(oContainer)))
    {
        object oItem = GetFirstItemInInventory(oContainer);
        while (GetIsObjectValid(oItem))
        {
            DestroyObject(oItem);

            oItem = GetNextItemInInventory(oContainer);
        }
    }

    DelayCommand(0.1f, DestroyContainer(oContainer));
}


#7
CPK87

CPK87
  • Members
  • 73 messages
Got it working - I was doing something dumb on my part, so I believe your first script worked too. Thanks man.

#8
Morbane

Morbane
  • Members
  • 1 883 messages
DESTROY!!!!!

GM: you destroy the chest, fifty Hezrou attack the party...

:devil:

Modifié par Morbane, 11 février 2014 - 10:11 .