name: Stardust
card_text: When an opponent's Special Summoned monster declares a direct attack, if its ATK is greater than or equal to your LP: Negate the attack, and if you do, draw 1 card, then you can Special Summon 1 "Stardust" monster from your Extra Deck or Graveyard. You can only activate 1 "Stardust Re-Spark" per turn.
external_ids: local SETCARD_ID_0 = 0xa3 --Stardust
  
lua: local SETCARD_ID_0 = 0xa3 --Stardust
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	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.condition(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttacker()
  	return at:IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local at = Duel.GetAttacker()
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and at:IsOnField() and at:GetAttack() >= Duel.GetLP(tp) and at:IsSummonType(SUMMON_TYPE_SPECIAL)
  	end
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and (c:IsLocation(LOCATION_GRAVE) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateAttack() and Duel.Draw(tp, 1, REASON_EFFECT) ~= 0 then
  		local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, nil, e, tp)
  		if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = g:Select(tp, 1, 1, nil)
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  
  
source_text: Stardust
  When an opponent's Special Summoned monster declares a direct attack, if its ATK is greater than or equal to your LP: Negate the attack, and if you do, draw 1 card, then you can Special Summon 1 "Stardust" monster from your Extra Deck or Graveyard. You can only activate 1 "Stardust Re-Spark" per turn.
target_text: -- Stardust
  local SETCARD_ID_0 = 0xa3 --Stardust
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	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.condition(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttacker()
  	return at:IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local at = Duel.GetAttacker()
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and at:IsOnField() and at:GetAttack() >= Duel.GetLP(tp) and at:IsSummonType(SUMMON_TYPE_SPECIAL)
  	end
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and (c:IsLocation(LOCATION_GRAVE) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateAttack() and Duel.Draw(tp, 1, REASON_EFFECT) ~= 0 then
  		local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, nil, e, tp)
  		if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = g:Select(tp, 1, 1, nil)
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  
  