name: Painful
card_text: Tribute 1 monster; add 1 monster with the same original Type, Attribute, and Level, but with a different original name, from your Deck or Graveyard to your hand.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetLabel(0)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cfilter(c, tp)
  	return c:GetOriginalLevel() > 0 and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, c)
  end
  function s.thfilter(c, tc)
  	return c:IsType(TYPE_MONSTER)
  		and c:GetOriginalLevel() == tc:GetOriginalLevel()
  		and c:GetOriginalRace() == tc:GetOriginalRace()
  		and c:GetOriginalAttribute() == tc:GetOriginalAttribute()
  		and not c:IsOriginalCodeRule(tc:GetOriginalCodeRule())
  		and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, tp)
  	e:SetLabelObject(g:GetFirst())
  	Duel.Release(g, REASON_COST)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, tc)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Painful
  Tribute 1 monster; add 1 monster with the same original Type, Attribute, and Level, but with a different original name, from your Deck or Graveyard to your hand.
target_text: -- Painful
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetLabel(0)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cfilter(c, tp)
  	return c:GetOriginalLevel() > 0 and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, c)
  end
  function s.thfilter(c, tc)
  	return c:IsType(TYPE_MONSTER)
  		and c:GetOriginalLevel() == tc:GetOriginalLevel()
  		and c:GetOriginalRace() == tc:GetOriginalRace()
  		and c:GetOriginalAttribute() == tc:GetOriginalAttribute()
  		and not c:IsOriginalCodeRule(tc:GetOriginalCodeRule())
  		and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, tp)
  	e:SetLabelObject(g:GetFirst())
  	Duel.Release(g, REASON_COST)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, tc)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  