name: Pendulum
card_text: Target 2 cards in your Pendulum Zones; Special Summon both targets, but negate their effects, then, immediately after this effect resolves, Xyz Summon 1 Xyz Monster using only those 2 monsters. When you do, you can treat the Level of 1 of the monsters the same as the other monster's. You can only activate 1 "Pendulum Xyz" per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.spfilter1(c, e, tp)
  	return c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.IsExistingTarget(s.spfilter2, tp, LOCATION_PZONE, 0, 1, c, e, tp, c)
  end
  function s.xyzlv(e, c, rc)
  	return e:GetHandler():GetLevel() + e:GetLabel() * 0x10000
  end
  function s.spfilter2(c, e, tp, mc)
  	if not c:IsCanBeSpecialSummoned(e, 0, tp, false, false) then
  		return false
  	end
  	local e1 = nil
  	local e2 = nil
  	if c:IsLevelAbove(1) and mc:IsLevelAbove(1) then
  		e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_XYZ_LEVEL)
  		e1:SetValue(s.xyzlv)
  		e1:SetLabel(mc:GetLevel())
  		c:RegisterEffect(e1, true)
  		e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_XYZ_LEVEL)
  		e2:SetValue(s.xyzlv)
  		e2:SetLabel(c:GetLevel())
  		mc:RegisterEffect(e2, true)
  	end
  	local res = Duel.IsExistingMatchingCard(Card.IsXyzSummonable, tp, LOCATION_EXTRA, 0, 1, nil, Group.FromCards(c, mc), 2, 2)
  	if e1 then
  		e1:Reset()
  	end
  	if e2 then
  		e2:Reset()
  	end
  	return res
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanSpecialSummonCount(tp, 2)
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
  			and Duel.IsExistingTarget(s.spfilter1, tp, LOCATION_PZONE, 0, 1, nil, e, tp)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, 0, 0)
  end
  function s.spfilter3(c, e, tp)
  	return c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
  		return
  	end
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(s.spfilter3, nil, e, tp)
  	if g:GetCount() < 2 then
  		return
  	end
  	local tc1 = g:GetFirst()
  	local tc2 = g:GetNext()
  	Duel.SpecialSummonStep(tc1, 0, tp, tp, false, false, POS_FACEUP)
  	Duel.SpecialSummonStep(tc2, 0, tp, tp, false, false, POS_FACEUP)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  	tc1:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_DISABLE_EFFECT)
  	e2:SetValue(RESET_TURN_SET)
  	tc1:RegisterEffect(e2)
  	local e3 = e1:Clone()
  	tc2:RegisterEffect(e3)
  	local e4 = e2:Clone()
  	tc2:RegisterEffect(e4)
  	Duel.SpecialSummonComplete()
  	Duel.AdjustAll()
  	if g:FilterCount(Card.IsLocation, nil, LOCATION_MZONE) < 2 then
  		return
  	end
  	local e5 = nil
  	local e6 = nil
  	if tc1:IsLevelAbove(1) and tc2:IsLevelAbove(1) then
  		e5 = Effect.CreateEffect(e:GetHandler())
  		e5:SetType(EFFECT_TYPE_SINGLE)
  		e5:SetCode(EFFECT_XYZ_LEVEL)
  		e5:SetValue(s.xyzlv)
  		e5:SetLabel(tc2:GetLevel())
  		e5:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc1:RegisterEffect(e5, true)
  		e6 = Effect.CreateEffect(e:GetHandler())
  		e6:SetType(EFFECT_TYPE_SINGLE)
  		e6:SetCode(EFFECT_XYZ_LEVEL)
  		e6:SetValue(s.xyzlv)
  		e6:SetLabel(tc1:GetLevel())
  		e6:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc2:RegisterEffect(e6, true)
  	end
  	local xyzg = Duel.GetMatchingGroup(Card.IsXyzSummonable, tp, LOCATION_EXTRA, 0, nil, g, 2, 2)
  	if xyzg:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local xyz = xyzg:Select(tp, 1, 1, nil):GetFirst()
  		Duel.XyzSummon(tp, xyz, g)
  	else
  		if e5 then
  			e5:Reset()
  		end
  		if e6 then
  			e5:Reset()
  		end
  	end
  end
  
  
source_text: Pendulum
  Target 2 cards in your Pendulum Zones; Special Summon both targets, but negate their effects, then, immediately after this effect resolves, Xyz Summon 1 Xyz Monster using only those 2 monsters. When you do, you can treat the Level of 1 of the monsters the same as the other monster's. You can only activate 1 "Pendulum Xyz" per turn.
target_text: -- Pendulum
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.spfilter1(c, e, tp)
  	return c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.IsExistingTarget(s.spfilter2, tp, LOCATION_PZONE, 0, 1, c, e, tp, c)
  end
  function s.xyzlv(e, c, rc)
  	return e:GetHandler():GetLevel() + e:GetLabel() * 0x10000
  end
  function s.spfilter2(c, e, tp, mc)
  	if not c:IsCanBeSpecialSummoned(e, 0, tp, false, false) then
  		return false
  	end
  	local e1 = nil
  	local e2 = nil
  	if c:IsLevelAbove(1) and mc:IsLevelAbove(1) then
  		e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_XYZ_LEVEL)
  		e1:SetValue(s.xyzlv)
  		e1:SetLabel(mc:GetLevel())
  		c:RegisterEffect(e1, true)
  		e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_XYZ_LEVEL)
  		e2:SetValue(s.xyzlv)
  		e2:SetLabel(c:GetLevel())
  		mc:RegisterEffect(e2, true)
  	end
  	local res = Duel.IsExistingMatchingCard(Card.IsXyzSummonable, tp, LOCATION_EXTRA, 0, 1, nil, Group.FromCards(c, mc), 2, 2)
  	if e1 then
  		e1:Reset()
  	end
  	if e2 then
  		e2:Reset()
  	end
  	return res
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanSpecialSummonCount(tp, 2)
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
  			and Duel.IsExistingTarget(s.spfilter1, tp, LOCATION_PZONE, 0, 1, nil, e, tp)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, 0, 0)
  end
  function s.spfilter3(c, e, tp)
  	return c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
  		return
  	end
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(s.spfilter3, nil, e, tp)
  	if g:GetCount() < 2 then
  		return
  	end
  	local tc1 = g:GetFirst()
  	local tc2 = g:GetNext()
  	Duel.SpecialSummonStep(tc1, 0, tp, tp, false, false, POS_FACEUP)
  	Duel.SpecialSummonStep(tc2, 0, tp, tp, false, false, POS_FACEUP)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  	tc1:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_DISABLE_EFFECT)
  	e2:SetValue(RESET_TURN_SET)
  	tc1:RegisterEffect(e2)
  	local e3 = e1:Clone()
  	tc2:RegisterEffect(e3)
  	local e4 = e2:Clone()
  	tc2:RegisterEffect(e4)
  	Duel.SpecialSummonComplete()
  	Duel.AdjustAll()
  	if g:FilterCount(Card.IsLocation, nil, LOCATION_MZONE) < 2 then
  		return
  	end
  	local e5 = nil
  	local e6 = nil
  	if tc1:IsLevelAbove(1) and tc2:IsLevelAbove(1) then
  		e5 = Effect.CreateEffect(e:GetHandler())
  		e5:SetType(EFFECT_TYPE_SINGLE)
  		e5:SetCode(EFFECT_XYZ_LEVEL)
  		e5:SetValue(s.xyzlv)
  		e5:SetLabel(tc2:GetLevel())
  		e5:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc1:RegisterEffect(e5, true)
  		e6 = Effect.CreateEffect(e:GetHandler())
  		e6:SetType(EFFECT_TYPE_SINGLE)
  		e6:SetCode(EFFECT_XYZ_LEVEL)
  		e6:SetValue(s.xyzlv)
  		e6:SetLabel(tc1:GetLevel())
  		e6:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc2:RegisterEffect(e6, true)
  	end
  	local xyzg = Duel.GetMatchingGroup(Card.IsXyzSummonable, tp, LOCATION_EXTRA, 0, nil, g, 2, 2)
  	if xyzg:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local xyz = xyzg:Select(tp, 1, 1, nil):GetFirst()
  		Duel.XyzSummon(tp, xyz, g)
  	else
  		if e5 then
  			e5:Reset()
  		end
  		if e6 then
  			e5:Reset()
  		end
  	end
  end
  
  