name: Beetrooper
card_text: If this card is Normal or Special Summoned: You can target 2 of your "Beetrooper" monsters with different names, that are banished and/or in your GY; add them to your hand, but for the rest of this turn you cannot activate their effects, or the effects of cards with their names. When an opponent's monster declares an attack: You can return this card to the hand, and if you do, negate that attack. You can only use each effect of "Beetrooper Light Flapper" once per turn.
external_ids: local SETCARD_ID_0 = 0x170 --Beetrooper
  
lua: local SETCARD_ID_0 = 0x170 --Beetrooper
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--add
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.atkcon)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.thfilter(c, e)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand() and (not c:IsLocation(LOCATION_REMOVED) or c:IsFaceup()) and c:IsCanBeEffectTarget(e)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and s.thfilter(chkc, e)
  	end
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, nil, e)
  	if chk == 0 then
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	Duel.SetTargetCard(g1)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g1, #g1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) > 0 then
  		local tg = g:Filter(s.check, nil, tp)
  		if #tg <= 0 then
  			return
  		end
  		Duel.ConfirmCards(1 - tp, tg)
  		local code_table = {}
  		for tc in aux.Next(tg) do
  			local codes = { tc:GetCode() }
  			for i = 1, #codes do
  				table.insert(code_table, codes[i])
  			end
  		end
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  		e1:SetTargetRange(1, 0)
  		e1:SetLabel(table.unpack(code_table))
  		e1:SetValue(s.aclimit)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.check(c, tp)
  	return c:IsLocation(LOCATION_HAND) and c:IsControler(tp)
  end
  function s.aclimit(e, re, tp)
  	return re:GetHandler():IsCode(e:GetLabel())
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttacker()
  	return at:IsControler(1 - tp)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, c, 1, 0, 0)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SendtoHand(c, nil, REASON_EFFECT) > 0 and c:IsLocation(LOCATION_HAND) then
  		Duel.NegateAttack()
  	end
  end
  
  
source_text: Beetrooper
  If this card is Normal or Special Summoned: You can target 2 of your "Beetrooper" monsters with different names, that are banished and/or in your GY; add them to your hand, but for the rest of this turn you cannot activate their effects, or the effects of cards with their names. When an opponent's monster declares an attack: You can return this card to the hand, and if you do, negate that attack. You can only use each effect of "Beetrooper Light Flapper" once per turn.
target_text: -- Beetrooper
  local SETCARD_ID_0 = 0x170 --Beetrooper
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--add
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.atkcon)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.thfilter(c, e)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand() and (not c:IsLocation(LOCATION_REMOVED) or c:IsFaceup()) and c:IsCanBeEffectTarget(e)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and s.thfilter(chkc, e)
  	end
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, nil, e)
  	if chk == 0 then
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g1 = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	Duel.SetTargetCard(g1)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g1, #g1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) > 0 then
  		local tg = g:Filter(s.check, nil, tp)
  		if #tg <= 0 then
  			return
  		end
  		Duel.ConfirmCards(1 - tp, tg)
  		local code_table = {}
  		for tc in aux.Next(tg) do
  			local codes = { tc:GetCode() }
  			for i = 1, #codes do
  				table.insert(code_table, codes[i])
  			end
  		end
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  		e1:SetTargetRange(1, 0)
  		e1:SetLabel(table.unpack(code_table))
  		e1:SetValue(s.aclimit)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.check(c, tp)
  	return c:IsLocation(LOCATION_HAND) and c:IsControler(tp)
  end
  function s.aclimit(e, re, tp)
  	return re:GetHandler():IsCode(e:GetLabel())
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttacker()
  	return at:IsControler(1 - tp)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, c, 1, 0, 0)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SendtoHand(c, nil, REASON_EFFECT) > 0 and c:IsLocation(LOCATION_HAND) then
  		Duel.NegateAttack()
  	end
  end
  
  