name: Odd-Eyes
card_text: Pendulum Scale = 8
  [ Pendulum Effect ]
  Once per turn, if a face-up "Odd-Eyes" Pendulum Monster(s) you control is destroyed by battle or card effect: You can destroy 1 card in your Pendulum Zone, and if you do, place 1 face-up "Odd-Eyes" Pendulum Monster in your Extra Deck in your Pendulum Zone, except "Odd-Eyes Mirage Dragon".
  ----------------------------------------
  [ Monster Effect ]
  While an "Odd-Eyes" card is in your Pendulum Zone (Quick Effect): You can target 1 "Odd-Eyes" monster you control; the first time it would be destroyed by battle or card effect this turn, it is not destroyed. You can only use this effect of "Odd-Eyes Mirage Dragon" once per turn.
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)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(s.indcon)
  	e1:SetTarget(s.indtg)
  	e1:SetOperation(s.indop)
  	c:RegisterEffect(e1)
  	--pendulum set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.pencon)
  	e2:SetTarget(s.pentg)
  	e2:SetOperation(s.penop)
  	c:RegisterEffect(e2)
  end
  function s.indfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(Card.IsSetCard, tp, LOCATION_PZONE, 0, 1, nil, 0x99)
  end
  function s.indtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.indfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.indfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.indfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.indop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCountLimit(1)
  		e1:SetValue(s.valcon)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.valcon(e, re, r, rp)
  	return bit.band(r, REASON_BATTLE + REASON_EFFECT) ~= 0
  end
  function s.cfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_PENDULUM)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousPosition(POS_FACEUP)
  		and c:IsPreviousControler(tp)
  end
  function s.penfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and c:IsFaceup() and not c:IsCode(id) and not c:IsForbidden()
  end
  function s.pencon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.pentg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_PZONE, 0) > 0 and Duel.IsExistingMatchingCard(s.penfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.penop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0):Select(tp, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		if Duel.Destroy(g, REASON_EFFECT) == 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local sg = Duel.SelectMatchingCard(tp, s.penfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  		local tc = sg:GetFirst()
  		if tc then
  			Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  		end
  	end
  end
  
  
source_text: Odd-Eyes
  Pendulum Scale = 8
  [ Pendulum Effect ]
  Once per turn, if a face-up "Odd-Eyes" Pendulum Monster(s) you control is destroyed by battle or card effect: You can destroy 1 card in your Pendulum Zone, and if you do, place 1 face-up "Odd-Eyes" Pendulum Monster in your Extra Deck in your Pendulum Zone, except "Odd-Eyes Mirage Dragon".
  ----------------------------------------
  [ Monster Effect ]
  While an "Odd-Eyes" card is in your Pendulum Zone (Quick Effect): You can target 1 "Odd-Eyes" monster you control; the first time it would be destroyed by battle or card effect this turn, it is not destroyed. You can only use this effect of "Odd-Eyes Mirage Dragon" once per turn.
target_text: -- Odd-Eyes
  local SETCARD_ID_0 = 0x99 --Odd-Eyes
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(s.indcon)
  	e1:SetTarget(s.indtg)
  	e1:SetOperation(s.indop)
  	c:RegisterEffect(e1)
  	--pendulum set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.pencon)
  	e2:SetTarget(s.pentg)
  	e2:SetOperation(s.penop)
  	c:RegisterEffect(e2)
  end
  function s.indfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(Card.IsSetCard, tp, LOCATION_PZONE, 0, 1, nil, 0x99)
  end
  function s.indtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.indfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.indfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.indfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.indop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCountLimit(1)
  		e1:SetValue(s.valcon)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.valcon(e, re, r, rp)
  	return bit.band(r, REASON_BATTLE + REASON_EFFECT) ~= 0
  end
  function s.cfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_PENDULUM)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousPosition(POS_FACEUP)
  		and c:IsPreviousControler(tp)
  end
  function s.penfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and c:IsFaceup() and not c:IsCode(id) and not c:IsForbidden()
  end
  function s.pencon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.pentg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_PZONE, 0) > 0 and Duel.IsExistingMatchingCard(s.penfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.penop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0):Select(tp, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		if Duel.Destroy(g, REASON_EFFECT) == 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local sg = Duel.SelectMatchingCard(tp, s.penfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  		local tc = sg:GetFirst()
  		if tc then
  			Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  		end
  	end
  end
  
  