name: Terrors
card_text: Target 1 card your opponent controls and 1 card in their GY; send that card on the field to the GY, and if you do, Set the other card from the GY to your opponent's field. You can only activate 1 "Terrors of the Overroot" per 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:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.tgfilter(c, e, tp)
  	return c:IsAbleToGrave() and Duel.IsExistingTarget(s.setfilter, tp, 0, LOCATION_GRAVE, 1, nil, c, e, tp)
  end
  function s.setfilter(c, cc, e, tp)
  	local b1 = Duel.GetMZoneCount(1 - tp, cc, tp) > 0
  	local b2 = Duel.GetSZoneCount(1 - tp, cc, tp) > 0
  	return b1 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE, 1 - tp) or (b2 or c:IsType(TYPE_FIELD)) and c:IsSSetable(true)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tgfilter, tp, 0, LOCATION_ONFIELD, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g1 = Duel.SelectTarget(tp, s.tgfilter, tp, 0, LOCATION_ONFIELD, 1, 1, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g2 = Duel.SelectTarget(tp, s.setfilter, tp, 0, LOCATION_GRAVE, 1, 1, nil, g1:GetFirst(), e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g1, 1, 0, 0)
  	if g2:GetFirst():IsType(TYPE_MONSTER) then
  		e:SetCategory(CATEGORY_TOGRAVE + CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g2, 1, 0, 0)
  	else
  		e:SetCategory(CATEGORY_TOGRAVE)
  		Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g2, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetTargetsRelateToChain()
  	local tc1 = tg:Filter(Card.IsLocation, nil, LOCATION_ONFIELD):GetFirst()
  	local tc2 = tg:Filter(Card.IsLocation, nil, LOCATION_GRAVE):GetFirst()
  	if tc1 and Duel.SendtoGrave(tc1, REASON_EFFECT) ~= 0 and tc1:IsLocation(LOCATION_GRAVE) and tc2 then
  		if tc2:IsType(TYPE_MONSTER) then
  			Duel.SpecialSummon(tc2, 0, tp, 1 - tp, false, false, POS_FACEDOWN_DEFENSE)
  		else
  			Duel.SSet(tp, tc2, 1 - tp)
  		end
  	end
  end
  
  
source_text: Terrors
  Target 1 card your opponent controls and 1 card in their GY; send that card on the field to the GY, and if you do, Set the other card from the GY to your opponent's field. You can only activate 1 "Terrors of the Overroot" per turn.
target_text: -- Terrors
  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:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.tgfilter(c, e, tp)
  	return c:IsAbleToGrave() and Duel.IsExistingTarget(s.setfilter, tp, 0, LOCATION_GRAVE, 1, nil, c, e, tp)
  end
  function s.setfilter(c, cc, e, tp)
  	local b1 = Duel.GetMZoneCount(1 - tp, cc, tp) > 0
  	local b2 = Duel.GetSZoneCount(1 - tp, cc, tp) > 0
  	return b1 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE, 1 - tp) or (b2 or c:IsType(TYPE_FIELD)) and c:IsSSetable(true)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tgfilter, tp, 0, LOCATION_ONFIELD, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g1 = Duel.SelectTarget(tp, s.tgfilter, tp, 0, LOCATION_ONFIELD, 1, 1, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g2 = Duel.SelectTarget(tp, s.setfilter, tp, 0, LOCATION_GRAVE, 1, 1, nil, g1:GetFirst(), e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g1, 1, 0, 0)
  	if g2:GetFirst():IsType(TYPE_MONSTER) then
  		e:SetCategory(CATEGORY_TOGRAVE + CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g2, 1, 0, 0)
  	else
  		e:SetCategory(CATEGORY_TOGRAVE)
  		Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g2, 1, 0, 0)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetTargetsRelateToChain()
  	local tc1 = tg:Filter(Card.IsLocation, nil, LOCATION_ONFIELD):GetFirst()
  	local tc2 = tg:Filter(Card.IsLocation, nil, LOCATION_GRAVE):GetFirst()
  	if tc1 and Duel.SendtoGrave(tc1, REASON_EFFECT) ~= 0 and tc1:IsLocation(LOCATION_GRAVE) and tc2 then
  		if tc2:IsType(TYPE_MONSTER) then
  			Duel.SpecialSummon(tc2, 0, tp, 1 - tp, false, false, POS_FACEDOWN_DEFENSE)
  		else
  			Duel.SSet(tp, tc2, 1 - tp)
  		end
  	end
  end
  
  