name: Vain
card_text: When an opponent's Xyz Monster declares an attack: Activate this card by targeting the attacking monster. It cannot attack, also its effects are negated. While that monster is on the field, during each of your opponent's End Phases: Send the top 3 cards of the opponent's Deck to the Graveyard. When that monster leaves the field, destroy this card.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetCondition(s.descon)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--discard deck
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCategory(CATEGORY_DECKDES)
  	e3:SetCountLimit(1)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.deckcon)
  	e3:SetTarget(s.decktg)
  	e3:SetOperation(s.deckop)
  	c:RegisterEffect(e3)
  	--disable
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_TARGET)
  	e4:SetCode(EFFECT_DISABLE)
  	e4:SetRange(LOCATION_SZONE)
  	c:RegisterEffect(e4)
  	--cannot attack
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_CANNOT_ATTACK)
  	c:RegisterEffect(e5)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local at = Duel.GetAttacker()
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return at:IsControler(1 - tp) and at:IsType(TYPE_XYZ) and at:IsOnField() and at:IsCanBeEffectTarget(e)
  	end
  	Duel.SetTargetCard(at)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, at, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		c:SetCardTarget(tc)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsStatus(STATUS_DESTROY_CONFIRMED) then
  		return false
  	end
  	local tc = c:GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.deckcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer() and e:GetHandler():GetFirstCardTarget() ~= nil
  end
  function s.decktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, 1 - tp, 3)
  end
  function s.deckop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	Duel.DiscardDeck(1 - tp, 3, REASON_EFFECT)
  end
  
  
source_text: Vain
  When an opponent's Xyz Monster declares an attack: Activate this card by targeting the attacking monster. It cannot attack, also its effects are negated. While that monster is on the field, during each of your opponent's End Phases: Send the top 3 cards of the opponent's Deck to the Graveyard. When that monster leaves the field, destroy this card.
target_text: -- Vain
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetCondition(s.descon)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--discard deck
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCategory(CATEGORY_DECKDES)
  	e3:SetCountLimit(1)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCondition(s.deckcon)
  	e3:SetTarget(s.decktg)
  	e3:SetOperation(s.deckop)
  	c:RegisterEffect(e3)
  	--disable
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_TARGET)
  	e4:SetCode(EFFECT_DISABLE)
  	e4:SetRange(LOCATION_SZONE)
  	c:RegisterEffect(e4)
  	--cannot attack
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_CANNOT_ATTACK)
  	c:RegisterEffect(e5)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local at = Duel.GetAttacker()
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return at:IsControler(1 - tp) and at:IsType(TYPE_XYZ) and at:IsOnField() and at:IsCanBeEffectTarget(e)
  	end
  	Duel.SetTargetCard(at)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, at, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		c:SetCardTarget(tc)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsStatus(STATUS_DESTROY_CONFIRMED) then
  		return false
  	end
  	local tc = c:GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.deckcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer() and e:GetHandler():GetFirstCardTarget() ~= nil
  end
  function s.decktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, 1 - tp, 3)
  end
  function s.deckop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	Duel.DiscardDeck(1 - tp, 3, REASON_EFFECT)
  end
  
  