name: Spiral
card_text: Activate 1 of these effects;
  ● If you control an "Odd-Eyes" card: Target 1 card on the field; destroy it.
  ● Add to your hand, 1 Level 7 "Odd-Eyes" monster from your Deck, or 1 face-up Level 7 "Odd-Eyes" Pendulum Monster from your Extra Deck.
external_ids: local SETCARD_ID_0 = 0x99 --Odd-Eyes
  
lua: local SETCARD_ID_0 = 0x99 --Odd-Eyes
  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:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  end
  function s.desfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevel(7) and (c:IsFaceup() or not c:IsLocation(LOCATION_EXTRA)) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField()
  	end
  	local b1 = Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_ONFIELD, 0, 1, nil) and Duel.IsExistingTarget(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	local b2 = Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	if op == 0 then
  		e:SetCategory(CATEGORY_DESTROY)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectTarget(tp, nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, e:GetHandler())
  		e:SetOperation(s.desop)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	else
  		e:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  		e:SetProperty(0)
  		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, nil)
  		e:SetOperation(s.thop)
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_EXTRA)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Spiral
  Activate 1 of these effects;
  ● If you control an "Odd-Eyes" card: Target 1 card on the field; destroy it.
  ● Add to your hand, 1 Level 7 "Odd-Eyes" monster from your Deck, or 1 face-up Level 7 "Odd-Eyes" Pendulum Monster from your Extra Deck.
target_text: -- Spiral
  local SETCARD_ID_0 = 0x99 --Odd-Eyes
  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:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  end
  function s.desfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevel(7) and (c:IsFaceup() or not c:IsLocation(LOCATION_EXTRA)) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField()
  	end
  	local b1 = Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_ONFIELD, 0, 1, nil) and Duel.IsExistingTarget(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	local b2 = Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	if op == 0 then
  		e:SetCategory(CATEGORY_DESTROY)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectTarget(tp, nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, e:GetHandler())
  		e:SetOperation(s.desop)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	else
  		e:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  		e:SetProperty(0)
  		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, nil)
  		e:SetOperation(s.thop)
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_EXTRA)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  