name: Performapal
card_text: Pendulum Scale = 1
  [ Pendulum Effect ]
  Once per turn, at the start of the Battle Phase: You can add 1 monster with 300 ATK/200 DEF from your Deck to your hand, then destroy this card.
  ----------------------------------------
  [ Monster Effect ]
  When your monster is destroyed by battle: You can Special Summon this card from your hand. Your opponent's monsters cannot target monsters for attacks, except this one. If this card is attacked, change it to Attack Position at the end of the Damage Step.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.tgtg)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--atk limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(0, LOCATION_MZONE)
  	e3:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e3:SetValue(s.atklimit)
  	c:RegisterEffect(e3)
  	--to attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetOperation(s.posop)
  	c:RegisterEffect(e4)
  end
  function s.tgfilter(c)
  	return c:IsAttack(300) and c:IsDefense(200) and c:IsAbleToHand()
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, e:GetHandler(), 1, 0, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc and Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 and tc:IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, tc)
  		Duel.BreakEffect()
  		Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.atklimit(e, c)
  	return c ~= e:GetHandler()
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c == Duel.GetAttackTarget() and c:IsDefensePos() and c:IsRelateToBattle() then
  		Duel.ChangePosition(c, POS_FACEUP_ATTACK)
  	end
  end
  
  
source_text: Performapal
  Pendulum Scale = 1
  [ Pendulum Effect ]
  Once per turn, at the start of the Battle Phase: You can add 1 monster with 300 ATK/200 DEF from your Deck to your hand, then destroy this card.
  ----------------------------------------
  [ Monster Effect ]
  When your monster is destroyed by battle: You can Special Summon this card from your hand. Your opponent's monsters cannot target monsters for attacks, except this one. If this card is attacked, change it to Attack Position at the end of the Damage Step.
target_text: -- Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.tgtg)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--atk limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(0, LOCATION_MZONE)
  	e3:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e3:SetValue(s.atklimit)
  	c:RegisterEffect(e3)
  	--to attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetOperation(s.posop)
  	c:RegisterEffect(e4)
  end
  function s.tgfilter(c)
  	return c:IsAttack(300) and c:IsDefense(200) and c:IsAbleToHand()
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, e:GetHandler(), 1, 0, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc and Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 and tc:IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, tc)
  		Duel.BreakEffect()
  		Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.atklimit(e, c)
  	return c ~= e:GetHandler()
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c == Duel.GetAttackTarget() and c:IsDefensePos() and c:IsRelateToBattle() then
  		Duel.ChangePosition(c, POS_FACEUP_ATTACK)
  	end
  end
  
  