name: Zaborg
card_text: You can Tribute Summon this card by Tributing 1 Tribute Summoned monster. If this card is Tribute Summoned: Target 1 monster on the field; destroy it, then, if it was a LIGHT monster, both players send as many cards as possible from their Extra Deck to the GY, but not more than the original Level/Rank of that destroyed monster. If this card was Tribute Summoned by Tributing a LIGHT monster, add this additional effect.
  ● You choose the cards your opponent sends to the GY.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--summon with 1 tribute
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SUMMON_PROC)
  	e1:SetCondition(s.otcon)
  	e1:SetOperation(s.otop)
  	e1:SetValue(SUMMON_TYPE_ADVANCE)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_SET_PROC)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_MATERIAL_CHECK)
  	e4:SetValue(s.valcheck)
  	e4:SetLabelObject(e3)
  	c:RegisterEffect(e4)
  end
  function s.otfilter(c)
  	return c:IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.otcon(e, c, minc)
  	if c == nil then
  		return true
  	end
  	local mg = Duel.GetMatchingGroup(s.otfilter, 0, LOCATION_MZONE, LOCATION_MZONE, nil)
  	return c:IsLevelAbove(7) and minc <= 1 and Duel.CheckTribute(c, 1, 1, mg)
  end
  function s.otop(e, tp, eg, ep, ev, re, r, rp, c)
  	local mg = Duel.GetMatchingGroup(s.otfilter, 0, LOCATION_MZONE, LOCATION_MZONE, nil)
  	local sg = Duel.SelectTribute(tp, c, 1, 1, mg)
  	c:SetMaterial(sg)
  	Duel.Release(sg, REASON_SUMMON + REASON_MATERIAL)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE)
  	end
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) then
  		if Duel.Destroy(tc, REASON_EFFECT) == 0 or bit.band(tc:GetPreviousAttributeOnField(), ATTRIBUTE_LIGHT) == 0 then
  			return
  		end
  		local lv = tc:GetOriginalLevel()
  		if tc:IsType(TYPE_XYZ) then
  			lv = tc:GetOriginalRank()
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g1 = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_EXTRA, 0, lv, lv, nil)
  		local tg = Duel.GetFieldGroup(tp, 0, LOCATION_EXTRA)
  		if e:GetLabel() == 1 then
  			Duel.ConfirmCards(tp, tg)
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  			local g2 = tg:Select(tp, lv, lv, nil)
  			g1:Merge(g2)
  		else
  			Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_TOGRAVE)
  			local g2 = tg:Select(1 - tp, lv, lv, nil)
  			g1:Merge(g2)
  		end
  		if g1:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SendtoGrave(g1, REASON_EFFECT)
  		end
  		if e:GetLabel() == 1 then
  			Duel.ShuffleExtra(1 - tp)
  		end
  	end
  end
  function s.valcheck(e, c)
  	local g = c:GetMaterial()
  	if g:IsExists(Card.IsAttribute, 1, nil, ATTRIBUTE_LIGHT) then
  		e:GetLabelObject():SetLabel(1)
  	else
  		e:GetLabelObject():SetLabel(0)
  	end
  end
  
  
source_text: Zaborg
  You can Tribute Summon this card by Tributing 1 Tribute Summoned monster. If this card is Tribute Summoned: Target 1 monster on the field; destroy it, then, if it was a LIGHT monster, both players send as many cards as possible from their Extra Deck to the GY, but not more than the original Level/Rank of that destroyed monster. If this card was Tribute Summoned by Tributing a LIGHT monster, add this additional effect.
  ● You choose the cards your opponent sends to the GY.
target_text: -- Zaborg
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--summon with 1 tribute
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SUMMON_PROC)
  	e1:SetCondition(s.otcon)
  	e1:SetOperation(s.otop)
  	e1:SetValue(SUMMON_TYPE_ADVANCE)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_SET_PROC)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_MATERIAL_CHECK)
  	e4:SetValue(s.valcheck)
  	e4:SetLabelObject(e3)
  	c:RegisterEffect(e4)
  end
  function s.otfilter(c)
  	return c:IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.otcon(e, c, minc)
  	if c == nil then
  		return true
  	end
  	local mg = Duel.GetMatchingGroup(s.otfilter, 0, LOCATION_MZONE, LOCATION_MZONE, nil)
  	return c:IsLevelAbove(7) and minc <= 1 and Duel.CheckTribute(c, 1, 1, mg)
  end
  function s.otop(e, tp, eg, ep, ev, re, r, rp, c)
  	local mg = Duel.GetMatchingGroup(s.otfilter, 0, LOCATION_MZONE, LOCATION_MZONE, nil)
  	local sg = Duel.SelectTribute(tp, c, 1, 1, mg)
  	c:SetMaterial(sg)
  	Duel.Release(sg, REASON_SUMMON + REASON_MATERIAL)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE)
  	end
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) then
  		if Duel.Destroy(tc, REASON_EFFECT) == 0 or bit.band(tc:GetPreviousAttributeOnField(), ATTRIBUTE_LIGHT) == 0 then
  			return
  		end
  		local lv = tc:GetOriginalLevel()
  		if tc:IsType(TYPE_XYZ) then
  			lv = tc:GetOriginalRank()
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g1 = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_EXTRA, 0, lv, lv, nil)
  		local tg = Duel.GetFieldGroup(tp, 0, LOCATION_EXTRA)
  		if e:GetLabel() == 1 then
  			Duel.ConfirmCards(tp, tg)
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  			local g2 = tg:Select(tp, lv, lv, nil)
  			g1:Merge(g2)
  		else
  			Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_TOGRAVE)
  			local g2 = tg:Select(1 - tp, lv, lv, nil)
  			g1:Merge(g2)
  		end
  		if g1:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SendtoGrave(g1, REASON_EFFECT)
  		end
  		if e:GetLabel() == 1 then
  			Duel.ShuffleExtra(1 - tp)
  		end
  	end
  end
  function s.valcheck(e, c)
  	local g = c:GetMaterial()
  	if g:IsExists(Card.IsAttribute, 1, nil, ATTRIBUTE_LIGHT) then
  		e:GetLabelObject():SetLabel(1)
  	else
  		e:GetLabelObject():SetLabel(0)
  	end
  end
  
  