PSY-Framegear
Cannot be Normal Summoned/Set. Must be Special Summoned by a card effect. When your opponent activates a monster effect while you control no monsters (Quick Effect): You can Special Summon both this card from your hand and 1 "PSY-Frame Driver" from your hand, Deck, or GY, and if you do, negate that activation, and if you do that, destroy that monster. During the End Phase, banish the face-up monsters Special Summoned by this effect.
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local CARD_ID_1 = 8802510 --PSY-Framelord Lambda
local CARD_ID_2 = 49036338 --PSY-Frame Driver

local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local CARD_ID_1 = 8802510 --PSY-Framelord Lambda
local CARD_ID_2 = 49036338 --PSY-Frame Driver
local s, id, o = GetID()
function s.initial_effect(c)
	--splimit
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
	e1:SetValue(s.splimit)
	c:RegisterEffect(e1)
	--spsummon
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_NEGATE + CATEGORY_DESTROY)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetRange(LOCATION_HAND)
	e2:SetCode(EVENT_CHAINING)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
	e2:SetCondition(s.condition)
	e2:SetTarget(s.target)
	e2:SetOperation(s.operation)
	c:RegisterEffect(e2)
end
function s.splimit(e, se, sp, st)
	return se:IsHasType(EFFECT_TYPE_ACTIONS)
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	return (Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 or Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1)) and ep ~= tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainNegatable(ev)
end
function s.spfilter(c, e, tp)
	return c:IsCode(CARD_ID_2) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return not e:GetHandler():IsStatus(STATUS_CHAINING)
			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
			and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
	end
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) or Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
		return
	end
	local c = e:GetHandler()
	if not c:IsRelateToEffect(e) or not c:IsCanBeSpecialSummoned(e, 0, tp, false, false) then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
	if g:GetCount() == 0 then
		return
	end
	local tc = g:GetFirst()
	local fid = c:GetFieldID()
	Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
	Duel.SpecialSummonStep(c, 0, tp, tp, false, false, POS_FACEUP)
	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
	Duel.SpecialSummonComplete()
	g:AddCard(c)
	g:KeepAlive()
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
	e1:SetCode(EVENT_PHASE + PHASE_END)
	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
	e1:SetCountLimit(1)
	e1:SetLabel(fid)
	e1:SetLabelObject(g)
	e1:SetCondition(s.rmcon)
	e1:SetOperation(s.rmop)
	Duel.RegisterEffect(e1, tp)
	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
		Duel.Destroy(eg, REASON_EFFECT)
	end
end
function s.rmfilter(c, fid)
	return c:GetFlagEffectLabel(id) == fid
end
function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
	local g = e:GetLabelObject()
	if not g:IsExists(s.rmfilter, 1, nil, e:GetLabel()) then
		g:DeleteGroup()
		e:Reset()
		return false
	else
		return true
	end
end
function s.rmop(e, tp, eg, ep, ev, re, r, rp)
	local g = e:GetLabelObject()
	local tg = g:Filter(s.rmfilter, nil, e:GetLabel())
	Duel.Remove(tg, POS_FACEUP, REASON_EFFECT)
end


PSY-Framegear
Cannot be Normal Summoned/Set. Must be Special Summoned by a card effect. When your opponent activates a monster effect while you control no monsters (Quick Effect): You can Special Summon both this card from your hand and 1 "PSY-Frame Driver" from your hand, Deck, or GY, and if you do, negate that activation, and if you do that, destroy that monster. During the End Phase, banish the face-up monsters Special Summoned by this effect.
-- PSY-Framegear
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local CARD_ID_1 = 8802510 --PSY-Framelord Lambda
local CARD_ID_2 = 49036338 --PSY-Frame Driver
local s, id, o = GetID()
function s.initial_effect(c)
	--splimit
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
	e1:SetValue(s.splimit)
	c:RegisterEffect(e1)
	--spsummon
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_NEGATE + CATEGORY_DESTROY)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetRange(LOCATION_HAND)
	e2:SetCode(EVENT_CHAINING)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
	e2:SetCondition(s.condition)
	e2:SetTarget(s.target)
	e2:SetOperation(s.operation)
	c:RegisterEffect(e2)
end
function s.splimit(e, se, sp, st)
	return se:IsHasType(EFFECT_TYPE_ACTIONS)
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	return (Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 or Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1)) and ep ~= tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainNegatable(ev)
end
function s.spfilter(c, e, tp)
	return c:IsCode(CARD_ID_2) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return not e:GetHandler():IsStatus(STATUS_CHAINING)
			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
			and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
	end
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) or Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
		return
	end
	local c = e:GetHandler()
	if not c:IsRelateToEffect(e) or not c:IsCanBeSpecialSummoned(e, 0, tp, false, false) then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
	if g:GetCount() == 0 then
		return
	end
	local tc = g:GetFirst()
	local fid = c:GetFieldID()
	Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP)
	Duel.SpecialSummonStep(c, 0, tp, tp, false, false, POS_FACEUP)
	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
	Duel.SpecialSummonComplete()
	g:AddCard(c)
	g:KeepAlive()
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
	e1:SetCode(EVENT_PHASE + PHASE_END)
	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
	e1:SetCountLimit(1)
	e1:SetLabel(fid)
	e1:SetLabelObject(g)
	e1:SetCondition(s.rmcon)
	e1:SetOperation(s.rmop)
	Duel.RegisterEffect(e1, tp)
	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
		Duel.Destroy(eg, REASON_EFFECT)
	end
end
function s.rmfilter(c, fid)
	return c:GetFlagEffectLabel(id) == fid
end
function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
	local g = e:GetLabelObject()
	if not g:IsExists(s.rmfilter, 1, nil, e:GetLabel()) then
		g:DeleteGroup()
		e:Reset()
		return false
	else
		return true
	end
end
function s.rmop(e, tp, eg, ep, ev, re, r, rp)
	local g = e:GetLabelObject()
	local tg = g:Filter(s.rmfilter, nil, e:GetLabel())
	Duel.Remove(tg, POS_FACEUP, REASON_EFFECT)
end

