name: Scrap
card_text: 2 monsters, including a "Scrap" monster
  You can target 1 "Scrap" monster in your GY; Special Summon it, then destroy 1 card you control. If another face-up "Scrap" monster is destroyed by card effect, while you control this monster (except during the Damage Step): You can Special Summon 1 "Scrap" monster from your Deck, then destroy 1 card on the field. You can only use each effect of "Scrap Wyvern" once per turn.
external_ids: local SETCARD_ID_0 = 0x24 --Scrap
  
lua: local SETCARD_ID_0 = 0x24 --Scrap
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:IsExists(Card.IsLinkSetCard, 1, nil, 0x24)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local g2 = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g2, 1, 0, 0)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  end
  function s.cfilter(c)
  	return c:IsReason(REASON_EFFECT) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousPosition(POS_FACEUP)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g1:GetCount() > 0 and Duel.SpecialSummon(g1, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g2 = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  		if g2:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.HintSelection(g2)
  			Duel.Destroy(g2, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Scrap
  2 monsters, including a "Scrap" monster
  You can target 1 "Scrap" monster in your GY; Special Summon it, then destroy 1 card you control. If another face-up "Scrap" monster is destroyed by card effect, while you control this monster (except during the Damage Step): You can Special Summon 1 "Scrap" monster from your Deck, then destroy 1 card on the field. You can only use each effect of "Scrap Wyvern" once per turn.
target_text: -- Scrap
  local SETCARD_ID_0 = 0x24 --Scrap
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:IsExists(Card.IsLinkSetCard, 1, nil, 0x24)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local g2 = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g2, 1, 0, 0)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  end
  function s.cfilter(c)
  	return c:IsReason(REASON_EFFECT) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousPosition(POS_FACEUP)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g1:GetCount() > 0 and Duel.SpecialSummon(g1, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g2 = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  		if g2:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.HintSelection(g2)
  			Duel.Destroy(g2, REASON_EFFECT)
  		end
  	end
  end
  
  