name: Wightbaking
card_text: This card's name becomes "Skull Servant" while in the GY. If a Level 3 or lower Zombie monster(s) you control would be destroyed by battle or card effect, you can discard this card, instead. If this card is sent to the GY: You can add 2 monsters with different names from your Deck to your hand, except "Wightbaking", that are either "Skull Servant" or mention it, then discard 1 card. You can only use this effect of "Wightbaking" once per turn.
external_ids: local CARD_ID_0 = 32274490 --Skull Servant
  
lua: local CARD_ID_0 = 32274490 --Skull Servant
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_0, LOCATION_GRAVE)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_HANDES)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsLevelBelow(3)
  		and c:IsRace(RACE_ZOMBIE)
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsReason(REASON_EFFECT + REASON_BATTLE)
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable() and not c:IsStatus(STATUS_DESTROY_CONFIRMED) and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SendtoGrave(e:GetHandler(), REASON_EFFECT + REASON_DISCARD)
  end
  function s.thfilter(c)
  	return aux.IsCodeOrListed(c, CARD_ID_0) and not c:IsCode(id) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tg1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	Duel.SendtoHand(tg1, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, tg1)
  	Duel.ShuffleHand(tp)
  	Duel.BreakEffect()
  	Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  end
  
  
source_text: Wightbaking
  This card's name becomes "Skull Servant" while in the GY. If a Level 3 or lower Zombie monster(s) you control would be destroyed by battle or card effect, you can discard this card, instead. If this card is sent to the GY: You can add 2 monsters with different names from your Deck to your hand, except "Wightbaking", that are either "Skull Servant" or mention it, then discard 1 card. You can only use this effect of "Wightbaking" once per turn.
target_text: -- Wightbaking
  local CARD_ID_0 = 32274490 --Skull Servant
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_0, LOCATION_GRAVE)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_HANDES)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsLevelBelow(3)
  		and c:IsRace(RACE_ZOMBIE)
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsReason(REASON_EFFECT + REASON_BATTLE)
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable() and not c:IsStatus(STATUS_DESTROY_CONFIRMED) and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SendtoGrave(e:GetHandler(), REASON_EFFECT + REASON_DISCARD)
  end
  function s.thfilter(c)
  	return aux.IsCodeOrListed(c, CARD_ID_0) and not c:IsCode(id) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tg1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	Duel.SendtoHand(tg1, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, tg1)
  	Duel.ShuffleHand(tp)
  	Duel.BreakEffect()
  	Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  end
  
  