name: Machine
card_text: Special Summon this card as an Effect Monster (Machine/EARTH/Level 4/ATK 1000/DEF 1000). (This card is also still a Trap.) If Summoned this way, once per turn, during your Main Phase: You can Tribute 1 Machine monster; this card gains ATK equal to the ATK the Tributed monster had on the field, until the end of this turn. You cannot Normal or Special Summon other monsters the turn you activate this card.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--atkup
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.atkcon)
  	e2:SetCost(s.atkcost)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetActivityCount(tp, ACTIVITY_SUMMON) == 0 and Duel.GetActivityCount(tp, ACTIVITY_SPSUMMON) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTargetRange(1, 0)
  	e1:SetLabelObject(e)
  	e1:SetTarget(s.sumlimit)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e2:SetCode(EFFECT_CANNOT_SUMMON)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	e2:SetTargetRange(1, 0)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.sumlimit(e, c, sump, sumtype, sumpos, targetp, se)
  	return e:GetLabelObject() ~= se
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:IsCostChecked()
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_MACHINE, ATTRIBUTE_EARTH)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_MACHINE, ATTRIBUTE_EARTH) then
  		return
  	end
  	c:AddMonsterAttribute(TYPE_EFFECT + TYPE_TRAP)
  	Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, true, false, POS_FACEUP)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsRace, 1, e:GetHandler(), RACE_MACHINE)
  	end
  	local g = Duel.SelectReleaseGroup(tp, Card.IsRace, 1, 1, e:GetHandler(), RACE_MACHINE)
  	e:SetLabel(g:GetFirst():GetAttack())
  	Duel.Release(g, REASON_COST)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFacedown() or not c:IsRelateToEffect(e) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(e:GetLabel())
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	c:RegisterEffect(e1)
  end
  
  
source_text: Machine
  Special Summon this card as an Effect Monster (Machine/EARTH/Level 4/ATK 1000/DEF 1000). (This card is also still a Trap.) If Summoned this way, once per turn, during your Main Phase: You can Tribute 1 Machine monster; this card gains ATK equal to the ATK the Tributed monster had on the field, until the end of this turn. You cannot Normal or Special Summon other monsters the turn you activate this card.
target_text: -- Machine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--atkup
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.atkcon)
  	e2:SetCost(s.atkcost)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetActivityCount(tp, ACTIVITY_SUMMON) == 0 and Duel.GetActivityCount(tp, ACTIVITY_SPSUMMON) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTargetRange(1, 0)
  	e1:SetLabelObject(e)
  	e1:SetTarget(s.sumlimit)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e2:SetCode(EFFECT_CANNOT_SUMMON)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	e2:SetTargetRange(1, 0)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.sumlimit(e, c, sump, sumtype, sumpos, targetp, se)
  	return e:GetLabelObject() ~= se
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:IsCostChecked()
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_MACHINE, ATTRIBUTE_EARTH)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_MACHINE, ATTRIBUTE_EARTH) then
  		return
  	end
  	c:AddMonsterAttribute(TYPE_EFFECT + TYPE_TRAP)
  	Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, true, false, POS_FACEUP)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsRace, 1, e:GetHandler(), RACE_MACHINE)
  	end
  	local g = Duel.SelectReleaseGroup(tp, Card.IsRace, 1, 1, e:GetHandler(), RACE_MACHINE)
  	e:SetLabel(g:GetFirst():GetAttack())
  	Duel.Release(g, REASON_COST)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFacedown() or not c:IsRelateToEffect(e) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(e:GetLabel())
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	c:RegisterEffect(e1)
  end
  
  