name: The
card_text: You can discard 1 card; send 1 "Phantom Knights" card from your Deck to the GY, except "The Phantom Knights of Torn Scales". If another "Phantom Knights" card in your GY is banished, while this card is in your GY: You can Special Summon this card, but banish it when it leaves the field. You can only use each effect of "The Phantom Knights of Torn Scales" once per turn.
external_ids: local SETCARD_ID_0 = 0x10db --The
  
lua: local SETCARD_ID_0 = 0x10db --The
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1, id)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCost(s.sgcost)
  	e1:SetTarget(s.sgtg)
  	e1:SetOperation(s.sgop)
  	c:RegisterEffect(e1)
  	--tograve
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCode(EVENT_REMOVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.sscon)
  	e2:SetTarget(s.sstg)
  	e2:SetOperation(s.ssop)
  	c:RegisterEffect(e2)
  end
  function s.sgcost(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.filter(c)
  	return not c:IsCode(id) and ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) or (c:IsSetCard(0xdb) and c:IsType(TYPE_SPELL + TYPE_TRAP))) and c:IsAbleToGrave()
  end
  function s.sgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.sgop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoGrave(g, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_GRAVE) and c:IsPreviousControler(tp) and ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) or (c:IsSetCard(0xdb) and c:IsType(TYPE_SPELL + TYPE_TRAP)))
  end
  function s.sscon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.sstg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.ssop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e1, true)
  	end
  end
  
  
source_text: The
  You can discard 1 card; send 1 "Phantom Knights" card from your Deck to the GY, except "The Phantom Knights of Torn Scales". If another "Phantom Knights" card in your GY is banished, while this card is in your GY: You can Special Summon this card, but banish it when it leaves the field. You can only use each effect of "The Phantom Knights of Torn Scales" once per turn.
target_text: -- The
  local SETCARD_ID_0 = 0x10db --The
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1, id)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCost(s.sgcost)
  	e1:SetTarget(s.sgtg)
  	e1:SetOperation(s.sgop)
  	c:RegisterEffect(e1)
  	--tograve
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCode(EVENT_REMOVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.sscon)
  	e2:SetTarget(s.sstg)
  	e2:SetOperation(s.ssop)
  	c:RegisterEffect(e2)
  end
  function s.sgcost(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.filter(c)
  	return not c:IsCode(id) and ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) or (c:IsSetCard(0xdb) and c:IsType(TYPE_SPELL + TYPE_TRAP))) and c:IsAbleToGrave()
  end
  function s.sgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.sgop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoGrave(g, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_GRAVE) and c:IsPreviousControler(tp) and ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) or (c:IsSetCard(0xdb) and c:IsType(TYPE_SPELL + TYPE_TRAP)))
  end
  function s.sscon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.sstg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.ssop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e1, true)
  	end
  end
  
  