name: T.G.
card_text: All "T.G." monsters on the field become Machine monsters. During your Main Phase, you can Normal Summon 1 "T.G." monster, in addition to your Normal Summon/Set. (You can only gain this effect once per turn.) During your Main Phase: You can destroy 1 "T.G." monster in your hand or field, and if you do, add 1 "T.G." monster with a different name from your Deck or GY to your hand. You can only use this effect of "T.G. All Clear" once per turn.
external_ids: local SETCARD_ID_0 = 0x27 --T.G.
  
lua: local SETCARD_ID_0 = 0x27 --T.G.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change race
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CHANGE_RACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetValue(RACE_MACHINE)
  	c:RegisterEffect(e2)
  	--extra normal summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_HAND + LOCATION_MZONE, 0)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e3)
  	--search
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_DESTROY + CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetTarget(s.target)
  	e4:SetOperation(s.operation)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsFaceupEx() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, c:GetCode())
  end
  function s.filter(c, ...)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and (#{ ... } == 0 or not c:IsCode(...))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, nil, tp)
  	if chk == 0 then
  		return #g > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, 1, 1, nil, tp)
  	if Duel.Destroy(g, REASON_EFFECT) == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, g:GetFirst():GetCode())
  	if #sg > 0 then
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  
  
source_text: T.G.
  All "T.G." monsters on the field become Machine monsters. During your Main Phase, you can Normal Summon 1 "T.G." monster, in addition to your Normal Summon/Set. (You can only gain this effect once per turn.) During your Main Phase: You can destroy 1 "T.G." monster in your hand or field, and if you do, add 1 "T.G." monster with a different name from your Deck or GY to your hand. You can only use this effect of "T.G. All Clear" once per turn.
target_text: -- T.G.
  local SETCARD_ID_0 = 0x27 --T.G.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change race
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CHANGE_RACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetValue(RACE_MACHINE)
  	c:RegisterEffect(e2)
  	--extra normal summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_HAND + LOCATION_MZONE, 0)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e3)
  	--search
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_DESTROY + CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetTarget(s.target)
  	e4:SetOperation(s.operation)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsFaceupEx() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, c:GetCode())
  end
  function s.filter(c, ...)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and (#{ ... } == 0 or not c:IsCode(...))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, nil, tp)
  	if chk == 0 then
  		return #g > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, 1, 1, nil, tp)
  	if Duel.Destroy(g, REASON_EFFECT) == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, g:GetFirst():GetCode())
  	if #sg > 0 then
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  
  