name: Ancient
card_text: 1 Tuner + 1+ non-Tuner monsters
  During your Main Phase: You can Special Summon 1 Level 4 or lower monster from your hand. You cannot conduct your Battle Phase the turn you activate this effect. During your Main Phase: You can destroy as many cards in the Field Zones as possible (min. 1), and if you do, gain 1000 LP, then you can add 1 Field Spell with a different name than the destroyed card(s), from your Deck to your hand. You can only use each effect of "Ancient Fairy Dragon" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.sumcon)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_RECOVER + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  function s.sumcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1
  end
  function s.sumfilter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.sumfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, LOCATION_HAND)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_BP)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.sumop(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 g = Duel.SelectMatchingCard(tp, s.sumfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetFieldGroup(tp, LOCATION_FZONE, LOCATION_FZONE)
  	if chk == 0 then
  		return g:GetCount() > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, 1000)
  end
  function s.ffilter(c, g)
  	return c:IsType(TYPE_FIELD) and c:IsAbleToHand() and not g:IsExists(Card.IsCode, 1, nil, c:GetCode())
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(tp, LOCATION_FZONE, LOCATION_FZONE)
  	if g:GetCount() > 0 then
  		Duel.Destroy(g, REASON_EFFECT)
  		local og = Duel.GetOperatedGroup()
  		if og:GetCount() > 0 then
  			Duel.Recover(tp, 1000, REASON_EFFECT)
  			local fg = Duel.GetMatchingGroup(s.ffilter, tp, LOCATION_DECK, 0, nil, og)
  			if fg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  				Duel.BreakEffect()
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  				local sg = fg:Select(tp, 1, 1, nil)
  				Duel.SendtoHand(sg, nil, REASON_EFFECT)
  				Duel.ConfirmCards(1 - tp, sg)
  			end
  		end
  	end
  end
  
  
source_text: Ancient
  1 Tuner + 1+ non-Tuner monsters
  During your Main Phase: You can Special Summon 1 Level 4 or lower monster from your hand. You cannot conduct your Battle Phase the turn you activate this effect. During your Main Phase: You can destroy as many cards in the Field Zones as possible (min. 1), and if you do, gain 1000 LP, then you can add 1 Field Spell with a different name than the destroyed card(s), from your Deck to your hand. You can only use each effect of "Ancient Fairy Dragon" once per turn.
target_text: -- Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.sumcon)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_RECOVER + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  function s.sumcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1
  end
  function s.sumfilter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.sumfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, LOCATION_HAND)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_BP)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.sumop(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 g = Duel.SelectMatchingCard(tp, s.sumfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetFieldGroup(tp, LOCATION_FZONE, LOCATION_FZONE)
  	if chk == 0 then
  		return g:GetCount() > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, 1000)
  end
  function s.ffilter(c, g)
  	return c:IsType(TYPE_FIELD) and c:IsAbleToHand() and not g:IsExists(Card.IsCode, 1, nil, c:GetCode())
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(tp, LOCATION_FZONE, LOCATION_FZONE)
  	if g:GetCount() > 0 then
  		Duel.Destroy(g, REASON_EFFECT)
  		local og = Duel.GetOperatedGroup()
  		if og:GetCount() > 0 then
  			Duel.Recover(tp, 1000, REASON_EFFECT)
  			local fg = Duel.GetMatchingGroup(s.ffilter, tp, LOCATION_DECK, 0, nil, og)
  			if fg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  				Duel.BreakEffect()
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  				local sg = fg:Select(tp, 1, 1, nil)
  				Duel.SendtoHand(sg, nil, REASON_EFFECT)
  				Duel.ConfirmCards(1 - tp, sg)
  			end
  		end
  	end
  end
  
  