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?
Destroy contents of chest along with chest?
Débuté par
CPK87
, févr. 11 2014 12:38
#1
Posté 11 février 2014 - 12:38
#2
Posté 11 février 2014 - 01:51
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....
this is the simple form, that ignores if a container is already empty, but it's the idea...
ps. untested.
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
Posté 11 février 2014 - 02:20
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
Posté 11 février 2014 - 02:47
There might be a function in ginc_item that does the trick.
#5
Posté 11 février 2014 - 03:25
Set the Droppable Flag on all items in the chest to zero before destroying the chest.... that should work i think.
#6
Posté 11 février 2014 - 03:32
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
Posté 11 février 2014 - 05:30
Got it working - I was doing something dumb on my part, so I believe your first script worked too. Thanks man.
#8
Posté 11 février 2014 - 10:10
DESTROY!!!!!
GM: you destroy the chest, fifty Hezrou attack the party...
GM: you destroy the chest, fifty Hezrou attack the party...
Modifié par Morbane, 11 février 2014 - 10:11 .





Retour en haut






