name: Performapal
card_text: Pendulum Scale = 1
  [ Pendulum Effect ]
  Once per turn, when an attack is declared involving your monster and an opponent's monster: You can discard 1 Pendulum Monster; that opponent's monster loses 1000 ATK, until the end of this turn.
  ----------------------------------------
  [ Monster Effect ]
  You can discard this card and 1 "Performapal" monster, except "Performapal Ladyange"; draw 2 cards. If this card is in your GY and you control an "Odd-Eyes" card or "Performapal Gentrude": You can place this card in your Pendulum Zone. You can only use 1 "Performapal Ladyange" effect per turn, and only once that turn.
external_ids: local CARD_ID_0 = 21949879 --Performapal Gentrude
  local SETCARD_ID_0 = 0x9f --Performapal
  local SETCARD_ID_1 = 0x99 --Odd-Eyes
  
lua: local CARD_ID_0 = 21949879 --Performapal Gentrude
  local SETCARD_ID_0 = 0x9f --Performapal
  local SETCARD_ID_1 = 0x99 --Odd-Eyes
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.EnablePendulumAttribute(c)
  	--atk down
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.atkcon)
  	e1:SetCost(s.atkcost)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.drcost)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  	--pendulum set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.pencon)
  	e3:SetTarget(s.pentg)
  	e3:SetOperation(s.penop)
  	c:RegisterEffect(e3)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local a, d = Duel.GetBattleMonster(tp)
  	return a and d and d:IsFaceup()
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsDiscardable()
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, s.costfilter, 1, 1, REASON_COST + REASON_DISCARD, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetBattleMonster(1 - tp)
  	if tc and tc:IsRelateToBattle() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(-1000)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.drfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and not c:IsCode(id) and c:IsDiscardable()
  end
  function s.drcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable() and Duel.IsExistingMatchingCard(s.drfilter, tp, LOCATION_HAND, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local g = Duel.SelectMatchingCard(tp, s.drfilter, tp, LOCATION_HAND, 0, 1, 1, c)
  	g:AddCard(c)
  	Duel.SendtoGrave(g, REASON_COST + REASON_DISCARD)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 2)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(2)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 2)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.penfilter(c)
  	return (c:IsSetCard(SETCARD_ID_1) or c:IsCode(CARD_ID_0)) and c:IsFaceup()
  end
  function s.pencon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.penfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  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
  
  
source_text: Performapal
  Pendulum Scale = 1
  [ Pendulum Effect ]
  Once per turn, when an attack is declared involving your monster and an opponent's monster: You can discard 1 Pendulum Monster; that opponent's monster loses 1000 ATK, until the end of this turn.
  ----------------------------------------
  [ Monster Effect ]
  You can discard this card and 1 "Performapal" monster, except "Performapal Ladyange"; draw 2 cards. If this card is in your GY and you control an "Odd-Eyes" card or "Performapal Gentrude": You can place this card in your Pendulum Zone. You can only use 1 "Performapal Ladyange" effect per turn, and only once that turn.
target_text: -- Performapal
  local CARD_ID_0 = 21949879 --Performapal Gentrude
  local SETCARD_ID_0 = 0x9f --Performapal
  local SETCARD_ID_1 = 0x99 --Odd-Eyes
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.EnablePendulumAttribute(c)
  	--atk down
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.atkcon)
  	e1:SetCost(s.atkcost)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.drcost)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  	--pendulum set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.pencon)
  	e3:SetTarget(s.pentg)
  	e3:SetOperation(s.penop)
  	c:RegisterEffect(e3)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local a, d = Duel.GetBattleMonster(tp)
  	return a and d and d:IsFaceup()
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsDiscardable()
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, s.costfilter, 1, 1, REASON_COST + REASON_DISCARD, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetBattleMonster(1 - tp)
  	if tc and tc:IsRelateToBattle() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(-1000)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.drfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and not c:IsCode(id) and c:IsDiscardable()
  end
  function s.drcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable() and Duel.IsExistingMatchingCard(s.drfilter, tp, LOCATION_HAND, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local g = Duel.SelectMatchingCard(tp, s.drfilter, tp, LOCATION_HAND, 0, 1, 1, c)
  	g:AddCard(c)
  	Duel.SendtoGrave(g, REASON_COST + REASON_DISCARD)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 2)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(2)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 2)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.penfilter(c)
  	return (c:IsSetCard(SETCARD_ID_1) or c:IsCode(CARD_ID_0)) and c:IsFaceup()
  end
  function s.pencon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.penfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  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
  
  