name: NEX
card_text: Send 1 face-up "Neo-Spacian" monster you control to the Graveyard. Special Summon 1 Level 4 monster with the same name from your Extra Deck.
external_ids: local SETCARD_ID_0 = 0x1f --Neo-Spacian
  
lua: local SETCARD_ID_0 = 0x1f --Neo-Spacian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, e, tp)
  	local code = c:GetCode()
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, code, e, tp, c)
  end
  function s.filter2(c, code, e, tp, mc)
  	return c:IsCode(code) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false) and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter1(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter1, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc1 = Duel.GetFirstTarget()
  	if tc1:IsRelateToEffect(e) and Duel.SendtoGrave(tc1, REASON_EFFECT) ~= 0 then
  		local code = tc1:GetCode()
  		local tc2 = Duel.GetFirstMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, nil, code, e, tp, nil)
  		if tc2 and Duel.SpecialSummon(tc2, 0, tp, tp, true, false, POS_FACEUP) ~= 0 then
  			tc2:CompleteProcedure()
  		end
  	end
  end
  
  
source_text: NEX
  Send 1 face-up "Neo-Spacian" monster you control to the Graveyard. Special Summon 1 Level 4 monster with the same name from your Extra Deck.
target_text: -- NEX
  local SETCARD_ID_0 = 0x1f --Neo-Spacian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, e, tp)
  	local code = c:GetCode()
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, code, e, tp, c)
  end
  function s.filter2(c, code, e, tp, mc)
  	return c:IsCode(code) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false) and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter1(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter1, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc1 = Duel.GetFirstTarget()
  	if tc1:IsRelateToEffect(e) and Duel.SendtoGrave(tc1, REASON_EFFECT) ~= 0 then
  		local code = tc1:GetCode()
  		local tc2 = Duel.GetFirstMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, nil, code, e, tp, nil)
  		if tc2 and Duel.SpecialSummon(tc2, 0, tp, tp, true, false, POS_FACEUP) ~= 0 then
  			tc2:CompleteProcedure()
  		end
  	end
  end
  
  