name: Beetrooper
card_text: When your opponent activates a monster effect, while you control a "Beetrooper" monster: Negate the activation, and if you do, destroy it. During your End Phase, if this card is in your GY and you control an Insect monster with 3000 or more ATK: You can banish 1 Insect monster from your GY; Set this card. You can only use 1 "Beetrooper Fly & Sting" effect per turn, and only once that 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)
  	--negate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.setcon)
  	e2:SetCost(s.setcost)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter1(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp ~= tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainNegatable(ev) and Duel.IsExistingMatchingCard(s.cfilter1, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  function s.cfilter2(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT) and c:IsAttackAbove(3000)
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp and Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.costfilter(c)
  	return c:IsRace(RACE_INSECT) and c:IsAbleToRemoveAsCost()
  end
  function s.setcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, c, 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  
source_text: Beetrooper
  When your opponent activates a monster effect, while you control a "Beetrooper" monster: Negate the activation, and if you do, destroy it. During your End Phase, if this card is in your GY and you control an Insect monster with 3000 or more ATK: You can banish 1 Insect monster from your GY; Set this card. You can only use 1 "Beetrooper Fly & Sting" effect per turn, and only once that turn.
target_text: -- Beetrooper
  local SETCARD_ID_0 = 0x170 --Beetrooper
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--negate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.setcon)
  	e2:SetCost(s.setcost)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter1(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp ~= tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainNegatable(ev) and Duel.IsExistingMatchingCard(s.cfilter1, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  function s.cfilter2(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT) and c:IsAttackAbove(3000)
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp and Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.costfilter(c)
  	return c:IsRace(RACE_INSECT) and c:IsAbleToRemoveAsCost()
  end
  function s.setcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, c, 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  