name: Souleating
card_text: If this card is Normal or Special Summoned: You can take 1 Dinosaur monster from your Deck, and either add it to your hand or send it to the GY. You can target 1 other Level 4 or lower Dinosaur monster on the field; destroy it, then Special Summon 1 Dinosaur monster from your GY in Defense Position. You can only use each effect of "Souleating Oviraptor" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand or grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsRace(RACE_DINOSAUR) and (c:IsAbleToHand() or c:IsAbleToGrave())
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		local tc = g:GetFirst()
  		if tc and tc:IsAbleToHand() and (not tc:IsAbleToGrave() or Duel.SelectOption(tp, 1190, 1191) == 0) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			Duel.SendtoGrave(tc, REASON_EFFECT)
  		end
  	end
  end
  function s.desfilter(c, tp)
  	return c:IsFaceup() and c:IsLevelBelow(4) and c:IsRace(RACE_DINOSAUR) and Duel.GetMZoneCount(tp, c, tp) > 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_DINOSAUR) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.desfilter(chkc, tp) and chkc ~= c
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.desfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, c, tp) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.desfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, c, tp)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Destroy(tc, REASON_EFFECT) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		end
  	end
  end
  
  
source_text: Souleating
  If this card is Normal or Special Summoned: You can take 1 Dinosaur monster from your Deck, and either add it to your hand or send it to the GY. You can target 1 other Level 4 or lower Dinosaur monster on the field; destroy it, then Special Summon 1 Dinosaur monster from your GY in Defense Position. You can only use each effect of "Souleating Oviraptor" once per turn.
target_text: -- Souleating
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand or grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsRace(RACE_DINOSAUR) and (c:IsAbleToHand() or c:IsAbleToGrave())
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		local tc = g:GetFirst()
  		if tc and tc:IsAbleToHand() and (not tc:IsAbleToGrave() or Duel.SelectOption(tp, 1190, 1191) == 0) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			Duel.SendtoGrave(tc, REASON_EFFECT)
  		end
  	end
  end
  function s.desfilter(c, tp)
  	return c:IsFaceup() and c:IsLevelBelow(4) and c:IsRace(RACE_DINOSAUR) and Duel.GetMZoneCount(tp, c, tp) > 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_DINOSAUR) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.desfilter(chkc, tp) and chkc ~= c
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.desfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, c, tp) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.desfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, c, tp)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Destroy(tc, REASON_EFFECT) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		end
  	end
  end
  
  