name: Performapal
card_text: Send up to 3 cards from your hand to the GY; draw that many cards, then you can Special Summon up to that many monsters from your hand, with different names, that are "Performapal" monsters, "Magician" Pendulum Monsters, and/or "Odd-Eyes" monsters, each with a Level between the Pendulum Scales of the 2 cards in your Pendulum Zones. If you did not Special Summon by this effect, you lose 1000 LP for each card in your hand. You can only activate 1 "Performapal Popperup" per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x9f --Performapal
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x9f --Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, e, tp, lsc, rsc)
  	local lv = c:GetLevel()
  	return (c:IsSetCard(SETCARD_ID_0, 0x99) or (c:IsSetCard(0x98) and c:IsType(TYPE_PENDULUM))) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and lv > 0 and lv > lsc and lv < rsc
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGraveAsCost, tp, LOCATION_HAND, 0, e:GetHandler())
  	if chk == 0 then
  		return g:GetCount() > 0
  	end
  	local ct = 1
  	for i = 2, 3 do
  		if Duel.IsPlayerCanDraw(tp, i) then
  			ct = i
  		end
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:Select(tp, 1, ct, nil)
  	e:SetLabel(Duel.SendtoGrave(sg, REASON_COST))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	local ct = e:GetLabel()
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(ct)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, ct)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	local ct = Duel.Draw(p, d, REASON_EFFECT)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local res = false
  	local lc = Duel.GetFieldCard(tp, LOCATION_PZONE, 0)
  	local rc = Duel.GetFieldCard(tp, LOCATION_PZONE, 1)
  	if ct > 0 and ft > 0 and lc and rc then
  		local lsc = lc:GetLeftScale()
  		local rsc = rc:GetRightScale()
  		if lsc > rsc then
  			lsc, rsc = rsc, lsc
  		end
  		if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp, lsc, rsc) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			ct = math.min(ct, ft)
  			if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  				ct = 1
  			end
  			local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND, 0, nil, e, tp, lsc, rsc)
  			local sg = g:SelectSubGroup(tp, aux.dncheck, false, 1, ct)
  			res = Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP) > 0
  		end
  	end
  	if not res then
  		local lp = Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0)
  		Duel.SetLP(tp, Duel.GetLP(tp) - lp * 1000)
  	end
  end
  
  
source_text: Performapal
  Send up to 3 cards from your hand to the GY; draw that many cards, then you can Special Summon up to that many monsters from your hand, with different names, that are "Performapal" monsters, "Magician" Pendulum Monsters, and/or "Odd-Eyes" monsters, each with a Level between the Pendulum Scales of the 2 cards in your Pendulum Zones. If you did not Special Summon by this effect, you lose 1000 LP for each card in your hand. You can only activate 1 "Performapal Popperup" per turn.
target_text: -- Performapal
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x9f --Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, e, tp, lsc, rsc)
  	local lv = c:GetLevel()
  	return (c:IsSetCard(SETCARD_ID_0, 0x99) or (c:IsSetCard(0x98) and c:IsType(TYPE_PENDULUM))) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and lv > 0 and lv > lsc and lv < rsc
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGraveAsCost, tp, LOCATION_HAND, 0, e:GetHandler())
  	if chk == 0 then
  		return g:GetCount() > 0
  	end
  	local ct = 1
  	for i = 2, 3 do
  		if Duel.IsPlayerCanDraw(tp, i) then
  			ct = i
  		end
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:Select(tp, 1, ct, nil)
  	e:SetLabel(Duel.SendtoGrave(sg, REASON_COST))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	local ct = e:GetLabel()
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(ct)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, ct)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	local ct = Duel.Draw(p, d, REASON_EFFECT)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local res = false
  	local lc = Duel.GetFieldCard(tp, LOCATION_PZONE, 0)
  	local rc = Duel.GetFieldCard(tp, LOCATION_PZONE, 1)
  	if ct > 0 and ft > 0 and lc and rc then
  		local lsc = lc:GetLeftScale()
  		local rsc = rc:GetRightScale()
  		if lsc > rsc then
  			lsc, rsc = rsc, lsc
  		end
  		if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp, lsc, rsc) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			ct = math.min(ct, ft)
  			if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  				ct = 1
  			end
  			local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND, 0, nil, e, tp, lsc, rsc)
  			local sg = g:SelectSubGroup(tp, aux.dncheck, false, 1, ct)
  			res = Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP) > 0
  		end
  	end
  	if not res then
  		local lp = Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0)
  		Duel.SetLP(tp, Duel.GetLP(tp) - lp * 1000)
  	end
  end
  
  