PenUltima Online Forum Index Official Core: 096.7
Official Core: 097 2008-02-26
Donate towards the POL web hosting bill!
 POL Home   FAQ   Search    Memberlist   Usergroups    Register    Profile   Log in to check your private messages   Log in
Items disappear when dragged onto pack animals

 
Post new topic   Reply to topic    PenUltima Online Forum Index -> General Help 096
Display posts from previous:   

Author Message
Datus



Joined: 19 Sep 2006
Posts: 58

PostPosted: Tue Feb 20, 2007 12:54 am    Post subject: Items disappear when dragged onto pack animals Reply with quote

If I drag an item onto a pack animal, it vanishes. If however, I open the pack first and then drag the item into the open pack graphic, it works fine. Anyone have any idea what the problem could be?

Author Message
CWO



Joined: 04 Feb 2006
Posts: 685
Location: Chicago, IL USA

PostPosted: Tue Feb 20, 2007 1:22 am    Post subject: Reply with quote

Look in the events for the AI script for SYSEVENT_ITEM_GIVEN.

That handles items given to the pack animal without the pack being open.

Author Message
Datus



Joined: 19 Sep 2006
Posts: 58

PostPosted: Tue Feb 20, 2007 9:40 am    Post subject: Reply with quote

CWO wrote:
Look in the events for the AI script for SYSEVENT_ITEM_GIVEN.

That handles items given to the pack animal without the pack being open.


That's where I've been digging. The event is in tamed.src. It's a modified 095 distro version although I didn't touch the SYSEVENT_ITEM_GIVEN as I haven't really done too much with system events yet. It calls the function TakeItem which is below.

Code:

function TakeItem(ev)
  var npccfg := ReadConfigFile("npcdesc");
  var foodtype := npccfg[me.npctemplate].food;
  if(!foodtype)
    foodtype := "all";
  endif
  var cfg := ReadConfigFile("::food");
  var elem := FindConfigElem(cfg,foodtype);
  var foodarray := GetConfigStringArray(elem,"food");
  if(CStr(ev.item.objtype)in foodarray)
    PlaySoundEffect(me, CInt(0x3b)+ RandomInt(3));
    DestroyItem(ev.item);
    PrintTextAbovePrivate(me,"your pet looks happier.", master);
    SetObjProperty(me,"happiness", 100);
    return;
  endif
  if((me.graphic == 0x123)||(me.graphic == 0x124))
    if(!MoveItemToContainer(ev.item, me.backpack))
      say("*your pet cannot hold that item*");
      return;
    else
      PlaySoundEffect(me,0x49);
    endif
  else
    var yourpack := ev.source.backpack;
    MoveItemToContainer(ev.item,yourpack);
  endif
endfunction

Author Message
Yukiko



Joined: 02 Feb 2006
Posts: 1094
Location: Southern Central USA

PostPosted: Tue Feb 20, 2007 8:03 pm    Post subject: Reply with quote

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.


Last edited by Yukiko on Wed Feb 21, 2007 1:13 am; edited 1 time in total

Author Message
Datus



Joined: 19 Sep 2006
Posts: 58

PostPosted: Tue Feb 20, 2007 10:42 pm    Post subject: Reply with quote

Heh ... actually there is no one particular distro that I'm currently using. It's an enormous mishmash of various other distros and my own horrible coding that currently make up my shard ... of course I owe you a ton of credit for getting me off the ground and ALWAYS being there to help, which in all honesty makes me feel really good. I can't count the number of times when I would have been pulling my hair out otherwise.

Anyway problem fixed. Thank you thank you thank you!!!

Author Message
Yukiko



Joined: 02 Feb 2006
Posts: 1094
Location: Southern Central USA

PostPosted: Wed Feb 21, 2007 1:28 am    Post subject: Reply with quote

No problem Datus. I help when I can.

I enjoy the opportunity of helping other people. I remember when I was starting out and how I would have been dead in the water without folks like Racalac, Maud, Shinigami, Austin, Marilla, CWO and the others who have helped me.

Plus this one was a double bonus because it helps me as well.

I only wish I knew more. I still want to fix that worker.src script.
*grins*

What is surprising though is that no one has reported this bug before. Atleast I don't recall ever seeing a post about it.

Post new topic   Reply to topic    PenUltima Online Forum Index -> General Help 096 All times are GMT - 4 Hours
Page 1 of 1

 




Powered by phpBB © 2001, 2005 phpBB Group :: Theme & Graphics by GHS & Scott E. Royalty