I have a function for doing that which I call
MoveInventory.
I beleive others have pointed out problems with how I implemented this, but I haven't encountered anything. I hope some of those that know what they are doing chime in and explain how to improve my function.
While it owuld be best to go to pastebin to see my function (see link above), I am also posting it here:
int MoveInventory(object oSource, object oTarget)
{
object oItem, oCopy; int nCount;
// move gold
if(GetObjectType(oSource)==OBJECT_TYPE_CREATURE)
{
int nGold = GetGold(oSource);
if(nGold)
{
AssignCommand(oTarget, TakeGoldFromCreature(nGold, oSource));
++nCount;
}
}
// copy containers
oItem = GetFirstItemInInventory(oSource);
while(GetIsObjectValid(oItem))
{
if(GetHasInventory(oItem)&&!GetLocalInt(oItem,"COPIED"))
{
nCount++;
// create a copy of the container
oCopy = CreateItemOnObject(GetResRef(oItem), oTarget, 1, GetTag(oItem));
SetLocalInt(oItem, "COPIED", TRUE); // mark the original as copied
SetName(oCopy, GetName(oItem));
SetDescription(oCopy, GetDescription(oItem));
SetIdentified(oCopy, GetIdentified(oItem));
// copy contents of container
nCount += MoveInventory(oItem, oCopy);
DestroyObject(oItem, 0.1);
}
oItem = GetNextItemInInventory(oSource);
}
// copy items
oItem = GetFirstItemInInventory(oSource);
while(GetIsObjectValid(oItem))
{
if(!GetHasInventory(oItem)&&!GetLocalInt(oItem,"COPIED"))
{
nCount++;
CopyItem(oItem, oTarget, TRUE);
SetLocalInt(oItem, "COPIED", TRUE);
DestroyObject(oItem, 0.1);
}
oItem = GetNextItemInInventory(oSource);
}
return nCount;
}
Modifié par henesua, 21 février 2014 - 01:04 .