name: Infinitrack
card_text: If this card is Normal or Special Summoned: You can Special Summon 1 EARTH Machine monster from your hand in Defense Position, except "Infinitrack Anchor Drill". You can target 1 other Machine monster you control; the Levels of both that monster and this card become the combined original Levels of those 2 monsters, until the end of this turn. You can only use each effect of "Infinitrack Anchor Drill" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--lv change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetTarget(s.lvtg)
  	e3:SetOperation(s.lvop)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_MACHINE) and c:IsAttribute(ATTRIBUTE_EARTH) and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  function s.lvfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE) and c:IsLevelAbove(0)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsControler(tp) and chkc ~= c and chkc:IsLocation(LOCATION_MZONE) and s.lvfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, c)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		local lv = c:GetOriginalLevel() + tc:GetOriginalLevel()
  		s.setlv(c, c, lv)
  		s.setlv(c, tc, lv)
  	end
  end
  function s.setlv(c, ec, lv)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CHANGE_LEVEL)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	e1:SetValue(lv)
  	ec:RegisterEffect(e1)
  end
  
  
source_text: Infinitrack
  If this card is Normal or Special Summoned: You can Special Summon 1 EARTH Machine monster from your hand in Defense Position, except "Infinitrack Anchor Drill". You can target 1 other Machine monster you control; the Levels of both that monster and this card become the combined original Levels of those 2 monsters, until the end of this turn. You can only use each effect of "Infinitrack Anchor Drill" once per turn.
target_text: -- Infinitrack
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--lv change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetTarget(s.lvtg)
  	e3:SetOperation(s.lvop)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_MACHINE) and c:IsAttribute(ATTRIBUTE_EARTH) and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  function s.lvfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE) and c:IsLevelAbove(0)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsControler(tp) and chkc ~= c and chkc:IsLocation(LOCATION_MZONE) and s.lvfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, c)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		local lv = c:GetOriginalLevel() + tc:GetOriginalLevel()
  		s.setlv(c, c, lv)
  		s.setlv(c, tc, lv)
  	end
  end
  function s.setlv(c, ec, lv)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CHANGE_LEVEL)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	e1:SetValue(lv)
  	ec:RegisterEffect(e1)
  end
  
  