name: Tlakalel,
card_text: If this card is Tribute Summoned: You can destroy any number of face-up monsters your opponent controls whose combined ATK is less than or equal to the original ATK of the monster Tributed to Tribute Summon this card.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCondition(s.descon)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_MATERIAL_CHECK)
  	e2:SetValue(s.valcheck)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsSummonType(SUMMON_TYPE_ADVANCE) and c:GetMaterialCount() > 0
  end
  function s.desfilter(c, atk)
  	return c:IsFaceup() and c:IsAttackBelow(atk)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local atk = e:GetLabel()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil, atk)
  	end
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil, atk)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.fselect(g, atk)
  	return g:GetSum(Card.GetAttack) <= atk
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local atk = e:GetLabel()
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil, atk)
  	if g:GetCount() == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local dg = g:SelectSubGroup(tp, s.fselect, false, 1, g:GetCount(), atk)
  	Duel.HintSelection(dg)
  	Duel.Destroy(dg, REASON_EFFECT)
  end
  function s.valcheck(e, c)
  	local atk = 0
  	local g = c:GetMaterial()
  	local tc = g:GetFirst()
  	while tc do
  		atk = atk + math.max(tc:GetTextAttack(), 0)
  		tc = g:GetNext()
  	end
  	e:GetLabelObject():SetLabel(atk)
  end
  
  
source_text: Tlakalel,
  If this card is Tribute Summoned: You can destroy any number of face-up monsters your opponent controls whose combined ATK is less than or equal to the original ATK of the monster Tributed to Tribute Summon this card.
target_text: -- Tlakalel,
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCondition(s.descon)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_MATERIAL_CHECK)
  	e2:SetValue(s.valcheck)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsSummonType(SUMMON_TYPE_ADVANCE) and c:GetMaterialCount() > 0
  end
  function s.desfilter(c, atk)
  	return c:IsFaceup() and c:IsAttackBelow(atk)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local atk = e:GetLabel()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil, atk)
  	end
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil, atk)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.fselect(g, atk)
  	return g:GetSum(Card.GetAttack) <= atk
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local atk = e:GetLabel()
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil, atk)
  	if g:GetCount() == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local dg = g:SelectSubGroup(tp, s.fselect, false, 1, g:GetCount(), atk)
  	Duel.HintSelection(dg)
  	Duel.Destroy(dg, REASON_EFFECT)
  end
  function s.valcheck(e, c)
  	local atk = 0
  	local g = c:GetMaterial()
  	local tc = g:GetFirst()
  	while tc do
  		atk = atk + math.max(tc:GetTextAttack(), 0)
  		tc = g:GetNext()
  	end
  	e:GetLabelObject():SetLabel(atk)
  end
  
  