name: Sylvan
card_text: 2 Level 1 monsters
  You can detach 1 Xyz Material from this card; excavate the top card of your Deck, and if it is a Spell/Trap, add it to your hand. Otherwise, send it to the GY. You can send 1 other Plant monster from your hand or face-up from your field to the GY, then target 1 "Sylvan" monster in your GY; Special Summon it. You can only use each effect of "Sylvan Princessprite" once per turn.
external_ids: local SETCARD_ID_0 = 0x90 --Sylvan
  
lua: local SETCARD_ID_0 = 0x90 --Sylvan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 1, 2)
  	c:EnableReviveLimit()
  	--tohand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 1) and Duel.IsExistingMatchingCard(Card.IsAbleToHand, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanDiscardDeck(tp, 1) then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 1)
  	local g = Duel.GetDecktopGroup(tp, 1)
  	local tc = g:GetFirst()
  	if tc:IsType(TYPE_SPELL + TYPE_TRAP) and tc:IsAbleToHand() then
  		Duel.DisableShuffleCheck()
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ShuffleHand(tp)
  	else
  		Duel.DisableShuffleCheck()
  		Duel.SendtoGrave(tc, REASON_EFFECT + REASON_REVEAL)
  	end
  end
  function s.cfilter(c, ft)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_HAND)) and c:IsRace(RACE_PLANT) and c:IsAbleToGraveAsCost() and (ft > 0 or c:GetSequence() < 5)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local loc = LOCATION_HAND + LOCATION_MZONE
  	if ft == 0 then
  		loc = LOCATION_MZONE
  	end
  	if chk == 0 then
  		return ft > -1 and Duel.IsExistingMatchingCard(s.cfilter, tp, loc, 0, 1, e:GetHandler(), ft)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, loc, 0, 1, 1, e:GetHandler(), ft)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Sylvan
  2 Level 1 monsters
  You can detach 1 Xyz Material from this card; excavate the top card of your Deck, and if it is a Spell/Trap, add it to your hand. Otherwise, send it to the GY. You can send 1 other Plant monster from your hand or face-up from your field to the GY, then target 1 "Sylvan" monster in your GY; Special Summon it. You can only use each effect of "Sylvan Princessprite" once per turn.
target_text: -- Sylvan
  local SETCARD_ID_0 = 0x90 --Sylvan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 1, 2)
  	c:EnableReviveLimit()
  	--tohand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 1) and Duel.IsExistingMatchingCard(Card.IsAbleToHand, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanDiscardDeck(tp, 1) then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 1)
  	local g = Duel.GetDecktopGroup(tp, 1)
  	local tc = g:GetFirst()
  	if tc:IsType(TYPE_SPELL + TYPE_TRAP) and tc:IsAbleToHand() then
  		Duel.DisableShuffleCheck()
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ShuffleHand(tp)
  	else
  		Duel.DisableShuffleCheck()
  		Duel.SendtoGrave(tc, REASON_EFFECT + REASON_REVEAL)
  	end
  end
  function s.cfilter(c, ft)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_HAND)) and c:IsRace(RACE_PLANT) and c:IsAbleToGraveAsCost() and (ft > 0 or c:GetSequence() < 5)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local loc = LOCATION_HAND + LOCATION_MZONE
  	if ft == 0 then
  		loc = LOCATION_MZONE
  	end
  	if chk == 0 then
  		return ft > -1 and Duel.IsExistingMatchingCard(s.cfilter, tp, loc, 0, 1, e:GetHandler(), ft)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, loc, 0, 1, 1, e:GetHandler(), ft)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  