name: Ghostrick
card_text: When exactly 1 face-up "Ghostrick" monster you control (and no other cards) is destroyed by battle or an opponent's card effect and sent to your GY: Target 2 "Ghostrick" monsters in your GY with different names from the destroyed monster; Special Summon them in face-down Defense Position.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x8d --Ghostrick
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x8d --Ghostrick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	if
  		eg:GetCount() == 1
  		and tc:IsReason(REASON_DESTROY)
  		and (tc:IsReason(REASON_BATTLE) or rp == 1 - tp and tc:IsReason(REASON_EFFECT))
  		and tc:IsPreviousLocation(LOCATION_MZONE)
  		and tc:IsPreviousControler(tp)
  		and tc:IsSetCard(SETCARD_ID_0)
  		and tc:IsPreviousPosition(POS_FACEUP)
  	then
  		e:SetLabel(tc:GetCode())
  		return true
  	else
  		return false
  	end
  end
  function s.filter(c, e, tp, code)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(code) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc, e, tp, e:GetLabel())
  	end
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
  			and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 2, nil, e, tp, e:GetLabel())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 2, 2, nil, e, tp, e:GetLabel())
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if sg:GetCount() == 0 or ft <= 0 or (sg:GetCount() > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) then
  		return
  	end
  	if ft < sg:GetCount() then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		sg = sg:FilterSelect(tp, s.filter, ft, ft, nil, e, tp, e:GetLabel())
  	end
  	if sg:GetCount() > 0 then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEDOWN_DEFENSE)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  
  
source_text: Ghostrick
  When exactly 1 face-up "Ghostrick" monster you control (and no other cards) is destroyed by battle or an opponent's card effect and sent to your GY: Target 2 "Ghostrick" monsters in your GY with different names from the destroyed monster; Special Summon them in face-down Defense Position.
target_text: -- Ghostrick
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x8d --Ghostrick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	if
  		eg:GetCount() == 1
  		and tc:IsReason(REASON_DESTROY)
  		and (tc:IsReason(REASON_BATTLE) or rp == 1 - tp and tc:IsReason(REASON_EFFECT))
  		and tc:IsPreviousLocation(LOCATION_MZONE)
  		and tc:IsPreviousControler(tp)
  		and tc:IsSetCard(SETCARD_ID_0)
  		and tc:IsPreviousPosition(POS_FACEUP)
  	then
  		e:SetLabel(tc:GetCode())
  		return true
  	else
  		return false
  	end
  end
  function s.filter(c, e, tp, code)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(code) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc, e, tp, e:GetLabel())
  	end
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
  			and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 2, nil, e, tp, e:GetLabel())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 2, 2, nil, e, tp, e:GetLabel())
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if sg:GetCount() == 0 or ft <= 0 or (sg:GetCount() > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) then
  		return
  	end
  	if ft < sg:GetCount() then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		sg = sg:FilterSelect(tp, s.filter, ft, ft, nil, e, tp, e:GetLabel())
  	end
  	if sg:GetCount() > 0 then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEDOWN_DEFENSE)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  
  