name: Infinitrack
card_text: 2 Level 7 monsters
  When this card destroys an opponent's monster by battle: You can attach that monster to this card as material. You can only use each of the following effects of "Infinitrack Mountain Smasher" once per turn.
  ● You can detach 1 material from this card; it gains 1000 ATK.
  ● If this card is in your GY: You can Tribute 1 Machine Link Monster; Special Summon this card in Defense Position.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	c:EnableReviveLimit()
  	aux.AddXyzProcedure(c, nil, 7, 2)
  	--attack up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1, id)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCost(s.atkcost)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--Attach
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetCondition(s.xyzcon)
  	e2:SetTarget(s.xyztg)
  	e2:SetOperation(s.xyzop)
  	c:RegisterEffect(e2)
  	--SpecialSummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCost(s.spcost)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(1000)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.xyzcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetBattleTarget()
  	if not c:IsRelateToBattle() then
  		return false
  	end
  	e:SetLabelObject(tc)
  	return tc and tc:IsType(TYPE_MONSTER) and tc:IsReason(REASON_BATTLE) and tc:IsCanOverlay() and (tc:IsLocation(LOCATION_GRAVE) or tc:IsFaceup() and tc:IsLocation(LOCATION_EXTRA + LOCATION_REMOVED))
  end
  function s.xyztg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsType(TYPE_XYZ)
  	end
  	local tc = e:GetLabelObject()
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, tc, 1, 0, 0)
  end
  function s.xyzop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsCanOverlay() then
  		Duel.Overlay(c, tc)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsType(TYPE_LINK) and c:IsRace(RACE_MACHINE) and Duel.GetMZoneCount(tp, c) > 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, tp)
  	Duel.Release(g, REASON_COST)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: Infinitrack
  2 Level 7 monsters
  When this card destroys an opponent's monster by battle: You can attach that monster to this card as material. You can only use each of the following effects of "Infinitrack Mountain Smasher" once per turn.
  ● You can detach 1 material from this card; it gains 1000 ATK.
  ● If this card is in your GY: You can Tribute 1 Machine Link Monster; Special Summon this card in Defense Position.
target_text: -- Infinitrack
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	c:EnableReviveLimit()
  	aux.AddXyzProcedure(c, nil, 7, 2)
  	--attack up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1, id)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCost(s.atkcost)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--Attach
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetCondition(s.xyzcon)
  	e2:SetTarget(s.xyztg)
  	e2:SetOperation(s.xyzop)
  	c:RegisterEffect(e2)
  	--SpecialSummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCost(s.spcost)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(1000)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.xyzcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetBattleTarget()
  	if not c:IsRelateToBattle() then
  		return false
  	end
  	e:SetLabelObject(tc)
  	return tc and tc:IsType(TYPE_MONSTER) and tc:IsReason(REASON_BATTLE) and tc:IsCanOverlay() and (tc:IsLocation(LOCATION_GRAVE) or tc:IsFaceup() and tc:IsLocation(LOCATION_EXTRA + LOCATION_REMOVED))
  end
  function s.xyztg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsType(TYPE_XYZ)
  	end
  	local tc = e:GetLabelObject()
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, tc, 1, 0, 0)
  end
  function s.xyzop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsCanOverlay() then
  		Duel.Overlay(c, tc)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsType(TYPE_LINK) and c:IsRace(RACE_MACHINE) and Duel.GetMZoneCount(tp, c) > 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.cfilter, 1, nil, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.cfilter, 1, 1, nil, tp)
  	Duel.Release(g, REASON_COST)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  