Curse
Cannot be Normal Summoned/Set. Must be Special Summoned by a card effect. You can target 3 of your banished Fiend monsters; Special Summon this card from your hand, and if you do, shuffle those banished monsters into the Deck. During the End Phase, if this card is in the GY because it was destroyed in your Monster Zone by an opponent's card and sent there this turn: Special Summon this card from your GY, then, you can destroy cards your opponent controls, up to the number of face-up Spells/Traps you control with different names. You can only use each effect of "Curse Necrofear" once per turn.
local s, id, o = GetID()
function s.initial_effect(c)
	--special summon by effect
	local e0 = Effect.CreateEffect(c)
	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e0:SetType(EFFECT_TYPE_SINGLE)
	e0:SetCode(EFFECT_SPSUMMON_CONDITION)
	e0:SetValue(s.splimit)
	c:RegisterEffect(e0)
	--special summon
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
	e1:SetType(EFFECT_TYPE_IGNITION)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetRange(LOCATION_HAND)
	e1:SetCountLimit(1, id)
	e1:SetTarget(s.sptg1)
	e1:SetOperation(s.spop1)
	c:RegisterEffect(e1)
	--reg
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e2:SetOperation(s.tgop)
	c:RegisterEffect(e2)
	--special summon
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 1))
	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e3:SetCode(EVENT_PHASE + PHASE_END)
	e3:SetRange(LOCATION_GRAVE)
	e3:SetCountLimit(1, id + 1)
	e3:SetCondition(s.spcon2)
	e3:SetTarget(s.sptg2)
	e3:SetOperation(s.spop2)
	c:RegisterEffect(e3)
end
function s.splimit(e, se, sp, st)
	return se:IsHasType(EFFECT_TYPE_ACTIONS)
end
function s.spcfilter(c)
	return c:IsRace(RACE_FIEND) and c:IsFaceup() and c:IsAbleToDeck()
end
function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_REMOVED) and s.spcfilter(chkc)
	end
	local c = e:GetHandler()
	if chk == 0 then
		return c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spcfilter, tp, LOCATION_REMOVED, 0, 3, nil)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
	local g = Duel.SelectTarget(tp, s.spcfilter, tp, LOCATION_REMOVED, 0, 3, 3, nil)
	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 3, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
end
function s.spop1(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if not c:IsRelateToEffect(e) then
		return
	end
	if Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
		local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
		Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
	end
end
function s.tgop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE) and rp == 1 - tp and bit.band(r, REASON_DESTROY) ~= 0 then
		c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
	end
end
function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetFlagEffect(id) > 0
end
function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
end
function s.spop2(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
		local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_SZONE, 0, nil)
		local ct = g:GetClassCount(Card.GetCode)
		local dg = Duel.GetMatchingGroup(nil, tp, 0, LOCATION_ONFIELD, nil)
		if ct > 0 and #dg > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
			Duel.BreakEffect()
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
			local sg = dg:Select(tp, 1, ct, nil)
			Duel.HintSelection(sg)
			Duel.Destroy(sg, REASON_EFFECT)
		end
	end
end


Curse
Cannot be Normal Summoned/Set. Must be Special Summoned by a card effect. You can target 3 of your banished Fiend monsters; Special Summon this card from your hand, and if you do, shuffle those banished monsters into the Deck. During the End Phase, if this card is in the GY because it was destroyed in your Monster Zone by an opponent's card and sent there this turn: Special Summon this card from your GY, then, you can destroy cards your opponent controls, up to the number of face-up Spells/Traps you control with different names. You can only use each effect of "Curse Necrofear" once per turn.
-- Curse
local s, id, o = GetID()
function s.initial_effect(c)
	--special summon by effect
	local e0 = Effect.CreateEffect(c)
	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e0:SetType(EFFECT_TYPE_SINGLE)
	e0:SetCode(EFFECT_SPSUMMON_CONDITION)
	e0:SetValue(s.splimit)
	c:RegisterEffect(e0)
	--special summon
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
	e1:SetType(EFFECT_TYPE_IGNITION)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetRange(LOCATION_HAND)
	e1:SetCountLimit(1, id)
	e1:SetTarget(s.sptg1)
	e1:SetOperation(s.spop1)
	c:RegisterEffect(e1)
	--reg
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e2:SetOperation(s.tgop)
	c:RegisterEffect(e2)
	--special summon
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 1))
	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e3:SetCode(EVENT_PHASE + PHASE_END)
	e3:SetRange(LOCATION_GRAVE)
	e3:SetCountLimit(1, id + 1)
	e3:SetCondition(s.spcon2)
	e3:SetTarget(s.sptg2)
	e3:SetOperation(s.spop2)
	c:RegisterEffect(e3)
end
function s.splimit(e, se, sp, st)
	return se:IsHasType(EFFECT_TYPE_ACTIONS)
end
function s.spcfilter(c)
	return c:IsRace(RACE_FIEND) and c:IsFaceup() and c:IsAbleToDeck()
end
function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_REMOVED) and s.spcfilter(chkc)
	end
	local c = e:GetHandler()
	if chk == 0 then
		return c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spcfilter, tp, LOCATION_REMOVED, 0, 3, nil)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
	local g = Duel.SelectTarget(tp, s.spcfilter, tp, LOCATION_REMOVED, 0, 3, 3, nil)
	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 3, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
end
function s.spop1(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if not c:IsRelateToEffect(e) then
		return
	end
	if Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
		local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
		Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
	end
end
function s.tgop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE) and rp == 1 - tp and bit.band(r, REASON_DESTROY) ~= 0 then
		c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
	end
end
function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetFlagEffect(id) > 0
end
function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
end
function s.spop2(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
		local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_SZONE, 0, nil)
		local ct = g:GetClassCount(Card.GetCode)
		local dg = Duel.GetMatchingGroup(nil, tp, 0, LOCATION_ONFIELD, nil)
		if ct > 0 and #dg > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
			Duel.BreakEffect()
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
			local sg = dg:Select(tp, 1, ct, nil)
			Duel.HintSelection(sg)
			Duel.Destroy(sg, REASON_EFFECT)
		end
	end
end

