name: Beetrooper
card_text: Tribute 1 non-Token Insect monster; Special Summon up to 1 "Beetrooper Token" (Insect/EARTH/Level 3/ATK 1000/DEF 1000) for every 1000 original ATK of that Tributed monster. You can only activate "Beetrooper Squad" once per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 40633085 --Beetrooper Token
  local CARD_ID_2 = 64213018 --Beetrooper Token
  local SETCARD_ID_0 = 0x170 --Beetrooper
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 40633085 --Beetrooper Token
  local CARD_ID_2 = 64213018 --Beetrooper Token
  local SETCARD_ID_0 = 0x170 --Beetrooper
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsType(TYPE_MONSTER) and not c:IsType(TYPE_TOKEN) and c:IsRace(RACE_INSECT) and c:GetBaseAttack() >= 1000 and Duel.GetMZoneCount(tp, c) > 0 and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, tp) and Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_2, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 1000, 1000, 3, RACE_INSECT, ATTRIBUTE_EARTH)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, tp)
  	local atk = g:GetFirst():GetBaseAttack()
  	Duel.Release(g, REASON_COST)
  	e:SetLabel(math.floor(atk / 1000))
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 or not Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_2, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 1000, 1000, 3, RACE_INSECT, ATTRIBUTE_EARTH) then
  		return
  	end
  	local ct = (Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) and 1 or math.min(ft, e:GetLabel())
  	local range = {}
  	for i = 1, ct do
  		table.insert(range, i)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	local n = Duel.AnnounceNumber(tp, table.unpack(range))
  	local sg = Group.CreateGroup()
  	for i = 1, n do
  		local token = Duel.CreateToken(tp, id + 1)
  		sg:AddCard(token)
  	end
  	if #sg <= 0 then
  		return
  	end
  	Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  
source_text: Beetrooper
  Tribute 1 non-Token Insect monster; Special Summon up to 1 "Beetrooper Token" (Insect/EARTH/Level 3/ATK 1000/DEF 1000) for every 1000 original ATK of that Tributed monster. You can only activate "Beetrooper Squad" once per turn.
target_text: -- Beetrooper
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 40633085 --Beetrooper Token
  local CARD_ID_2 = 64213018 --Beetrooper Token
  local SETCARD_ID_0 = 0x170 --Beetrooper
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsType(TYPE_MONSTER) and not c:IsType(TYPE_TOKEN) and c:IsRace(RACE_INSECT) and c:GetBaseAttack() >= 1000 and Duel.GetMZoneCount(tp, c) > 0 and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, tp) and Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_2, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 1000, 1000, 3, RACE_INSECT, ATTRIBUTE_EARTH)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, tp)
  	local atk = g:GetFirst():GetBaseAttack()
  	Duel.Release(g, REASON_COST)
  	e:SetLabel(math.floor(atk / 1000))
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 or not Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_2, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 1000, 1000, 3, RACE_INSECT, ATTRIBUTE_EARTH) then
  		return
  	end
  	local ct = (Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) and 1 or math.min(ft, e:GetLabel())
  	local range = {}
  	for i = 1, ct do
  		table.insert(range, i)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	local n = Duel.AnnounceNumber(tp, table.unpack(range))
  	local sg = Group.CreateGroup()
  	for i = 1, n do
  		local token = Duel.CreateToken(tp, id + 1)
  		sg:AddCard(token)
  	end
  	if #sg <= 0 then
  		return
  	end
  	Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  