name: Performapal
card_text: When a card or effect is activated that would inflict damage to you (Quick Effect): You can discard this card; make that effect damage to you 0. During the Main Phase (Quick Effect): You can discard this card, then target 1 "Performapal" or "Odd-Eyes" card you control; this turn, it cannot be destroyed by battle or card effects.
external_ids: local SETCARD_ID_0 = 0x9f --Performapal
  
lua: local SETCARD_ID_0 = 0x9f --Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--no damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e1:SetCondition(aux.damcon1)
  	e1:SetCost(s.effcost)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCondition(s.condition2)
  	e2:SetCost(s.effcost)
  	e2:SetTarget(s.target2)
  	e2:SetOperation(s.operation2)
  	c:RegisterEffect(e2)
  end
  function s.effcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local cid = Duel.GetChainInfo(ev, CHAININFO_CHAIN_ID)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetLabel(cid)
  	e1:SetValue(s.damcon)
  	e1:SetReset(RESET_CHAIN)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.damcon(e, re, val, r, rp, rc)
  	local cc = Duel.GetCurrentChain()
  	if cc == 0 or bit.band(r, REASON_EFFECT) == 0 then
  		return
  	end
  	local cid = Duel.GetChainInfo(0, CHAININFO_CHAIN_ID)
  	if cid == e:GetLabel() then
  		return 0
  	end
  	return val
  end
  function s.condition2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0, 0x99)
  end
  function s.target2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsOnField() and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  end
  function s.operation2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  		tc:RegisterEffect(e2)
  	end
  end
  
  
source_text: Performapal
  When a card or effect is activated that would inflict damage to you (Quick Effect): You can discard this card; make that effect damage to you 0. During the Main Phase (Quick Effect): You can discard this card, then target 1 "Performapal" or "Odd-Eyes" card you control; this turn, it cannot be destroyed by battle or card effects.
target_text: -- Performapal
  local SETCARD_ID_0 = 0x9f --Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--no damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e1:SetCondition(aux.damcon1)
  	e1:SetCost(s.effcost)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCondition(s.condition2)
  	e2:SetCost(s.effcost)
  	e2:SetTarget(s.target2)
  	e2:SetOperation(s.operation2)
  	c:RegisterEffect(e2)
  end
  function s.effcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local cid = Duel.GetChainInfo(ev, CHAININFO_CHAIN_ID)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetLabel(cid)
  	e1:SetValue(s.damcon)
  	e1:SetReset(RESET_CHAIN)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.damcon(e, re, val, r, rp, rc)
  	local cc = Duel.GetCurrentChain()
  	if cc == 0 or bit.band(r, REASON_EFFECT) == 0 then
  		return
  	end
  	local cid = Duel.GetChainInfo(0, CHAININFO_CHAIN_ID)
  	if cid == e:GetLabel() then
  		return 0
  	end
  	return val
  end
  function s.condition2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0, 0x99)
  end
  function s.target2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsOnField() and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  end
  function s.operation2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  		tc:RegisterEffect(e2)
  	end
  end
  
  