name: Zoodiac
card_text: You can target 1 face-up card you control; destroy it, and if you do, Special Summon 1 "Zoodiac" monster from your Deck. You can only use this effect of "Zoodiac Barrage" once per turn. If this card is destroyed by a card effect and sent to the GY: You can target 1 "Zoodiac" Xyz Monster you control; attach this card from your GY to that Xyz Monster as Xyz Material.
external_ids: local SETCARD_ID_0 = 0xf1 --Zoodiac
  
lua: local SETCARD_ID_0 = 0xf1 --Zoodiac
  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)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCondition(s.matcon)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(e:GetLabel()) and chkc:IsControler(tp) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		if ft < -1 then
  			return false
  		end
  		local loc = LOCATION_ONFIELD
  		if ft == 0 then
  			loc = LOCATION_MZONE
  		end
  		e:SetLabel(loc)
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, loc, 0, 1, nil) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, Card.IsFaceup, tp, e:GetLabel(), 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Destroy(tc, REASON_EFFECT) ~= 0 then
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.matcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(e:GetHandler():GetReason(), 0x41) == 0x41
  end
  function s.matfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.matfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.matfilter, tp, LOCATION_MZONE, 0, 1, nil) and e:GetHandler():IsCanOverlay()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.matfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and c:IsCanOverlay() and tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  		Duel.Overlay(tc, Group.FromCards(c))
  	end
  end
  
  
source_text: Zoodiac
  You can target 1 face-up card you control; destroy it, and if you do, Special Summon 1 "Zoodiac" monster from your Deck. You can only use this effect of "Zoodiac Barrage" once per turn. If this card is destroyed by a card effect and sent to the GY: You can target 1 "Zoodiac" Xyz Monster you control; attach this card from your GY to that Xyz Monster as Xyz Material.
target_text: -- Zoodiac
  local SETCARD_ID_0 = 0xf1 --Zoodiac
  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)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCondition(s.matcon)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(e:GetLabel()) and chkc:IsControler(tp) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		if ft < -1 then
  			return false
  		end
  		local loc = LOCATION_ONFIELD
  		if ft == 0 then
  			loc = LOCATION_MZONE
  		end
  		e:SetLabel(loc)
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, loc, 0, 1, nil) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, Card.IsFaceup, tp, e:GetLabel(), 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Destroy(tc, REASON_EFFECT) ~= 0 then
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.matcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(e:GetHandler():GetReason(), 0x41) == 0x41
  end
  function s.matfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.matfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.matfilter, tp, LOCATION_MZONE, 0, 1, nil) and e:GetHandler():IsCanOverlay()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.matfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and c:IsCanOverlay() and tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  		Duel.Overlay(tc, Group.FromCards(c))
  	end
  end
  
  