name: Performapal
card_text: Pendulum Scale = 1
  [ Pendulum Effect ]
  Once per turn, if a monster is Fusion Summoned to your field (except during the Damage Step): You can add 1 "Performapal", "Odd-Eyes", or "Magician" Pendulum Monster from your GY or face-up in your Extra Deck to your hand.
  ----------------------------------------
  [ Monster Effect ]
  Once per turn, during your Main Phase, if this card was Pendulum Summoned this turn: You can Fusion Summon 1 Fusion Monster from your Extra Deck, using this card you control and Dragon monsters you control as Fusion Materials.
external_ids: local SETCARD_ID_0 = 0x98 --Magician
  
lua: local SETCARD_ID_0 = 0x98 --Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.EnablePendulumAttribute(c)
  	--salvage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--reg
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCondition(s.effcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--fusion
  	local e3 = FusionSpell.CreateSummonEffect(c, {
  		matfilter = s.matfilter,
  		pre_select_mat_location = LOCATION_MZONE,
  		gc = s.gc,
  	})
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.spcon)
  	c:RegisterEffect(e3)
  end
  
  function s.thcfilter(c, tp)
  	return c:IsControler(tp) and c:IsSummonType(SUMMON_TYPE_FUSION)
  end
  
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg and eg:IsExists(s.thcfilter, 1, nil, tp)
  end
  
  function s.thfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsSetCard(SETCARD_ID_0, 0x99, 0x9f) and c:IsType(TYPE_PENDULUM) and c:IsAbleToHand()
  end
  
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE + LOCATION_EXTRA)
  end
  
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  function s.effcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_PENDULUM)
  end
  
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  
  function s.matfilter(c, e)
  	return c:IsRace(RACE_DRAGON) or c == e:GetHandler()
  end
  
  function s.gc(e)
  	return e:GetHandler()
  end
  
  
source_text: Performapal
  Pendulum Scale = 1
  [ Pendulum Effect ]
  Once per turn, if a monster is Fusion Summoned to your field (except during the Damage Step): You can add 1 "Performapal", "Odd-Eyes", or "Magician" Pendulum Monster from your GY or face-up in your Extra Deck to your hand.
  ----------------------------------------
  [ Monster Effect ]
  Once per turn, during your Main Phase, if this card was Pendulum Summoned this turn: You can Fusion Summon 1 Fusion Monster from your Extra Deck, using this card you control and Dragon monsters you control as Fusion Materials.
target_text: -- Performapal
  local SETCARD_ID_0 = 0x98 --Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.EnablePendulumAttribute(c)
  	--salvage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--reg
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCondition(s.effcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--fusion
  	local e3 = FusionSpell.CreateSummonEffect(c, {
  		matfilter = s.matfilter,
  		pre_select_mat_location = LOCATION_MZONE,
  		gc = s.gc,
  	})
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.spcon)
  	c:RegisterEffect(e3)
  end
  
  function s.thcfilter(c, tp)
  	return c:IsControler(tp) and c:IsSummonType(SUMMON_TYPE_FUSION)
  end
  
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg and eg:IsExists(s.thcfilter, 1, nil, tp)
  end
  
  function s.thfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsSetCard(SETCARD_ID_0, 0x99, 0x9f) and c:IsType(TYPE_PENDULUM) and c:IsAbleToHand()
  end
  
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE + LOCATION_EXTRA)
  end
  
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  function s.effcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_PENDULUM)
  end
  
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  
  function s.matfilter(c, e)
  	return c:IsRace(RACE_DRAGON) or c == e:GetHandler()
  end
  
  function s.gc(e)
  	return e:GetHandler()
  end
  
  