name: Imprudent
card_text: Your LP must be lower than your opponent's to activate and to resolve this effect.
  Activate 1 of these effects;
  ● Destroy 1 monster your opponent controls with ATK less than or equal to the difference in LP.
  ● Special Summon 1 monster from your GY with ATK less than or equal to the difference in LP.
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:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) < Duel.GetLP(1 - tp)
  end
  function s.desfilter(c, dif)
  	return c:IsAttackBelow(dif) and c:IsFaceup()
  end
  function s.spfilter(c, dif, e, tp)
  	return c:IsAttackBelow(dif) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local dif = Duel.GetLP(1 - tp) - Duel.GetLP(tp)
  	local c = e:GetHandler()
  	local b1 = Duel.IsExistingMatchingCard(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil, dif)
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, dif, e, tp)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local s = 0
  	if b1 and not b2 then
  		s = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	end
  	if not b1 and b2 then
  		s = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	if b1 and b2 then
  		s = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	end
  	e:SetLabel(s)
  	if s == 0 then
  		e:SetCategory(CATEGORY_DESTROY)
  		local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil, dif)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	end
  	if s == 1 then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local dif = Duel.GetLP(1 - tp) - Duel.GetLP(tp)
  	if dif <= 0 then
  		return
  	end
  	if e:GetLabel() == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, 0, LOCATION_MZONE, 1, 1, nil, dif)
  		if g:GetCount() > 0 then
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  	if e:GetLabel() == 1 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, dif, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  
  
source_text: Imprudent
  Your LP must be lower than your opponent's to activate and to resolve this effect.
  Activate 1 of these effects;
  ● Destroy 1 monster your opponent controls with ATK less than or equal to the difference in LP.
  ● Special Summon 1 monster from your GY with ATK less than or equal to the difference in LP.
target_text: -- Imprudent
  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:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) < Duel.GetLP(1 - tp)
  end
  function s.desfilter(c, dif)
  	return c:IsAttackBelow(dif) and c:IsFaceup()
  end
  function s.spfilter(c, dif, e, tp)
  	return c:IsAttackBelow(dif) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local dif = Duel.GetLP(1 - tp) - Duel.GetLP(tp)
  	local c = e:GetHandler()
  	local b1 = Duel.IsExistingMatchingCard(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil, dif)
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, dif, e, tp)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local s = 0
  	if b1 and not b2 then
  		s = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	end
  	if not b1 and b2 then
  		s = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	if b1 and b2 then
  		s = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	end
  	e:SetLabel(s)
  	if s == 0 then
  		e:SetCategory(CATEGORY_DESTROY)
  		local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil, dif)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	end
  	if s == 1 then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local dif = Duel.GetLP(1 - tp) - Duel.GetLP(tp)
  	if dif <= 0 then
  		return
  	end
  	if e:GetLabel() == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, 0, LOCATION_MZONE, 1, 1, nil, dif)
  		if g:GetCount() > 0 then
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  	if e:GetLabel() == 1 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, dif, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  
  