Hello fellow XMLspawner/attachment Fans!
I've looked over all documentation, and worked with others trying to figure out a solution for this problem to no avail. I'm making this post in hopes someone understands what I'm trying to do and can tell me how to correctly make this possible.
The Goal
Attaching a pack to a creature/npc that can be opened and items from within be obtained by other players. (even after the pack has been closed by a previous player)
Current Status
This works fine...
1. Add pack to creature/npc
2. Add attachment to creature/npc for the packid
Because the creature/npc is the "owner / parent" of the pack the items could not be obtained from the pack "freely" so the parent is being changed to the player. I noticed server crash at first doing this and had to use parent = null then set parent = player. After doing this I can dbl click the creature and open the newly added pack via the help of the attachment...
So what's wrong?
Once the pack is closed by the player it can not be reopened due to the creature/npc not being the parent of the pack any longer. So with this problem I am trying to now add an attachment to the pack (on creation) that contains the creature/npc's id and using an OnMovement check, set the creature/npc as the parent of the pack again when the pack gets closed.
The OnMovement check is nested in the item class which is located in the same script the attachment class is (each having their own respective class; xmlAttachment class and Item class). Any suggestions on retrieving the original parent of the pack and setting it as the parent again? I understand the XmlAttach.FindAttachment usage but I'm getting lost trying to do this from the Item class since that's where the OnMovement check is.
Maybe I've gone about this the wrong way and there's a much easier way to handle this so if anyone can instruct me how to do this using the attachments or another way I just need to restore the original parent of the pack once it is closed.
Thanks,
Tecmo
yeah, you dont want to mess around with the Parent field on the container.
If you wanted to use attachments give player access to containers being held on flagged creatures, you could make a little mod like this in basecreature.cs. Add this override
QUOTE |
//ARTEGORDONMOD // allow players to lift items from flagged creature packs public override bool CheckNonlocalLift(Mobile from, Item item) { if (XmlAttach.FindAttachment(this, typeof(XmlData), "AllowAccess") != null) return true;
return base.CheckNonlocalLift(from, item); }
|
That should allow them to remove the contents of containers held by the flagged creatures.
You also need to make the check in the OnDoubleClick method in basecreature.cs to allow players to actually open the packs by dclicking with this mod
QUOTE |
public override void OnDoubleClick(Mobile from) {
//ARTEGORDONMOD // allow players to open flagged creature packs by double clicking bool allowaccess = (XmlAttach.FindAttachment(this, typeof(XmlData), "AllowAccess") != null);
if ((from.AccessLevel >= AccessLevel.GameMaster || allowaccess) && !Body.IsHuman) { Container pack = this.Backpack;
if (pack != null) pack.DisplayTo(from); }
|
then just attach an XmlData attachment named "AllowAccess" to a creature and players will be able to access any containers that they carry.
These mods will have no impact on normal creature or container access.
Note that there is nothing special about using the XmlData attachment, and you could use more sophisticated attachments or add more sophisticated tests than just testing for the presence of the attachment.
Thanks for the reply Arte!
We actually accomplished our goal using 2 attachments.
We couldn't have done it without your great work with Xml's though... Thank you so much, you make it enjoyable!