name: Catapult
card_text: Once per turn, if a monster you control would be destroyed by battle, you can send 1 Rock-Type monster from your Deck to the Graveyard instead.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.destg)
  	e2:SetValue(s.value)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.dfilter(c, tp)
  	return c:IsControler(tp) and c:IsReason(REASON_BATTLE)
  end
  function s.repfilter(c)
  	return c:IsRace(RACE_ROCK) and c:IsAbleToGrave()
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.dfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.repfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.value(e, c)
  	return c:IsControler(e:GetHandlerPlayer()) and c:IsReason(REASON_BATTLE)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.repfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_EFFECT)
  end
  
  
source_text: Catapult
  Once per turn, if a monster you control would be destroyed by battle, you can send 1 Rock-Type monster from your Deck to the Graveyard instead.
target_text: -- Catapult
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.destg)
  	e2:SetValue(s.value)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.dfilter(c, tp)
  	return c:IsControler(tp) and c:IsReason(REASON_BATTLE)
  end
  function s.repfilter(c)
  	return c:IsRace(RACE_ROCK) and c:IsAbleToGrave()
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.dfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.repfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.value(e, c)
  	return c:IsControler(e:GetHandlerPlayer()) and c:IsReason(REASON_BATTLE)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.repfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_EFFECT)
  end
  
  