name: SolSolfachord
card_text: Pendulum Scale = 4
  [ Pendulum Effect ]
  Your opponent cannot activate a Spell/Trap Card, or monster effect, when your "Solfachord" Pendulum Monster(s) is Pendulum Summoned.
  ----------------------------------------
  [ Monster Effect ]
  While you have an even Pendulum Scale in your Pendulum Zone, if your "Solfachord" Pendulum Monster attacks, your opponent cannot activate monster effects until the end of the Damage Step. If this card is Normal or Special Summoned: You can add 1 "Solfachord" Spell/Trap from your Deck to your hand. You can only use this effect of "SolSolfachord Gracia" once per turn.
external_ids: local SETCARD_ID_0 = 0x162 --Solfachord
  
lua: local SETCARD_ID_0 = 0x162 --Solfachord
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--actlimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCondition(s.limcon)
  	e1:SetOperation(s.limop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetCode(EVENT_CHAIN_END)
  	e2:SetOperation(s.limop2)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.srtg)
  	e3:SetOperation(s.srop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--actlimit attack
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e5:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetTargetRange(0, 1)
  	e5:SetCondition(s.actcon)
  	e5:SetValue(s.aclimit)
  	c:RegisterEffect(e5)
  end
  function s.limfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and c:IsSummonType(SUMMON_TYPE_PENDULUM)
  end
  function s.limcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.limfilter, 1, nil, tp)
  end
  function s.limop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetCurrentChain() == 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	elseif Duel.GetCurrentChain() == 1 then
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_CHAINING)
  		e1:SetOperation(s.resetop)
  		Duel.RegisterEffect(e1, tp)
  		local e2 = e1:Clone()
  		e2:SetCode(EVENT_BREAK_EFFECT)
  		e2:SetReset(RESET_CHAIN)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.resetop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():ResetFlagEffect(id)
  	e:Reset()
  end
  function s.limop2(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():GetFlagEffect(id) ~= 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	end
  end
  function s.chainlm(e, ep, tp)
  	return ep == tp or e:IsActiveType(TYPE_SPELL + TYPE_TRAP) and not e:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  function s.srfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.srtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.srfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.srop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.srfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.pfilter(c)
  	return c:GetCurrentScale() % 2 == 0
  end
  function s.actcon(e)
  	local a = Duel.GetAttacker()
  	local tp = e:GetHandlerPlayer()
  	return a and a:IsControler(tp) and a:IsSetCard(SETCARD_ID_0) and a:IsType(TYPE_PENDULUM) and Duel.IsExistingMatchingCard(s.pfilter, tp, LOCATION_PZONE, 0, 1, nil)
  end
  function s.aclimit(e, re, tp)
  	return re:IsActiveType(TYPE_MONSTER)
  end
  
  
source_text: SolSolfachord
  Pendulum Scale = 4
  [ Pendulum Effect ]
  Your opponent cannot activate a Spell/Trap Card, or monster effect, when your "Solfachord" Pendulum Monster(s) is Pendulum Summoned.
  ----------------------------------------
  [ Monster Effect ]
  While you have an even Pendulum Scale in your Pendulum Zone, if your "Solfachord" Pendulum Monster attacks, your opponent cannot activate monster effects until the end of the Damage Step. If this card is Normal or Special Summoned: You can add 1 "Solfachord" Spell/Trap from your Deck to your hand. You can only use this effect of "SolSolfachord Gracia" once per turn.
target_text: -- SolSolfachord
  local SETCARD_ID_0 = 0x162 --Solfachord
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--actlimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCondition(s.limcon)
  	e1:SetOperation(s.limop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetCode(EVENT_CHAIN_END)
  	e2:SetOperation(s.limop2)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.srtg)
  	e3:SetOperation(s.srop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--actlimit attack
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e5:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetTargetRange(0, 1)
  	e5:SetCondition(s.actcon)
  	e5:SetValue(s.aclimit)
  	c:RegisterEffect(e5)
  end
  function s.limfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and c:IsSummonType(SUMMON_TYPE_PENDULUM)
  end
  function s.limcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.limfilter, 1, nil, tp)
  end
  function s.limop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetCurrentChain() == 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	elseif Duel.GetCurrentChain() == 1 then
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_CHAINING)
  		e1:SetOperation(s.resetop)
  		Duel.RegisterEffect(e1, tp)
  		local e2 = e1:Clone()
  		e2:SetCode(EVENT_BREAK_EFFECT)
  		e2:SetReset(RESET_CHAIN)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.resetop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():ResetFlagEffect(id)
  	e:Reset()
  end
  function s.limop2(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():GetFlagEffect(id) ~= 0 then
  		Duel.SetChainLimitTillChainEnd(s.chainlm)
  	end
  end
  function s.chainlm(e, ep, tp)
  	return ep == tp or e:IsActiveType(TYPE_SPELL + TYPE_TRAP) and not e:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  function s.srfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.srtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.srfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.srop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.srfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.pfilter(c)
  	return c:GetCurrentScale() % 2 == 0
  end
  function s.actcon(e)
  	local a = Duel.GetAttacker()
  	local tp = e:GetHandlerPlayer()
  	return a and a:IsControler(tp) and a:IsSetCard(SETCARD_ID_0) and a:IsType(TYPE_PENDULUM) and Duel.IsExistingMatchingCard(s.pfilter, tp, LOCATION_PZONE, 0, 1, nil)
  end
  function s.aclimit(e, re, tp)
  	return re:IsActiveType(TYPE_MONSTER)
  end
  
  