Generate a YGOPro Lua script for the following Yu-Gi-Oh card effect:
FLIP: You can Special Summon 1 "Shaddoll" monster from your Deck in face-up or face-down Defense Position, except "Reeshaddoll Wendi". If this card is sent to the GY by a card effect: You can Special Summon 1 "Shaddoll" monster from your Deck in face-down Defense Position, except "Reeshaddoll Wendi". You can only use 1 "Reeshaddoll Wendi" effect per turn, and only once that turn.
--影霊の翼 ウェンディ
--Reeshaddoll Wendi
--Scripted by AlphaKretin
local s,id=GetID()
function s.initial_effect(c)
	--special summon (any pos)
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id,0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_FLIP+EFFECT_TYPE_TRIGGER_O)
	e1:SetProperty(EFFECT_FLAG_DELAY)
	e1:SetCountLimit(1,id)
	e1:SetTarget(s.sptg(POS_DEFENSE))
	e1:SetOperation(s.spop(POS_DEFENSE))
	c:RegisterEffect(e1)
	--special summon (face-down)
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id,1))
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DELAY)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCountLimit(1,id)
	e2:SetCondition(s.spcon)
	e2:SetTarget(s.sptg(POS_FACEDOWN_DEFENSE))
	e2:SetOperation(s.spop(POS_FACEDOWN_DEFENSE))
	c:RegisterEffect(e2)
end
s.listed_names={id}
s.listed_series={SET_SHADDOLL}
function s.spfilter(c,e,tp,pos)
	return c:IsSetCard(SET_SHADDOLL) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,pos) and not c:IsCode(id)
end
function s.sptg(pos)
	return function(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_DECK,0,1,nil,e,tp,pos) end
		Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,0,LOCATION_DECK)
	end
end
function s.spop(pos)
	return function(e,tp,eg,ep,ev,re,r,rp)
		Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
		local g=Duel.SelectMatchingCard(tp,s.spfilter,tp,LOCATION_DECK,0,1,1,nil,e,tp,pos)
		if #g>0 then
			Duel.SpecialSummon(g,0,tp,tp,false,false,pos)
			Duel.ConfirmCards(1-tp,g)
		end
	end
end
function s.spcon(e,tp,eg,ep,ev,re,r,rp)
	return e:GetHandler():IsReason(REASON_EFFECT)
end