name: Millennium
card_text: Show 5 "Forbidden One" Monster Cards from your hand, Deck, and/or face-up field, then Special Summon 1 "The Unstoppable Exodia Incarnate" from your Extra Deck, then shuffle the face-up Monster Cards you control into the Deck, except "Exodia" Monster Cards whose original Levels are 10 or higher, and "Millennium" Monster Cards, also you cannot Summon for the rest of this turn. After activation, shuffle this card into the Deck instead of sending it to the GY.
external_ids: local CARD_ID_0 = 83257450 --The Unstoppable Exodia Incarnate
  local CARD_ID_1 = 4130270 --G.B. Hunter
  local SETCARD_ID_0 = 0x40 --Forbidden
  local SETCARD_ID_1 = 0xde --Exodia
  
lua: local CARD_ID_0 = 83257450 --The Unstoppable Exodia Incarnate
  local CARD_ID_1 = 4130270 --G.B. Hunter
  local SETCARD_ID_0 = 0x40 --Forbidden
  local SETCARD_ID_1 = 0xde --Exodia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c, e, tp)
  	return c:IsFaceupEx() and c:IsSetCard(SETCARD_ID_1) and bit.band(c:GetOriginalType(), TYPE_MONSTER) ~= 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1)
  			and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_HAND + LOCATION_ONFIELD, 0, 5, nil)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.dfilter(c)
  	return c:IsFaceup() and bit.band(c:GetOriginalType(), TYPE_MONSTER) ~= 0 and not (c:GetOriginalLevel() >= 10 and c:IsSetCard(SETCARD_ID_1) or c:IsSetCard(0x1ae))
  end
  function s.tdfilter(c)
  	return s.dfilter(c) and c:IsAbleToDeck()
  end
  function s.ndfilter(c)
  	return s.dfilter(c) and not c:IsAbleToDeck()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_HAND + LOCATION_ONFIELD, 0, 5, nil) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK + LOCATION_HAND + LOCATION_ONFIELD, 0, 5, 5, nil, e, tp)
  		Duel.ConfirmCards(tp, g)
  		Duel.ConfirmCards(1 - tp, g)
  		if g:FilterCount(Card.IsLocation, nil, LOCATION_HAND) >= 1 then
  			Duel.ShuffleHand(tp)
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  		local tc = sg:GetFirst()
  		if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) then
  			local tg = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_ONFIELD, 0, nil)
  			if #tg > 0 then
  				Duel.BreakEffect()
  				Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	Duel.RegisterEffect(e2, tp)
  	local e3 = e1:Clone()
  	e3:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
  	Duel.RegisterEffect(e3, tp)
  	if c:IsRelateToEffect(e) and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		Duel.BreakEffect()
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT, tp, true)
  	end
  end
  
  
source_text: Millennium
  Show 5 "Forbidden One" Monster Cards from your hand, Deck, and/or face-up field, then Special Summon 1 "The Unstoppable Exodia Incarnate" from your Extra Deck, then shuffle the face-up Monster Cards you control into the Deck, except "Exodia" Monster Cards whose original Levels are 10 or higher, and "Millennium" Monster Cards, also you cannot Summon for the rest of this turn. After activation, shuffle this card into the Deck instead of sending it to the GY.
target_text: -- Millennium
  local CARD_ID_0 = 83257450 --The Unstoppable Exodia Incarnate
  local CARD_ID_1 = 4130270 --G.B. Hunter
  local SETCARD_ID_0 = 0x40 --Forbidden
  local SETCARD_ID_1 = 0xde --Exodia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c, e, tp)
  	return c:IsFaceupEx() and c:IsSetCard(SETCARD_ID_1) and bit.band(c:GetOriginalType(), TYPE_MONSTER) ~= 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1)
  			and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_HAND + LOCATION_ONFIELD, 0, 5, nil)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.dfilter(c)
  	return c:IsFaceup() and bit.band(c:GetOriginalType(), TYPE_MONSTER) ~= 0 and not (c:GetOriginalLevel() >= 10 and c:IsSetCard(SETCARD_ID_1) or c:IsSetCard(0x1ae))
  end
  function s.tdfilter(c)
  	return s.dfilter(c) and c:IsAbleToDeck()
  end
  function s.ndfilter(c)
  	return s.dfilter(c) and not c:IsAbleToDeck()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_HAND + LOCATION_ONFIELD, 0, 5, nil) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK + LOCATION_HAND + LOCATION_ONFIELD, 0, 5, 5, nil, e, tp)
  		Duel.ConfirmCards(tp, g)
  		Duel.ConfirmCards(1 - tp, g)
  		if g:FilterCount(Card.IsLocation, nil, LOCATION_HAND) >= 1 then
  			Duel.ShuffleHand(tp)
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  		local tc = sg:GetFirst()
  		if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) then
  			local tg = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_ONFIELD, 0, nil)
  			if #tg > 0 then
  				Duel.BreakEffect()
  				Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	Duel.RegisterEffect(e2, tp)
  	local e3 = e1:Clone()
  	e3:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
  	Duel.RegisterEffect(e3, tp)
  	if c:IsRelateToEffect(e) and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		Duel.BreakEffect()
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT, tp, true)
  	end
  end
  
  