name: Infinite
card_text: Activate this card by sending 1 face-up "Infinite Machine" from your Spell & Trap Zone to the GY. This face-up card cannot be destroyed by your opponent's card effects. Neither player can target "Timelord" monsters you control with card effects, or return "Timelord" monsters from the field to the Deck. Once per turn, if you control no monsters: You can Special Summon up to 1 "Timelord" monster each from your hand, Deck, and GY, with different names, ignoring their Summoning conditions.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 36894320 --Infinite Machine
  local SETCARD_ID_0 = 0x4a --Timelord
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 36894320 --Infinite Machine
  local SETCARD_ID_0 = 0x4a --Timelord
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.actcost)
  	e1:SetTarget(s.acttg)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  	--untarget
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--cannot to deck
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_TO_DECK)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetTargetRange(1, 1)
  	e4:SetTarget(s.tdtg)
  	c:RegisterEffect(e4)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_QUICK_O)
  	e5:SetCode(EVENT_FREE_CHAIN)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCondition(s.spcon)
  	e5:SetCost(s.spcost)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.acfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1) and c:IsAbleToGraveAsCost()
  end
  function s.actcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.acfilter, tp, LOCATION_SZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.acfilter, tp, LOCATION_SZONE, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.acttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	if s.spcon(e, tp, eg, ep, ev, re, r, rp) and s.spcost(e, tp, eg, ep, ev, re, r, rp, 0) and s.sptg(e, tp, eg, ep, ev, re, r, rp, 0) and Duel.SelectYesNo(tp, 94) then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		e:SetOperation(s.spop)
  		s.spcost(e, tp, eg, ep, ev, re, r, rp, 1)
  		s.sptg(e, tp, eg, ep, ev, re, r, rp, 1)
  	end
  end
  function s.tdtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLocation(LOCATION_MZONE)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:GetFlagEffect(id) == 0
  	end
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.sptg(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_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.gselect(g)
  	return aux.dncheck(g) and g:GetClassCount(Card.GetLocation) == #g
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, s.gselect, false, 1, math.min(ft, 3))
  	if sg then
  		Duel.SpecialSummon(sg, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  
  
source_text: Infinite
  Activate this card by sending 1 face-up "Infinite Machine" from your Spell & Trap Zone to the GY. This face-up card cannot be destroyed by your opponent's card effects. Neither player can target "Timelord" monsters you control with card effects, or return "Timelord" monsters from the field to the Deck. Once per turn, if you control no monsters: You can Special Summon up to 1 "Timelord" monster each from your hand, Deck, and GY, with different names, ignoring their Summoning conditions.
target_text: -- Infinite
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 36894320 --Infinite Machine
  local SETCARD_ID_0 = 0x4a --Timelord
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.actcost)
  	e1:SetTarget(s.acttg)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  	--untarget
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--cannot to deck
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_TO_DECK)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetTargetRange(1, 1)
  	e4:SetTarget(s.tdtg)
  	c:RegisterEffect(e4)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_QUICK_O)
  	e5:SetCode(EVENT_FREE_CHAIN)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCondition(s.spcon)
  	e5:SetCost(s.spcost)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.acfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1) and c:IsAbleToGraveAsCost()
  end
  function s.actcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.acfilter, tp, LOCATION_SZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.acfilter, tp, LOCATION_SZONE, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.acttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	if s.spcon(e, tp, eg, ep, ev, re, r, rp) and s.spcost(e, tp, eg, ep, ev, re, r, rp, 0) and s.sptg(e, tp, eg, ep, ev, re, r, rp, 0) and Duel.SelectYesNo(tp, 94) then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		e:SetOperation(s.spop)
  		s.spcost(e, tp, eg, ep, ev, re, r, rp, 1)
  		s.sptg(e, tp, eg, ep, ev, re, r, rp, 1)
  	end
  end
  function s.tdtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLocation(LOCATION_MZONE)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:GetFlagEffect(id) == 0
  	end
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.sptg(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_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.gselect(g)
  	return aux.dncheck(g) and g:GetClassCount(Card.GetLocation) == #g
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, s.gselect, false, 1, math.min(ft, 3))
  	if sg then
  		Duel.SpecialSummon(sg, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  
  