name: Upstart
card_text: Once per turn: You can send 1 Trap from your hand to the GY; Special Summon 1 Level 4 or lower "Ninja" monster from your Deck in face-up Defense Position or face-down Defense Position.
external_ids: local SETCARD_ID_0 = 0x2b --Ninja
  
lua: local SETCARD_ID_0 = 0x2b --Ninja
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_TRAP) and c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local cg = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	Duel.SendtoGrave(cg, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_DEFENSE)
  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.filter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.operation(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, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_DEFENSE) ~= 0 and tc:IsFacedown() then
  		Duel.ConfirmCards(1 - tp, tc)
  	end
  end
  
  
source_text: Upstart
  Once per turn: You can send 1 Trap from your hand to the GY; Special Summon 1 Level 4 or lower "Ninja" monster from your Deck in face-up Defense Position or face-down Defense Position.
target_text: -- Upstart
  local SETCARD_ID_0 = 0x2b --Ninja
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_TRAP) and c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local cg = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	Duel.SendtoGrave(cg, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_DEFENSE)
  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.filter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.operation(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, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_DEFENSE) ~= 0 and tc:IsFacedown() then
  		Duel.ConfirmCards(1 - tp, tc)
  	end
  end
  
  