name: Performapal
card_text: Pendulum Scale = 8
  [ Pendulum Effect ]
  When an opponent's monster declares a direct attack, this card is destroyed.
  ----------------------------------------
  [ Monster Effect ]
  If this card is destroyed by its own Pendulum Effect: End the Battle Phase. You can only use each of the following effects of "Performapal Classikuriboh" once per turn. You can discard this card, then target 1 card in your Pendulum Zone; its Pendulum Scale becomes 1 until the end of this turn. When you take battle damage while this card is in your GY: You can place this card in your Pendulum Zone.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCondition(s.descon)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	--scale
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.sccost)
  	e2:SetTarget(s.sctg)
  	e2:SetOperation(s.scop)
  	c:RegisterEffect(e2)
  	--pendulum set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_BATTLE_DAMAGE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.pencon)
  	e3:SetTarget(s.pentg)
  	e3:SetOperation(s.penop)
  	c:RegisterEffect(e3)
  	--end battle phase
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_DESTROYED)
  	e4:SetCondition(s.endcon)
  	e4:SetOperation(s.endop)
  	c:RegisterEffect(e4)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.sccost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_DISCARD + REASON_COST)
  end
  function s.scfilter(c)
  	return c:GetCurrentScale() ~= 1
  end
  function s.sctg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_PZONE) and chkc:IsControler(tp) and s.scfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.scfilter, tp, LOCATION_PZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.scfilter, tp, LOCATION_PZONE, 0, 1, 1, nil)
  end
  function s.scop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LSCALE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_CHANGE_RSCALE)
  		tc:RegisterEffect(e2)
  	end
  end
  function s.pencon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp
  end
  function s.pentg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.penop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.MoveToField(c, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  	end
  end
  function s.endcon(e, tp, eg, ep, ev, re, r, rp)
  	if not re then
  		return
  	end
  	local c = e:GetHandler()
  	local rc = re:GetHandler()
  	return c:IsReason(REASON_EFFECT) and rc == c
  end
  function s.endop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SkipPhase(1 - tp, PHASE_BATTLE, RESET_PHASE + PHASE_BATTLE_STEP, 1)
  end
  
  
source_text: Performapal
  Pendulum Scale = 8
  [ Pendulum Effect ]
  When an opponent's monster declares a direct attack, this card is destroyed.
  ----------------------------------------
  [ Monster Effect ]
  If this card is destroyed by its own Pendulum Effect: End the Battle Phase. You can only use each of the following effects of "Performapal Classikuriboh" once per turn. You can discard this card, then target 1 card in your Pendulum Zone; its Pendulum Scale becomes 1 until the end of this turn. When you take battle damage while this card is in your GY: You can place this card in your Pendulum Zone.
target_text: -- Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCondition(s.descon)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	--scale
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.sccost)
  	e2:SetTarget(s.sctg)
  	e2:SetOperation(s.scop)
  	c:RegisterEffect(e2)
  	--pendulum set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_BATTLE_DAMAGE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.pencon)
  	e3:SetTarget(s.pentg)
  	e3:SetOperation(s.penop)
  	c:RegisterEffect(e3)
  	--end battle phase
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_DESTROYED)
  	e4:SetCondition(s.endcon)
  	e4:SetOperation(s.endop)
  	c:RegisterEffect(e4)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.sccost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_DISCARD + REASON_COST)
  end
  function s.scfilter(c)
  	return c:GetCurrentScale() ~= 1
  end
  function s.sctg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_PZONE) and chkc:IsControler(tp) and s.scfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.scfilter, tp, LOCATION_PZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.scfilter, tp, LOCATION_PZONE, 0, 1, 1, nil)
  end
  function s.scop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LSCALE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_CHANGE_RSCALE)
  		tc:RegisterEffect(e2)
  	end
  end
  function s.pencon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp
  end
  function s.pentg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.penop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.MoveToField(c, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  	end
  end
  function s.endcon(e, tp, eg, ep, ev, re, r, rp)
  	if not re then
  		return
  	end
  	local c = e:GetHandler()
  	local rc = re:GetHandler()
  	return c:IsReason(REASON_EFFECT) and rc == c
  end
  function s.endop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SkipPhase(1 - tp, PHASE_BATTLE, RESET_PHASE + PHASE_BATTLE_STEP, 1)
  end
  
  