name: Bait
card_text: Target 1 Set card in the Spell & Trap Card Zone; reveal that target, force its activation if it is a Trap Card, then negate its effect if the activation timing is incorrect, and if you do, destroy it. (If it is not a Trap Card, return it face-down.) When this card resolves, shuffle it into the Deck instead of sending it to the Graveyard.
external_ids: local CARD_ID_0 = 4130270 --G.B. Hunter
  
lua: local CARD_ID_0 = 4130270 --G.B. Hunter
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c)
  	return c:IsFacedown() and c:GetSequence() ~= 5
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_SZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.IsExistingTarget(s.filter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, e:GetHandler())
  	end
  	e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEDOWN)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, 1, e:GetHandler())
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) or tc:IsFaceup() then
  		if c:IsRelateToEffect(e) and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  			Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT, tp, true)
  		end
  		return
  	end
  	Duel.ConfirmCards(tp, tc)
  	if tc:IsType(TYPE_TRAP) then
  		local te = tc:GetActivateEffect()
  		local tep = tc:GetControler()
  		if not te then
  			Duel.ChangePosition(tc, POS_FACEUP)
  			if Duel.Destroy(tc, REASON_EFFECT) == 0 then
  				Duel.SendtoGrave(tc, REASON_RULE)
  			end
  		else
  			local condition = te:GetCondition()
  			local cost = te:GetCost()
  			local target = te:GetTarget()
  			local operation = te:GetOperation()
  			if
  				te:GetCode() == EVENT_FREE_CHAIN
  				and te:IsActivatable(tep)
  				and (not condition or condition(te, tep, eg, ep, ev, re, r, rp))
  				and (not cost or cost(te, tep, eg, ep, ev, re, r, rp, 0))
  				and (not target or target(te, tep, eg, ep, ev, re, r, rp, 0))
  			then
  				Duel.ClearTargetCard()
  				e:SetProperty(te:GetProperty())
  				Duel.Hint(HINT_CARD, 0, tc:GetOriginalCode())
  				Duel.ChangePosition(tc, POS_FACEUP)
  				if tc:GetType() == TYPE_TRAP then
  					tc:CancelToGrave(false)
  				end
  				tc:CreateEffectRelation(te)
  				if cost then
  					cost(te, tep, eg, ep, ev, re, r, rp, 1)
  				end
  				if target then
  					target(te, tep, eg, ep, ev, re, r, rp, 1)
  				end
  				local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  				local tg = g:GetFirst()
  				while tg do
  					tg:CreateEffectRelation(te)
  					tg = g:GetNext()
  				end
  				if operation then
  					operation(te, tep, eg, ep, ev, re, r, rp)
  				end
  				tc:ReleaseEffectRelation(te)
  				tg = g:GetFirst()
  				while tg do
  					tg:ReleaseEffectRelation(te)
  					tg = g:GetNext()
  				end
  			else
  				if Duel.Destroy(tc, REASON_EFFECT) == 0 then
  					Duel.SendtoGrave(tc, REASON_RULE)
  				end
  			end
  		end
  	end
  	if c:IsRelateToEffect(e) and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT, tp, true)
  	end
  end
  
  
source_text: Bait
  Target 1 Set card in the Spell & Trap Card Zone; reveal that target, force its activation if it is a Trap Card, then negate its effect if the activation timing is incorrect, and if you do, destroy it. (If it is not a Trap Card, return it face-down.) When this card resolves, shuffle it into the Deck instead of sending it to the Graveyard.
target_text: -- Bait
  local CARD_ID_0 = 4130270 --G.B. Hunter
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c)
  	return c:IsFacedown() and c:GetSequence() ~= 5
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_SZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.IsExistingTarget(s.filter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, e:GetHandler())
  	end
  	e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEDOWN)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, 1, e:GetHandler())
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) or tc:IsFaceup() then
  		if c:IsRelateToEffect(e) and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  			Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT, tp, true)
  		end
  		return
  	end
  	Duel.ConfirmCards(tp, tc)
  	if tc:IsType(TYPE_TRAP) then
  		local te = tc:GetActivateEffect()
  		local tep = tc:GetControler()
  		if not te then
  			Duel.ChangePosition(tc, POS_FACEUP)
  			if Duel.Destroy(tc, REASON_EFFECT) == 0 then
  				Duel.SendtoGrave(tc, REASON_RULE)
  			end
  		else
  			local condition = te:GetCondition()
  			local cost = te:GetCost()
  			local target = te:GetTarget()
  			local operation = te:GetOperation()
  			if
  				te:GetCode() == EVENT_FREE_CHAIN
  				and te:IsActivatable(tep)
  				and (not condition or condition(te, tep, eg, ep, ev, re, r, rp))
  				and (not cost or cost(te, tep, eg, ep, ev, re, r, rp, 0))
  				and (not target or target(te, tep, eg, ep, ev, re, r, rp, 0))
  			then
  				Duel.ClearTargetCard()
  				e:SetProperty(te:GetProperty())
  				Duel.Hint(HINT_CARD, 0, tc:GetOriginalCode())
  				Duel.ChangePosition(tc, POS_FACEUP)
  				if tc:GetType() == TYPE_TRAP then
  					tc:CancelToGrave(false)
  				end
  				tc:CreateEffectRelation(te)
  				if cost then
  					cost(te, tep, eg, ep, ev, re, r, rp, 1)
  				end
  				if target then
  					target(te, tep, eg, ep, ev, re, r, rp, 1)
  				end
  				local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  				local tg = g:GetFirst()
  				while tg do
  					tg:CreateEffectRelation(te)
  					tg = g:GetNext()
  				end
  				if operation then
  					operation(te, tep, eg, ep, ev, re, r, rp)
  				end
  				tc:ReleaseEffectRelation(te)
  				tg = g:GetFirst()
  				while tg do
  					tg:ReleaseEffectRelation(te)
  					tg = g:GetNext()
  				end
  			else
  				if Duel.Destroy(tc, REASON_EFFECT) == 0 then
  					Duel.SendtoGrave(tc, REASON_RULE)
  				end
  			end
  		end
  	end
  	if c:IsRelateToEffect(e) and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT, tp, true)
  	end
  end
  
  