Ninjitsu
Activate this card by Tributing 1 "Ninja" monster; Special Summon any number of "Ninja" monsters from your Deck, in face-up Attack Position and/or face-down Defense Position, with combined Levels less than or equal to the Level of the Tributed monster. When this card leaves the field, destroy those monsters.
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local SETCARD_ID_0 = 0x2b --Ninja

local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local SETCARD_ID_0 = 0x2b --Ninja
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
	e1:SetTarget(s.target)
	e1:SetOperation(s.operation)
	c:RegisterEffect(e1)
	--Destroy
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
	e2:SetCode(EVENT_LEAVE_FIELD)
	e2:SetOperation(s.desop)
	c:RegisterEffect(e2)
end
function s.cfilter(c, e, tp, ft)
	local lv = c:GetLevel()
	return lv > 0
		and c:IsSetCard(SETCARD_ID_0)
		and (ft > 0 or (c:IsControler(tp) and c:GetSequence() < 5))
		and (c:IsControler(tp) or c:IsFaceup())
		and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, lv, e, tp)
end
function s.spfilter(c, lv, e, tp)
	return c:IsLevelBelow(lv) and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if chk == 0 then
		return ft > -1 and Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, e, tp, ft)
	end
	local rg = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, e, tp, ft)
	e:SetLabel(rg:GetFirst():GetLevel())
	Duel.Release(rg, REASON_COST)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
end
function s.gselect(g, slv)
	return g:GetSum(Card.GetLevel) <= slv
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if ft <= 0 then
		return
	end
	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
		ft = 1
	end
	local c = e:GetHandler()
	local slv = e:GetLabel()
	local sg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, slv, e, tp)
	if sg:GetCount() == 0 then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local tg = sg:SelectSubGroup(tp, s.gselect, false, 1, ft, slv)
	local cg = Group.CreateGroup()
	for tc in aux.Next(tg) do
		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
		if tc:IsFacedown() then
			cg:AddCard(tc)
		end
		c:SetCardTarget(tc)
	end
	Duel.SpecialSummonComplete()
	Duel.ConfirmCards(1 - tp, cg)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local g = e:GetHandler():GetCardTarget():Filter(Card.IsLocation, nil, LOCATION_MZONE)
	Duel.Destroy(g, REASON_EFFECT)
end


Ninjitsu
Activate this card by Tributing 1 "Ninja" monster; Special Summon any number of "Ninja" monsters from your Deck, in face-up Attack Position and/or face-down Defense Position, with combined Levels less than or equal to the Level of the Tributed monster. When this card leaves the field, destroy those monsters.
-- Ninjitsu
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local SETCARD_ID_0 = 0x2b --Ninja
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
	e1:SetTarget(s.target)
	e1:SetOperation(s.operation)
	c:RegisterEffect(e1)
	--Destroy
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
	e2:SetCode(EVENT_LEAVE_FIELD)
	e2:SetOperation(s.desop)
	c:RegisterEffect(e2)
end
function s.cfilter(c, e, tp, ft)
	local lv = c:GetLevel()
	return lv > 0
		and c:IsSetCard(SETCARD_ID_0)
		and (ft > 0 or (c:IsControler(tp) and c:GetSequence() < 5))
		and (c:IsControler(tp) or c:IsFaceup())
		and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, lv, e, tp)
end
function s.spfilter(c, lv, e, tp)
	return c:IsLevelBelow(lv) and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if chk == 0 then
		return ft > -1 and Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, e, tp, ft)
	end
	local rg = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, e, tp, ft)
	e:SetLabel(rg:GetFirst():GetLevel())
	Duel.Release(rg, REASON_COST)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
end
function s.gselect(g, slv)
	return g:GetSum(Card.GetLevel) <= slv
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if ft <= 0 then
		return
	end
	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
		ft = 1
	end
	local c = e:GetHandler()
	local slv = e:GetLabel()
	local sg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, slv, e, tp)
	if sg:GetCount() == 0 then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local tg = sg:SelectSubGroup(tp, s.gselect, false, 1, ft, slv)
	local cg = Group.CreateGroup()
	for tc in aux.Next(tg) do
		Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
		if tc:IsFacedown() then
			cg:AddCard(tc)
		end
		c:SetCardTarget(tc)
	end
	Duel.SpecialSummonComplete()
	Duel.ConfirmCards(1 - tp, cg)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local g = e:GetHandler():GetCardTarget():Filter(Card.IsLocation, nil, LOCATION_MZONE)
	Duel.Destroy(g, REASON_EFFECT)
end

