name: Shinobi
card_text: 2 monsters with different names
  While this card points to a monster(s), your opponent's monsters cannot target this card for attacks. If a monster(s) this card points to is destroyed by battle or card effect: You can Special Summon 1 Level 4 or lower Insect monster from your hand or GY, but banish it when it leaves the field. You can only use this effect of "Shinobi Insect Hagakuremino" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--cannot be target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.tgcon)
  	e1:SetValue(aux.imval1)
  	c:RegisterEffect(e1)
  	--SpecialSummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.tgfilter(c)
  	return c:IsType(TYPE_MONSTER)
  end
  function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetLinkedGroup():IsExists(s.tgfilter, 1, nil)
  end
  function s.cfilter(c, tp, zone)
  	local seq = c:GetPreviousSequence()
  	if c:IsPreviousControler(1 - tp) then
  		seq = seq + 16
  	end
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT) and c:IsPreviousLocation(LOCATION_MZONE) and bit.extract(zone, seq) ~= 0
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp, e:GetHandler():GetLinkedZone())
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_INSECT) and c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(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_HAND + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc and Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		tc:RegisterEffect(e1, true)
  	end
  	Duel.SpecialSummonComplete()
  end
  
  
source_text: Shinobi
  2 monsters with different names
  While this card points to a monster(s), your opponent's monsters cannot target this card for attacks. If a monster(s) this card points to is destroyed by battle or card effect: You can Special Summon 1 Level 4 or lower Insect monster from your hand or GY, but banish it when it leaves the field. You can only use this effect of "Shinobi Insect Hagakuremino" once per turn.
target_text: -- Shinobi
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--cannot be target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.tgcon)
  	e1:SetValue(aux.imval1)
  	c:RegisterEffect(e1)
  	--SpecialSummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.tgfilter(c)
  	return c:IsType(TYPE_MONSTER)
  end
  function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetLinkedGroup():IsExists(s.tgfilter, 1, nil)
  end
  function s.cfilter(c, tp, zone)
  	local seq = c:GetPreviousSequence()
  	if c:IsPreviousControler(1 - tp) then
  		seq = seq + 16
  	end
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT) and c:IsPreviousLocation(LOCATION_MZONE) and bit.extract(zone, seq) ~= 0
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp, e:GetHandler():GetLinkedZone())
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_INSECT) and c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(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_HAND + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc and Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		tc:RegisterEffect(e1, true)
  	end
  	Duel.SpecialSummonComplete()
  end
  
  