Pendulum
Discard 1 card; add 2 "Magician" Pendulum Monsters with different names from your Deck to your hand, also, until the end of your opponent's next turn after this card resolves, "Magician" cards in your Pendulum Zones cannot be destroyed by card effects. You can only activate 1 "Pendulum Call" per turn. You cannot activate this card if you activated a "Magician" monster's Pendulum Effect this turn.
local SETCARD_ID_0 = 0x98 --Magician

local SETCARD_ID_0 = 0x98 --Magician
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
	e1:SetCondition(s.condition)
	e1:SetCost(s.cost)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
end
function s.chainfilter(re, tp, cid)
	local rc = re:GetHandler()
	local loc = Duel.GetChainInfo(cid, CHAININFO_TRIGGERING_LOCATION)
	return not (re:GetActiveType() == TYPE_PENDULUM + TYPE_SPELL and not re:IsHasType(EFFECT_TYPE_ACTIVATE) and bit.band(loc, LOCATION_PZONE) == LOCATION_PZONE and rc:IsSetCard(SETCARD_ID_0))
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) == 0
end
function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
	end
	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
end
function s.thfilter(c)
	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and c:IsAbleToHand()
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
		return g:GetClassCount(Card.GetCode) >= 2
	end
	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
	if g:GetClassCount(Card.GetCode) >= 2 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
		local g1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
		Duel.SendtoHand(g1, nil, REASON_EFFECT)
		Duel.ConfirmCards(1 - tp, g1)
	end
	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
		local e1 = Effect.CreateEffect(e:GetHandler())
		e1:SetType(EFFECT_TYPE_FIELD)
		e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
		e1:SetTargetRange(LOCATION_PZONE, 0)
		e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
		e1:SetValue(1)
		e1:SetReset(RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
		Duel.RegisterEffect(e1, tp)
	end
end


Pendulum
Discard 1 card; add 2 "Magician" Pendulum Monsters with different names from your Deck to your hand, also, until the end of your opponent's next turn after this card resolves, "Magician" cards in your Pendulum Zones cannot be destroyed by card effects. You can only activate 1 "Pendulum Call" per turn. You cannot activate this card if you activated a "Magician" monster's Pendulum Effect this turn.
-- Pendulum
local SETCARD_ID_0 = 0x98 --Magician
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
	e1:SetCondition(s.condition)
	e1:SetCost(s.cost)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
end
function s.chainfilter(re, tp, cid)
	local rc = re:GetHandler()
	local loc = Duel.GetChainInfo(cid, CHAININFO_TRIGGERING_LOCATION)
	return not (re:GetActiveType() == TYPE_PENDULUM + TYPE_SPELL and not re:IsHasType(EFFECT_TYPE_ACTIVATE) and bit.band(loc, LOCATION_PZONE) == LOCATION_PZONE and rc:IsSetCard(SETCARD_ID_0))
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) == 0
end
function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
	end
	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
end
function s.thfilter(c)
	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and c:IsAbleToHand()
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
		return g:GetClassCount(Card.GetCode) >= 2
	end
	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
	if g:GetClassCount(Card.GetCode) >= 2 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
		local g1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
		Duel.SendtoHand(g1, nil, REASON_EFFECT)
		Duel.ConfirmCards(1 - tp, g1)
	end
	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
		local e1 = Effect.CreateEffect(e:GetHandler())
		e1:SetType(EFFECT_TYPE_FIELD)
		e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
		e1:SetTargetRange(LOCATION_PZONE, 0)
		e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
		e1:SetValue(1)
		e1:SetReset(RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
		Duel.RegisterEffect(e1, tp)
	end
end

