Ninjitsu
Activate this card by targeting 1 "Ninja" monster or 1 face-down Defense Position monster on the field; Tribute it, and if you do, Special Summon 1 "Ninja" monster from your Deck. When this card leaves the field, send that monster to the GY. You can target 1 "Ninjitsu Art" Continuous Spell/Trap in your Spell & Trap Zone; return it to the hand. You can only use 1 "Ninjitsu Art of Dancing Leaves" effect per turn, and only once that turn.
local SETCARD_ID_0 = 0x2b --Ninja
local SETCARD_ID_1 = 0x61 --Ninjitsu

local SETCARD_ID_0 = 0x2b --Ninja
local SETCARD_ID_1 = 0x61 --Ninjitsu
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_RELEASE + CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
	e1:SetTarget(s.target)
	e1:SetOperation(s.operation)
	c:RegisterEffect(e1)
	--leave
	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)
	--tohand
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 1))
	e3:SetCategory(CATEGORY_TOHAND)
	e3:SetType(EFFECT_TYPE_QUICK_O)
	e3:SetCode(EVENT_FREE_CHAIN)
	e3:SetRange(LOCATION_SZONE)
	e3:SetCountLimit(1, id)
	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e3:SetCondition(s.thcon)
	e3:SetTarget(s.thtg)
	e3:SetOperation(s.thop)
	c:RegisterEffect(e3)
end
function s.cfilter(c, tp)
	return (c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) or c:IsPosition(POS_FACEDOWN_DEFENSE)) and c:IsReleasableByEffect() and Duel.GetMZoneCount(tp, c) > 0
end
function s.spfilter(c, e, tp)
	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_MZONE) and s.cfilter(chkc, tp)
	end
	if chk == 0 then
		return Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, tp) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
	local g = Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, tp)
	Duel.SetOperationInfo(0, CATEGORY_RELEASE, g, 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local tc = Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) and Duel.Release(tc, REASON_EFFECT) > 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local sc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp):GetFirst()
		if not sc then
			return
		end
		if Duel.SpecialSummonStep(sc, 0, tp, tp, false, false, POS_FACEUP) then
			c:SetCardTarget(sc)
		end
		Duel.SpecialSummonComplete()
	end
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local tc = e:GetHandler():GetFirstCardTarget()
	if tc and tc:IsLocation(LOCATION_MZONE) then
		Duel.SendtoGrave(tc, REASON_EFFECT)
	end
end
function s.thcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED)
end
function s.thfilter(c)
	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_CONTINUOUS) and c:GetSequence() < 5 and c:IsAbleToHand()
end
function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_SZONE) and chkc:IsControler(tp) and s.thfilter(chkc)
	end
	if chk == 0 then
		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_SZONE, 0, 1, nil)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_SZONE, 0, 1, 1, nil)
	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
end
function s.thop(e, tp, eg, ep, ev, re, r, rp)
	local tc = Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) then
		Duel.SendtoHand(tc, nil, REASON_EFFECT)
	end
end


Ninjitsu
Activate this card by targeting 1 "Ninja" monster or 1 face-down Defense Position monster on the field; Tribute it, and if you do, Special Summon 1 "Ninja" monster from your Deck. When this card leaves the field, send that monster to the GY. You can target 1 "Ninjitsu Art" Continuous Spell/Trap in your Spell & Trap Zone; return it to the hand. You can only use 1 "Ninjitsu Art of Dancing Leaves" effect per turn, and only once that turn.
-- Ninjitsu
local SETCARD_ID_0 = 0x2b --Ninja
local SETCARD_ID_1 = 0x61 --Ninjitsu
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_RELEASE + CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
	e1:SetTarget(s.target)
	e1:SetOperation(s.operation)
	c:RegisterEffect(e1)
	--leave
	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)
	--tohand
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 1))
	e3:SetCategory(CATEGORY_TOHAND)
	e3:SetType(EFFECT_TYPE_QUICK_O)
	e3:SetCode(EVENT_FREE_CHAIN)
	e3:SetRange(LOCATION_SZONE)
	e3:SetCountLimit(1, id)
	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e3:SetCondition(s.thcon)
	e3:SetTarget(s.thtg)
	e3:SetOperation(s.thop)
	c:RegisterEffect(e3)
end
function s.cfilter(c, tp)
	return (c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) or c:IsPosition(POS_FACEDOWN_DEFENSE)) and c:IsReleasableByEffect() and Duel.GetMZoneCount(tp, c) > 0
end
function s.spfilter(c, e, tp)
	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_MZONE) and s.cfilter(chkc, tp)
	end
	if chk == 0 then
		return Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, tp) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
	local g = Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, tp)
	Duel.SetOperationInfo(0, CATEGORY_RELEASE, g, 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local tc = Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) and Duel.Release(tc, REASON_EFFECT) > 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local sc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp):GetFirst()
		if not sc then
			return
		end
		if Duel.SpecialSummonStep(sc, 0, tp, tp, false, false, POS_FACEUP) then
			c:SetCardTarget(sc)
		end
		Duel.SpecialSummonComplete()
	end
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local tc = e:GetHandler():GetFirstCardTarget()
	if tc and tc:IsLocation(LOCATION_MZONE) then
		Duel.SendtoGrave(tc, REASON_EFFECT)
	end
end
function s.thcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED)
end
function s.thfilter(c)
	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_CONTINUOUS) and c:GetSequence() < 5 and c:IsAbleToHand()
end
function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_SZONE) and chkc:IsControler(tp) and s.thfilter(chkc)
	end
	if chk == 0 then
		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_SZONE, 0, 1, nil)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_SZONE, 0, 1, 1, nil)
	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
end
function s.thop(e, tp, eg, ep, ev, re, r, rp)
	local tc = Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) then
		Duel.SendtoHand(tc, nil, REASON_EFFECT)
	end
end

