name: Gimmick
card_text: 2 Machine monsters
  During your Main Phase, if you control this Link Summoned card: You can activate this effect; you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except Machine Xyz Monsters, also take 1 "Gimmick Puppet" monster from your Deck, and either add it to your hand or send it to the GY, then, if all monsters you control are "Gimmick Puppet" monsters (min. 1), you can Special Summon 1 "Gimmick Puppet" monster from your hand. You can only use this effect of "Gimmick Puppet Chimera Doll" once per turn.
external_ids: local SETCARD_ID_0 = 0x1083 --Gimmick
  
lua: local SETCARD_ID_0 = 0x1083 --Gimmick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkRace, RACE_MACHINE), 2, 2)
  	--tohand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DECKDES + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  end
  function s.thcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and (c:IsAbleToHand() or c:IsAbleToGrave())
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.cfilter(c)
  	return c:IsFacedown() or not c:IsSetCard(SETCARD_ID_0)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g1 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g1:GetCount() > 0 then
  		local tc = g1:GetFirst()
  		local res = false
  		if tc and tc:IsAbleToHand() and (not tc:IsAbleToGrave() or Duel.SelectOption(tp, 1190, 1191) == 0) then
  			if Duel.SendtoHand(tc, nil, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_HAND) then
  				Duel.ConfirmCards(1 - tp, tc)
  				res = true
  			end
  		else
  			if Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_GRAVE) then
  				res = true
  			end
  		end
  		local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp)
  		if res and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and not Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = g2:Select(tp, 1, 1, nil)
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.splimit(e, c)
  	return not (c:IsRace(RACE_MACHINE) and c:IsType(TYPE_XYZ)) and c:IsLocation(LOCATION_EXTRA)
  end
  
  
source_text: Gimmick
  2 Machine monsters
  During your Main Phase, if you control this Link Summoned card: You can activate this effect; you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except Machine Xyz Monsters, also take 1 "Gimmick Puppet" monster from your Deck, and either add it to your hand or send it to the GY, then, if all monsters you control are "Gimmick Puppet" monsters (min. 1), you can Special Summon 1 "Gimmick Puppet" monster from your hand. You can only use this effect of "Gimmick Puppet Chimera Doll" once per turn.
target_text: -- Gimmick
  local SETCARD_ID_0 = 0x1083 --Gimmick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkRace, RACE_MACHINE), 2, 2)
  	--tohand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DECKDES + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  end
  function s.thcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and (c:IsAbleToHand() or c:IsAbleToGrave())
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.cfilter(c)
  	return c:IsFacedown() or not c:IsSetCard(SETCARD_ID_0)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g1 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g1:GetCount() > 0 then
  		local tc = g1:GetFirst()
  		local res = false
  		if tc and tc:IsAbleToHand() and (not tc:IsAbleToGrave() or Duel.SelectOption(tp, 1190, 1191) == 0) then
  			if Duel.SendtoHand(tc, nil, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_HAND) then
  				Duel.ConfirmCards(1 - tp, tc)
  				res = true
  			end
  		else
  			if Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_GRAVE) then
  				res = true
  			end
  		end
  		local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp)
  		if res and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and not Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = g2:Select(tp, 1, 1, nil)
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.splimit(e, c)
  	return not (c:IsRace(RACE_MACHINE) and c:IsType(TYPE_XYZ)) and c:IsLocation(LOCATION_EXTRA)
  end
  
  