name: Knightmare
card_text: 2 monsters with different names
  If this card is Link Summoned: You can discard 1 card, then target 1 Special Summoned monster in your opponent's Main Monster Zone; destroy it, then, if this card was co-linked when this effect was activated, you can draw 1 card. You can only use this effect of "Knightmare Cerberus" once per turn. Co-linked monsters you control cannot be destroyed by card effects.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.descon)
  	e1:SetCost(s.descost)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.desfilter(c)
  	return c:IsSummonType(SUMMON_TYPE_SPECIAL) and c:GetSequence() < 5
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.desfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.desfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	if e:GetHandler():GetMutualLinkedGroupCount() > 0 then
  		e:SetCategory(CATEGORY_DESTROY + CATEGORY_DRAW)
  		e:SetLabel(1)
  	else
  		e:SetCategory(CATEGORY_DESTROY)
  		e:SetLabel(0)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Destroy(tc, REASON_EFFECT) ~= 0 and e:GetLabel() == 1 and Duel.IsPlayerCanDraw(tp, 1) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  function s.indtg(e, c)
  	return c:GetMutualLinkedGroupCount() > 0
  end
  
  
source_text: Knightmare
  2 monsters with different names
  If this card is Link Summoned: You can discard 1 card, then target 1 Special Summoned monster in your opponent's Main Monster Zone; destroy it, then, if this card was co-linked when this effect was activated, you can draw 1 card. You can only use this effect of "Knightmare Cerberus" once per turn. Co-linked monsters you control cannot be destroyed by card effects.
target_text: -- Knightmare
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.descon)
  	e1:SetCost(s.descost)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.desfilter(c)
  	return c:IsSummonType(SUMMON_TYPE_SPECIAL) and c:GetSequence() < 5
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.desfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.desfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	if e:GetHandler():GetMutualLinkedGroupCount() > 0 then
  		e:SetCategory(CATEGORY_DESTROY + CATEGORY_DRAW)
  		e:SetLabel(1)
  	else
  		e:SetCategory(CATEGORY_DESTROY)
  		e:SetLabel(0)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Destroy(tc, REASON_EFFECT) ~= 0 and e:GetLabel() == 1 and Duel.IsPlayerCanDraw(tp, 1) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  function s.indtg(e, c)
  	return c:GetMutualLinkedGroupCount() > 0
  end
  
  