name: Booby
card_text: Discard 1 card; Set 1 Continuous Trap Card from your hand or Graveyard to your field. That Set card can be activated during this turn.
lua: 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)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, tp)
  	return c:IsDiscardable() and ((s.filter2(c) and c:IsAbleToGraveAsCost()) or Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, c))
  end
  function s.filter2(c)
  	return c:GetType() == TYPE_TRAP + TYPE_CONTINUOUS and c:IsSSetable()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_HAND, 0, 1, nil, tp)
  	end
  	Duel.DiscardHand(tp, s.filter1, 1, 1, REASON_COST + REASON_DISCARD, nil, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ct = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		if e:IsHasType(EFFECT_TYPE_ACTIVATE) and not e:GetHandler():IsLocation(LOCATION_SZONE) then
  			ct = ct - 1
  		end
  		return ct > 0 and (e:IsCostChecked() or Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil))
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter2), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc and Duel.SSet(tp, tc) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetDescription(aux.Stringid(id, 0))
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_TRAP_ACT_IN_SET_TURN)
  		e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Booby
  Discard 1 card; Set 1 Continuous Trap Card from your hand or Graveyard to your field. That Set card can be activated during this turn.
target_text: -- Booby
  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)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, tp)
  	return c:IsDiscardable() and ((s.filter2(c) and c:IsAbleToGraveAsCost()) or Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, c))
  end
  function s.filter2(c)
  	return c:GetType() == TYPE_TRAP + TYPE_CONTINUOUS and c:IsSSetable()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_HAND, 0, 1, nil, tp)
  	end
  	Duel.DiscardHand(tp, s.filter1, 1, 1, REASON_COST + REASON_DISCARD, nil, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ct = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		if e:IsHasType(EFFECT_TYPE_ACTIVATE) and not e:GetHandler():IsLocation(LOCATION_SZONE) then
  			ct = ct - 1
  		end
  		return ct > 0 and (e:IsCostChecked() or Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil))
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter2), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc and Duel.SSet(tp, tc) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetDescription(aux.Stringid(id, 0))
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_TRAP_ACT_IN_SET_TURN)
  		e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  
  