The first question that needed to be asked here was "Which version of scripts are you using?"
I happen to know the answer however because I provided a (mostly) converted (to POL 0.96) POL 0.95 Distro to Datus.
I actually decided to look into this issue as I am running the same basic set of scripts and I found the problem.
So anyone running the converted 0.95 Distro should take note of this bug since it will exist in your scripts as well.
The problem arises from the fact that the script is using two separate containers depending on how items are given to the NPC.
If you open the pack animal's pack by double clicking on it you will get the animal's
tamed storage area container. If you drag an item onto the "closed" animal the item gets placed into its backpack.
Take note of the following code snippets from the tamed AI script.
First at the beginning the variable mypack is defined by
Code:
var mypack := FindPack(me.serial);
Here is the function FindPack located in the tamedai.src file:
Code:
function FindPack(myserial)
var mybank := OpenTamedStorageAreas();
var bank_obj_name := "Bankbox " + Hex(myserial);
var bankbox := FindRootItemInStorageArea(mybank, bank_obj_name);
if(!bankbox)
if((me.graphic == 0x123)||(me.graphic == 0x124))
bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, 0x966b);
else
bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, UOBJ_BANKBOX);
endif
else
if(((me.graphic == 0x123)||(me.graphic == 0x124))&&((me.backpack).objtype == UOBJ_BANKBOX))
DestroyItem(bankbox);
bankbox := CreateRootItemInStorageArea(mybank, bank_obj_name, 0x966b);
endif
endif
return bankbox;
endfunction
Note that FindPack is returning a reference to the tamed storage area container.
Now look at the relevant part of the OpenMyPack function that gets called when you double click a tamed NPC:
Code:
function OpenMyPack();
if((me.graphic == 0x123)||(me.graphic == 0x124)) // If I am a pack animal
if(Distance(me, master)> 2)
return;
endif
foreach item in EnumerateItemsInContainer(mypack)
if(item.container == me.backpack)
MoveItemToContainer(item, me.backpack);
endif
endforeach
SendOpenSpecialContainer(master, mypack);
return;
else
..
Not sure what is happening with the
if(item.container == me.backpack) statement but the part we are interested in is the SendOpenSpecialContainer which opens the mypack container which is alright as long as all items given to the NPC are actually going to that container. The problem is that when you drop an item on the NPC rather than placing it in the opened pack it is actually going to the NPCs backpack not to the NPCs tamed storage container. Here's the relevant section of the TakeItem function, found in tamedai, that accepts items dropped on an NPCs head:
Code:
if((me.graphic == 0x123)||(me.graphic == 0x124))
// Changed from mypack to me.backpack. Upon death npcs would not have the item
// on them for loot, causing stuff to be left in their storage. BAD NPC!
if(!MoveItemToContainer(ev.item, me.backpack))
say("*your pet cannot hold that item*");
return;
else
Whoever had "fixed" the death problem (note the comments) actually created the current one. Any item "given" to the NPC by dropping it on its head rather than dropping it into the opened pack gets placed in the backpack rather than the tamed storage area container.
This creates in effect two separate areas for storage. It also creates the illusion that the item is not on the NPC because all you are seeing is the opened tamed storage area container when you double click the NPC. You don’t see what’s in its backpack. Now for some reason the death problem noted in the commented area seems to be fixed because upon death the items in the tamed storage container get dumped into the corpse container along with the backpack contents.
"OK, we know what's wrong. How do we fix it?" you ask.
If you’ll be patient I’ll tell you!
If you want to have all items dropped into the NPCs backpack as was the original intention of the person who attempted to fix the death error mentioned above you need do a few things.
First is to move the following code located somewhere near line 74 of the tamedai source to the line just above the “var mypack” line located near line 30:
Code:
if(!me.backpack)
var newbackpack := CreateItemAtLocation(5288, 1176, 0, 0xe75,1, "britannia_alt");
EquipItem(me, newbackpack);
Endif
Second is replace the var mypack := FindPack(me.serial) at the beginning of tamedai with var mypack := me.backpack.
The third thing that needs to be done is inside the OpenMyPack function change the code from this:
Code:
function OpenMyPack();
if((me.graphic == 0x123)||(me.graphic == 0x124))
if(Distance(me, master)> 2)
return;
endif
foreach item in EnumerateItemsInContainer(mypack)
if(item.container == me.backpack)
MoveItemToContainer(item, me.backpack);
endif
endforeach
SendOpenSpecialContainer(master, mypack);
return;
else
…
To this:
Code:
function OpenMyPack();
if((me.graphic == 0x123)||(me.graphic == 0x124))
if(Distance(me, master)> 2)
return;
endif
return SendOpenSpecialContainer(master, me.backpack);
else
…
I think that about does it.
This same bug might exist in other scriptbases since many are based on the Distro so you all should look into your tamedai script.