name: Painful
card_text: Send 1 Level 4 or lower Normal Monster from your Deck to the GY, and if you do, add 1 monster with the same name from your Deck to your hand. You can only activate 1 "Painful Decision" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOGRAVE + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.tgfilter(c, tp)
  	return c:IsLevelBelow(4) and c:IsType(TYPE_NORMAL) and c:IsAbleToGrave() and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, c, c:GetCode())
  end
  function s.thfilter(c, code)
  	return c:IsCode(code) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	local tc = g:GetFirst()
  	if tc and Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_GRAVE) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil, tc:GetCode())
  		if sg:GetCount() > 0 then
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  		end
  	end
  end
  
  
source_text: Painful
  Send 1 Level 4 or lower Normal Monster from your Deck to the GY, and if you do, add 1 monster with the same name from your Deck to your hand. You can only activate 1 "Painful Decision" per turn.
target_text: -- Painful
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOGRAVE + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.tgfilter(c, tp)
  	return c:IsLevelBelow(4) and c:IsType(TYPE_NORMAL) and c:IsAbleToGrave() and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, c, c:GetCode())
  end
  function s.thfilter(c, code)
  	return c:IsCode(code) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	local tc = g:GetFirst()
  	if tc and Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_GRAVE) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil, tc:GetCode())
  		if sg:GetCount() > 0 then
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  		end
  	end
  end
  
  