name: Setuppercut
card_text: When a monster you control is destroyed by battle: Special Summon 1 monster from your hand or Deck with ATK less than or equal to that destroyed monster, in face-down Defense Position. You can only activate 1 "Setuppercut" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_BATTLE_DESTROYED)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:Filter(s.cfilter, nil, tp):GetFirst()
  	if not tc then
  		return false
  	end
  	local atk = tc:GetAttack()
  	if atk < 0 then
  		atk = 0
  	end
  	e:SetLabel(atk)
  	return true
  end
  function s.spfilter(c, e, tp, atk)
  	return c:IsAttackBelow(atk) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp, e:GetLabel())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp, e:GetLabel())
  	if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEDOWN_DEFENSE) ~= 0 then
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Setuppercut
  When a monster you control is destroyed by battle: Special Summon 1 monster from your hand or Deck with ATK less than or equal to that destroyed monster, in face-down Defense Position. You can only activate 1 "Setuppercut" per turn.
target_text: -- Setuppercut
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_BATTLE_DESTROYED)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:Filter(s.cfilter, nil, tp):GetFirst()
  	if not tc then
  		return false
  	end
  	local atk = tc:GetAttack()
  	if atk < 0 then
  		atk = 0
  	end
  	e:SetLabel(atk)
  	return true
  end
  function s.spfilter(c, e, tp, atk)
  	return c:IsAttackBelow(atk) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp, e:GetLabel())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp, e:GetLabel())
  	if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEDOWN_DEFENSE) ~= 0 then
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  