name: Soul
card_text: You can target 2 cards in your Pendulum Zones; change each target's Pendulum Scale by 1 (min. 1). You can only use this effect of "Soul Pendulum" once per turn. Each time your Pendulum Monster(s) is Pendulum Summoned, place 1 counter on this card. Pendulum Monsters on the field gain 300 ATK for each counter on this card. You can remove 3 counters from this card; during your Main Phase this turn, you can conduct 1 Pendulum Summon of a monster(s) in addition to your Pendulum Summon. (You can only gain this effect once per turn.)
external_ids: local CARD_ID_0 = 29432356 --Zefraath
  local COUNTER_ID_0 = 0x4e --Counter(Soul
  
lua: local CARD_ID_0 = 29432356 --Zefraath
  local COUNTER_ID_0 = 0x4e --Counter(Soul
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x4e)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--scale
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetOperation(s.counterop)
  	c:RegisterEffect(e3)
  	--atk up
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_UPDATE_ATTACK)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e4:SetTarget(aux.TargetBoolFunction(Card.IsType, TYPE_PENDULUM))
  	e4:SetValue(s.atkval)
  	c:RegisterEffect(e4)
  	--extra pendulum
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 3))
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCost(s.expcost)
  	e5:SetTarget(s.exptg)
  	e5:SetOperation(s.expop)
  	c:RegisterEffect(e5)
  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.IsExistingTarget(nil, tp, LOCATION_PZONE, 0, 2, nil)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0)
  	Duel.SetTargetCard(g)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tg = g:Filter(Card.IsRelateToEffect, nil, e)
  	local tc = tg:GetFirst()
  	while tc do
  		Duel.HintSelection(Group.FromCards(tc))
  		local sel = 0
  		if tc:GetLeftScale() <= 1 then
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 1))
  		else
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  		end
  		local ct = 1
  		if sel == 1 then
  			ct = -1
  		end
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LSCALE)
  		e1:SetValue(ct)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_RSCALE)
  		tc:RegisterEffect(e2)
  		tc = tg:GetNext()
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_PENDULUM) and c:IsControler(tp) and c:IsSummonType(SUMMON_TYPE_PENDULUM)
  end
  function s.counterop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.cfilter, 1, nil, tp) then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.atkval(e, c)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) * 300
  end
  function s.expcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  end
  function s.exptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  function s.expop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 4))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_EXTRA_PENDULUM_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetCountLimit(1, CARD_ID_0)
  	e1:SetValue(aux.TRUE)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  
  
source_text: Soul
  You can target 2 cards in your Pendulum Zones; change each target's Pendulum Scale by 1 (min. 1). You can only use this effect of "Soul Pendulum" once per turn. Each time your Pendulum Monster(s) is Pendulum Summoned, place 1 counter on this card. Pendulum Monsters on the field gain 300 ATK for each counter on this card. You can remove 3 counters from this card; during your Main Phase this turn, you can conduct 1 Pendulum Summon of a monster(s) in addition to your Pendulum Summon. (You can only gain this effect once per turn.)
target_text: -- Soul
  local CARD_ID_0 = 29432356 --Zefraath
  local COUNTER_ID_0 = 0x4e --Counter(Soul
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x4e)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--scale
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetOperation(s.counterop)
  	c:RegisterEffect(e3)
  	--atk up
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_UPDATE_ATTACK)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e4:SetTarget(aux.TargetBoolFunction(Card.IsType, TYPE_PENDULUM))
  	e4:SetValue(s.atkval)
  	c:RegisterEffect(e4)
  	--extra pendulum
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 3))
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCost(s.expcost)
  	e5:SetTarget(s.exptg)
  	e5:SetOperation(s.expop)
  	c:RegisterEffect(e5)
  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.IsExistingTarget(nil, tp, LOCATION_PZONE, 0, 2, nil)
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_PZONE, 0)
  	Duel.SetTargetCard(g)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tg = g:Filter(Card.IsRelateToEffect, nil, e)
  	local tc = tg:GetFirst()
  	while tc do
  		Duel.HintSelection(Group.FromCards(tc))
  		local sel = 0
  		if tc:GetLeftScale() <= 1 then
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 1))
  		else
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  		end
  		local ct = 1
  		if sel == 1 then
  			ct = -1
  		end
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LSCALE)
  		e1:SetValue(ct)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_RSCALE)
  		tc:RegisterEffect(e2)
  		tc = tg:GetNext()
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_PENDULUM) and c:IsControler(tp) and c:IsSummonType(SUMMON_TYPE_PENDULUM)
  end
  function s.counterop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.cfilter, 1, nil, tp) then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.atkval(e, c)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) * 300
  end
  function s.expcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  end
  function s.exptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  function s.expop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 4))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_EXTRA_PENDULUM_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetCountLimit(1, CARD_ID_0)
  	e1:SetValue(aux.TRUE)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  
  