name: Number
card_text: 2 Level 3 monsters
  Neither player can target this card on the field with card effects. If this card would be destroyed by battle or card effect, you can detach 1 material from this card instead. Once per turn, during your Standby Phase: Gain 500 LP. If this card is sent from the field to the GY: Target 2 Level 3 monsters in your GY; shuffle them both into the Deck, and if you do, return this card from your GY to the Extra Deck. You can only use this effect of "Number 49: Fortune Tune" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 3, 2)
  	c:EnableReviveLimit()
  	--lpup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCategory(CATEGORY_RECOVER)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.reccon)
  	e1:SetTarget(s.rectg)
  	e1:SetOperation(s.recop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.reptg)
  	c:RegisterEffect(e3)
  	--todeck
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_TODECK + CATEGORY_TOEXTRA)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetCountLimit(1, id)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetCondition(s.tdcon)
  	e4:SetTarget(s.tdtg)
  	e4:SetOperation(s.tdop)
  	c:RegisterEffect(e4)
  end
  aux.xyz_number[id] = 49
  function s.reccon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.rectg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(500)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, 500)
  end
  function s.recop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Recover(p, d, REASON_EFFECT)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		c:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  		return true
  	else
  		return false
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.filter(c, e)
  	return c:IsLevel(3) and c:IsCanBeEffectTarget(e) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc, e)
  	end
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil, e)
  	if g:GetCount() >= 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local sg = g:Select(tp, 2, 2, nil)
  		Duel.SetTargetCard(sg)
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, sg, 2, 0, 0)
  		Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, e:GetHandler(), 1, 0, 0)
  	end
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	if not g then
  		return
  	end
  	local tg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() ~= 2 then
  		return
  	end
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  
source_text: Number
  2 Level 3 monsters
  Neither player can target this card on the field with card effects. If this card would be destroyed by battle or card effect, you can detach 1 material from this card instead. Once per turn, during your Standby Phase: Gain 500 LP. If this card is sent from the field to the GY: Target 2 Level 3 monsters in your GY; shuffle them both into the Deck, and if you do, return this card from your GY to the Extra Deck. You can only use this effect of "Number 49: Fortune Tune" once per turn.
target_text: -- Number
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 3, 2)
  	c:EnableReviveLimit()
  	--lpup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCategory(CATEGORY_RECOVER)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.reccon)
  	e1:SetTarget(s.rectg)
  	e1:SetOperation(s.recop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.reptg)
  	c:RegisterEffect(e3)
  	--todeck
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_TODECK + CATEGORY_TOEXTRA)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetCountLimit(1, id)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetCondition(s.tdcon)
  	e4:SetTarget(s.tdtg)
  	e4:SetOperation(s.tdop)
  	c:RegisterEffect(e4)
  end
  aux.xyz_number[id] = 49
  function s.reccon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.rectg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(500)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, 500)
  end
  function s.recop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Recover(p, d, REASON_EFFECT)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		c:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  		return true
  	else
  		return false
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.filter(c, e)
  	return c:IsLevel(3) and c:IsCanBeEffectTarget(e) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc, e)
  	end
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil, e)
  	if g:GetCount() >= 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local sg = g:Select(tp, 2, 2, nil)
  		Duel.SetTargetCard(sg)
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, sg, 2, 0, 0)
  		Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, e:GetHandler(), 1, 0, 0)
  	end
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	if not g then
  		return
  	end
  	local tg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() ~= 2 then
  		return
  	end
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  