Kamras

Member
I need to have an XML Attachment removed upon doule clicking on an item to start the process then targeting another item to remove the attachment from the item.

I know this snipped can be used to add an attachment, but how would I remove an attachment? I've been kicking this around for a bit and it's buggin me.

Code:
XmlAttach.FindAttachment(item, typeof(ItemAtt))
 
This needs to be done via script via interaction with an item. So the player uses the item, they get a target courser, they target an item with an attachment and it gets deleted. In game commands are not the target goal for this.
 
This needs to be done via script via interaction with an item. So the player uses the item, they get a target courser, they target an item with an attachment and it gets deleted. In game commands are not the target goal for this.
Is there a reason why this needs to be done via script?
Any tool can have the use overridden by adding an attachment to it. Once the attachment is in place, you set your own Use (the SuccessAction is where you would put your attachment delete code). Here is how you can delete an attachment, using an Xmlspawner:
Code:
SETONTRIGMOB/ATTACHMENT,xmlvalue,XS,DoDelete/true
 
Set a variable for the attachment and delete it.

var todelete = XmlAttach.FindAttachment(item, typeof(ItemAtt))

todelete.Delete();
 
Assuming you're not using Framework 4 you should use:

Code:
XmlAttachment todelete = XmlAttach.FindAttachment(item, typeof(YourAttachmentClass));

if(todelete!=null && !todelete.Deleted)//null checks - prevent server crash
	todelete.Delete();
 
@ taas23 and @Ravenwolf - thank you for your suggestions. I tried both and ended up using Ravenwolfs method as it made more sense to what my initial goal was. I did not encounter any server crashes yet but I did forget the null check, thank you fwiffo for reminding me of that. :) Better to add in the code now then to find out later. :)
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back