name: Number
card_text: 2+ Level 4 monsters
  At the end of the Battle Phase, if this card destroyed an opponent's monster by battle: You can Special Summon from your Extra Deck, 1 Rank 10 or higher Machine Xyz Monster by using this face-up card you control as material. (This is treated as an Xyz Summon. Transfer its materials to the Summoned monster.) You can only use this effect of "Number 27: Dreadnought Dreadnoid" once per turn. If this face-up card on the field would be destroyed by battle or card effect, you can detach 1 material from this card instead.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	c:EnableReviveLimit()
  	aux.AddXyzProcedure(c, nil, 4, 2, nil, nil, 99)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.reptg)
  	c:RegisterEffect(e3)
  end
  aux.xyz_number[id] = 27
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.filter(c, e, tp, mc)
  	return c:IsRankAbove(10)
  		and c:IsRace(RACE_MACHINE)
  		and mc:IsCanBeXyzMaterial(c)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_XYZ, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) and c:IsControler(tp) and not c:IsImmuneToEffect(e) and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, c)
  		local tc = g:GetFirst()
  		if tc then
  			local mg = c:GetOverlayGroup()
  			if mg:GetCount() ~= 0 then
  				Duel.Overlay(tc, mg)
  			end
  			tc:SetMaterial(Group.FromCards(c))
  			Duel.Overlay(tc, Group.FromCards(c))
  			Duel.SpecialSummon(tc, SUMMON_TYPE_XYZ, tp, tp, false, false, POS_FACEUP)
  			tc:CompleteProcedure()
  		end
  	end
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE) and c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  		return true
  	else
  		return false
  	end
  end
  
  
source_text: Number
  2+ Level 4 monsters
  At the end of the Battle Phase, if this card destroyed an opponent's monster by battle: You can Special Summon from your Extra Deck, 1 Rank 10 or higher Machine Xyz Monster by using this face-up card you control as material. (This is treated as an Xyz Summon. Transfer its materials to the Summoned monster.) You can only use this effect of "Number 27: Dreadnought Dreadnoid" once per turn. If this face-up card on the field would be destroyed by battle or card effect, you can detach 1 material from this card instead.
target_text: -- Number
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	c:EnableReviveLimit()
  	aux.AddXyzProcedure(c, nil, 4, 2, nil, nil, 99)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.reptg)
  	c:RegisterEffect(e3)
  end
  aux.xyz_number[id] = 27
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.filter(c, e, tp, mc)
  	return c:IsRankAbove(10)
  		and c:IsRace(RACE_MACHINE)
  		and mc:IsCanBeXyzMaterial(c)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_XYZ, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) and c:IsControler(tp) and not c:IsImmuneToEffect(e) and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, c)
  		local tc = g:GetFirst()
  		if tc then
  			local mg = c:GetOverlayGroup()
  			if mg:GetCount() ~= 0 then
  				Duel.Overlay(tc, mg)
  			end
  			tc:SetMaterial(Group.FromCards(c))
  			Duel.Overlay(tc, Group.FromCards(c))
  			Duel.SpecialSummon(tc, SUMMON_TYPE_XYZ, tp, tp, false, false, POS_FACEUP)
  			tc:CompleteProcedure()
  		end
  	end
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE) and c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  		return true
  	else
  		return false
  	end
  end
  
  