name: Insect
card_text: Gains 200 ATK for each Insect monster on the field. Cannot declare an attack unless you Tribute 1 monster. Once per turn, during the End Phase, if this card destroyed an opponent's monster by battle this turn: Special Summon 1 "Insect Monster Token" (Insect/EARTH/Level 1/ATK 100/DEF 100) in Attack Position.
external_ids: local CARD_ID_0 = 91512836 --Insect Monster Token
  
lua: local CARD_ID_0 = 91512836 --Insect Monster Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--attack cost
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_ATTACK_COST)
  	e1:SetCost(s.atcost)
  	e1:SetOperation(s.atop)
  	c:RegisterEffect(e1)
  	--atkup
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetValue(s.value)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetCode(EVENT_BATTLE_DESTROYING)
  	e3:SetOperation(s.regop)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.atcost(e, c, tp)
  	return Duel.CheckReleaseGroupEx(tp, nil, 1, REASON_ACTION, false, e:GetHandler())
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.SelectReleaseGroupEx(tp, nil, 1, 1, REASON_ACTION, false, e:GetHandler())
  	Duel.Release(g, REASON_ACTION)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT)
  end
  function s.value(e, c)
  	return Duel.GetMatchingGroupCount(s.filter, 0, LOCATION_MZONE, LOCATION_MZONE, nil) * 200
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH, POS_FACEUP_ATTACK) then
  		return
  	end
  	local token = Duel.CreateToken(tp, id + 1)
  	Duel.SpecialSummon(token, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  end
  
  
source_text: Insect
  Gains 200 ATK for each Insect monster on the field. Cannot declare an attack unless you Tribute 1 monster. Once per turn, during the End Phase, if this card destroyed an opponent's monster by battle this turn: Special Summon 1 "Insect Monster Token" (Insect/EARTH/Level 1/ATK 100/DEF 100) in Attack Position.
target_text: -- Insect
  local CARD_ID_0 = 91512836 --Insect Monster Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--attack cost
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_ATTACK_COST)
  	e1:SetCost(s.atcost)
  	e1:SetOperation(s.atop)
  	c:RegisterEffect(e1)
  	--atkup
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetValue(s.value)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetCode(EVENT_BATTLE_DESTROYING)
  	e3:SetOperation(s.regop)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.atcost(e, c, tp)
  	return Duel.CheckReleaseGroupEx(tp, nil, 1, REASON_ACTION, false, e:GetHandler())
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.SelectReleaseGroupEx(tp, nil, 1, 1, REASON_ACTION, false, e:GetHandler())
  	Duel.Release(g, REASON_ACTION)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT)
  end
  function s.value(e, c)
  	return Duel.GetMatchingGroupCount(s.filter, 0, LOCATION_MZONE, LOCATION_MZONE, nil) * 200
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH, POS_FACEUP_ATTACK) then
  		return
  	end
  	local token = Duel.CreateToken(tp, id + 1)
  	Duel.SpecialSummon(token, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  end
  
  