name: U.A.
card_text: You can Special Summon this card (from your hand) by returning 1 "U.A." monster you control to the hand, except "U.A. Libero Spiker". You can only Special Summon "U.A. Libero Spiker" once per turn this way. During your opponent's Main Phase (Quick Effect): You can shuffle 1 Level 5 or higher "U.A." monster from your hand into the Deck, and if you do, Special Summon 1 "U.A." monster from your Deck with a different name, then return this card to the hand. You can only use this effect of "U.A. Libero Spiker" once per turn.
external_ids: local SETCARD_ID_0 = 0xb2 --U.A.
  
lua: local SETCARD_ID_0 = 0xb2 --U.A.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--special summon from deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToHandAsCost() and Duel.GetMZoneCount(tp, c) > 0
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_MZONE, 0, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local tc = g:SelectUnselect(nil, tp, false, true, 1, 1)
  	if tc then
  		e:SetLabelObject(tc)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoHand(g, nil, REASON_SPSUMMON)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp and (Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2)
  end
  function s.spfilter1(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelAbove(5) and c:IsAbleToDeck() and Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_DECK, 0, 1, nil, e, tp, c)
  end
  function s.spfilter2(c, e, tp, tc)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(tc:GetCode()) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsAbleToHand() and Duel.IsExistingMatchingCard(s.spfilter1, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g1 = Duel.GetMatchingGroup(s.spfilter1, tp, LOCATION_HAND, 0, nil, e, tp)
  	if g1:GetCount() <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local tg1 = g1:Select(tp, 1, 1, nil)
  	Duel.ConfirmCards(1 - tp, tg1)
  	if Duel.SendtoDeck(tg1, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g2 = Duel.SelectMatchingCard(tp, s.spfilter2, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, tg1:GetFirst())
  		if Duel.SpecialSummon(g2, 0, tp, tp, false, false, POS_FACEUP) and e:GetHandler():IsRelateToEffect(e) then
  			Duel.BreakEffect()
  			Duel.SendtoHand(e:GetHandler(), nil, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: U.A.
  You can Special Summon this card (from your hand) by returning 1 "U.A." monster you control to the hand, except "U.A. Libero Spiker". You can only Special Summon "U.A. Libero Spiker" once per turn this way. During your opponent's Main Phase (Quick Effect): You can shuffle 1 Level 5 or higher "U.A." monster from your hand into the Deck, and if you do, Special Summon 1 "U.A." monster from your Deck with a different name, then return this card to the hand. You can only use this effect of "U.A. Libero Spiker" once per turn.
target_text: -- U.A.
  local SETCARD_ID_0 = 0xb2 --U.A.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--special summon from deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToHandAsCost() and Duel.GetMZoneCount(tp, c) > 0
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_MZONE, 0, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local tc = g:SelectUnselect(nil, tp, false, true, 1, 1)
  	if tc then
  		e:SetLabelObject(tc)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoHand(g, nil, REASON_SPSUMMON)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp and (Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2)
  end
  function s.spfilter1(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelAbove(5) and c:IsAbleToDeck() and Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_DECK, 0, 1, nil, e, tp, c)
  end
  function s.spfilter2(c, e, tp, tc)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(tc:GetCode()) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsAbleToHand() and Duel.IsExistingMatchingCard(s.spfilter1, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g1 = Duel.GetMatchingGroup(s.spfilter1, tp, LOCATION_HAND, 0, nil, e, tp)
  	if g1:GetCount() <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local tg1 = g1:Select(tp, 1, 1, nil)
  	Duel.ConfirmCards(1 - tp, tg1)
  	if Duel.SendtoDeck(tg1, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g2 = Duel.SelectMatchingCard(tp, s.spfilter2, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, tg1:GetFirst())
  		if Duel.SpecialSummon(g2, 0, tp, tp, false, false, POS_FACEUP) and e:GetHandler():IsRelateToEffect(e) then
  			Duel.BreakEffect()
  			Duel.SendtoHand(e:GetHandler(), nil, REASON_EFFECT)
  		end
  	end
  end
  
  