name: Xyz
card_text: When your opponent activates a monster effect: Detach 1 Xyz Material from a monster you control; negate the activation, and if you do, destroy that monster.
external_ids: local CARD_ID_0 = 85551711 --Ebon High Magician
  
lua: local CARD_ID_0 = 85551711 --Ebon High Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainNegatable(ev)
  end
  function s.only_filter(c, onlyc, tp)
  	local require_count = c == onlyc and 2 or 1
  	return c:CheckRemoveOverlayCard(tp, require_count, REASON_COST)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local c = e:GetHandler()
  		if c:IsLocation(LOCATION_HAND) then
  			local fromhand_effects = { c:IsHasEffect(EFFECT_TRAP_ACT_IN_HAND) }
  			local available_fromhand_effects = {}
  			for _, te in ipairs(fromhand_effects) do
  				local cost = te:GetCost()
  				if te:CheckCountLimit(tp) and (not cost or cost(te, tp, eg, ep, ev, re, r, rp, 0, e)) then
  					table.insert(available_fromhand_effects, te)
  				end
  			end
  			if #available_fromhand_effects == 1 and available_fromhand_effects[1]:GetValue() == CARD_ID_0 then
  				return Duel.IsExistingMatchingCard(s.only_filter, tp, LOCATION_MZONE, 0, 1, nil, available_fromhand_effects[1]:GetHandler(), tp)
  			else
  				return Duel.CheckRemoveOverlayCard(tp, 1, 0, 1, REASON_COST)
  			end
  		else
  			return Duel.CheckRemoveOverlayCard(tp, 1, 0, 1, REASON_COST)
  		end
  	end
  	Duel.RemoveOverlayCard(tp, 1, 0, 1, 1, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  
source_text: Xyz
  When your opponent activates a monster effect: Detach 1 Xyz Material from a monster you control; negate the activation, and if you do, destroy that monster.
target_text: -- Xyz
  local CARD_ID_0 = 85551711 --Ebon High Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainNegatable(ev)
  end
  function s.only_filter(c, onlyc, tp)
  	local require_count = c == onlyc and 2 or 1
  	return c:CheckRemoveOverlayCard(tp, require_count, REASON_COST)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local c = e:GetHandler()
  		if c:IsLocation(LOCATION_HAND) then
  			local fromhand_effects = { c:IsHasEffect(EFFECT_TRAP_ACT_IN_HAND) }
  			local available_fromhand_effects = {}
  			for _, te in ipairs(fromhand_effects) do
  				local cost = te:GetCost()
  				if te:CheckCountLimit(tp) and (not cost or cost(te, tp, eg, ep, ev, re, r, rp, 0, e)) then
  					table.insert(available_fromhand_effects, te)
  				end
  			end
  			if #available_fromhand_effects == 1 and available_fromhand_effects[1]:GetValue() == CARD_ID_0 then
  				return Duel.IsExistingMatchingCard(s.only_filter, tp, LOCATION_MZONE, 0, 1, nil, available_fromhand_effects[1]:GetHandler(), tp)
  			else
  				return Duel.CheckRemoveOverlayCard(tp, 1, 0, 1, REASON_COST)
  			end
  		else
  			return Duel.CheckRemoveOverlayCard(tp, 1, 0, 1, REASON_COST)
  		end
  	end
  	Duel.RemoveOverlayCard(tp, 1, 0, 1, 1, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  