Armed
Special Summon 1 Insect monster with 1000 or less ATK from your hand or Deck, then if you Special Summoned from the Deck, send 1 monster you control to the GY, also you cannot Special Summon for the rest of this turn after this card resolves, except Insect monsters. If a face-up Insect Synchro Monster(s) you control is destroyed by battle or card effect, while this card is in your GY: You can banish this card; add 1 "Summoning Swarm" from your Deck to your hand. You can only activate 1 "Armed Rebeellion" per turn.
local CARD_ID_0 = 52838896 --Summoning Swarm

local CARD_ID_0 = 52838896 --Summoning Swarm
local s, id, o = GetID()
function s.initial_effect(c)
	aux.AddCodeList(c, CARD_ID_0)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOGRAVE)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--to hand
	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 1))
	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
	e2:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_FIELD)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
	e2:SetCode(EVENT_DESTROYED)
	e2:SetRange(LOCATION_GRAVE)
	e2:SetLabelObject(e0)
	e2:SetCondition(s.thcon)
	e2:SetCost(aux.bfgcost)
	e2:SetTarget(s.thtg)
	e2:SetOperation(s.thop)
	c:RegisterEffect(e2)
end
function s.spfilter(c, e, tp)
	return c:IsRace(RACE_INSECT) and c:IsAttackBelow(1000) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_HAND)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	if Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, 1, nil, e, tp)
		local tc = g:GetFirst()
		if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 and tc:IsSummonLocation(LOCATION_DECK) then
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
			local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToGrave, tp, LOCATION_MZONE, 0, 1, 1, nil)
			local gc = sg:GetFirst()
			if gc then
				Duel.HintSelection(sg)
				Duel.SendtoGrave(gc, REASON_EFFECT)
			end
		end
	end
	local e1 = Effect.CreateEffect(e:GetHandler())
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e1:SetTargetRange(1, 0)
	e1:SetTarget(s.splimit)
	e1:SetReset(RESET_PHASE + PHASE_END)
	Duel.RegisterEffect(e1, tp)
end
function s.splimit(e, c)
	return not c:IsRace(RACE_INSECT)
end
function s.cfilter(c, se)
	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
		and c:IsType(TYPE_SYNCHRO)
		and bit.band(c:GetPreviousRaceOnField(), RACE_INSECT) ~= 0
		and c:IsPreviousPosition(POS_FACEUP)
		and c:IsPreviousLocation(LOCATION_MZONE)
		and (se == nil or c:GetReasonEffect() ~= se)
end
function s.thcon(e, tp, eg, ep, ev, re, r, rp)
	local se = e:GetLabelObject():GetLabelObject()
	return eg:IsExists(s.cfilter, 1, e:GetHandler(), se)
end
function s.thfilter(c)
	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
end
function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
	end
	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
end
function s.thop(e, tp, eg, ep, ev, re, r, rp)
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
	if g:GetCount() > 0 then
		Duel.SendtoHand(g, nil, REASON_EFFECT)
		Duel.ConfirmCards(1 - tp, g)
	end
end


Armed
Special Summon 1 Insect monster with 1000 or less ATK from your hand or Deck, then if you Special Summoned from the Deck, send 1 monster you control to the GY, also you cannot Special Summon for the rest of this turn after this card resolves, except Insect monsters. If a face-up Insect Synchro Monster(s) you control is destroyed by battle or card effect, while this card is in your GY: You can banish this card; add 1 "Summoning Swarm" from your Deck to your hand. You can only activate 1 "Armed Rebeellion" per turn.
-- Armed
local CARD_ID_0 = 52838896 --Summoning Swarm
local s, id, o = GetID()
function s.initial_effect(c)
	aux.AddCodeList(c, CARD_ID_0)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOGRAVE)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--to hand
	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 1))
	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
	e2:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_FIELD)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
	e2:SetCode(EVENT_DESTROYED)
	e2:SetRange(LOCATION_GRAVE)
	e2:SetLabelObject(e0)
	e2:SetCondition(s.thcon)
	e2:SetCost(aux.bfgcost)
	e2:SetTarget(s.thtg)
	e2:SetOperation(s.thop)
	c:RegisterEffect(e2)
end
function s.spfilter(c, e, tp)
	return c:IsRace(RACE_INSECT) and c:IsAttackBelow(1000) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_HAND)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	if Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK + LOCATION_HAND, 0, 1, 1, nil, e, tp)
		local tc = g:GetFirst()
		if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 and tc:IsSummonLocation(LOCATION_DECK) then
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
			local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToGrave, tp, LOCATION_MZONE, 0, 1, 1, nil)
			local gc = sg:GetFirst()
			if gc then
				Duel.HintSelection(sg)
				Duel.SendtoGrave(gc, REASON_EFFECT)
			end
		end
	end
	local e1 = Effect.CreateEffect(e:GetHandler())
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e1:SetTargetRange(1, 0)
	e1:SetTarget(s.splimit)
	e1:SetReset(RESET_PHASE + PHASE_END)
	Duel.RegisterEffect(e1, tp)
end
function s.splimit(e, c)
	return not c:IsRace(RACE_INSECT)
end
function s.cfilter(c, se)
	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
		and c:IsType(TYPE_SYNCHRO)
		and bit.band(c:GetPreviousRaceOnField(), RACE_INSECT) ~= 0
		and c:IsPreviousPosition(POS_FACEUP)
		and c:IsPreviousLocation(LOCATION_MZONE)
		and (se == nil or c:GetReasonEffect() ~= se)
end
function s.thcon(e, tp, eg, ep, ev, re, r, rp)
	local se = e:GetLabelObject():GetLabelObject()
	return eg:IsExists(s.cfilter, 1, e:GetHandler(), se)
end
function s.thfilter(c)
	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
end
function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
	end
	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
end
function s.thop(e, tp, eg, ep, ev, re, r, rp)
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
	if g:GetCount() > 0 then
		Duel.SendtoHand(g, nil, REASON_EFFECT)
		Duel.ConfirmCards(1 - tp, g)
	end
end

