name: Stardust
card_text: Once per turn, if a "Stardust" Synchro Monster you control is Tributed to activate its own effect (except during the Damage Step): You can target that monster; Special Summon it. Your opponent cannot activate cards or effects in response to this effect's activation. Monsters Special Summoned by this effect cannot be destroyed by battle while in Attack Position.
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:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_RELEASE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.activate)
  	c:RegisterEffect(e2)
  	--indes
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e3:SetTarget(s.indtg)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  end
  function s.filter(c, e, tp, re)
  	return c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_SYNCHRO)
  		and c:IsReason(REASON_COST)
  		and c == re:GetHandler()
  		and c:IsCanBeEffectTarget(e)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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 eg:IsExists(s.filter, 1, nil, e, tp, re) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  	end
  	local tg
  	if #eg == 1 then
  		tg = eg:Clone()
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		tg = eg:FilterSelect(tp, s.filter, 1, 1, nil, e, tp, re)
  	end
  	Duel.SetTargetCard(tg)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, tg, 1, 0, 0)
  	Duel.SetChainLimit(s.chlimit)
  end
  function s.chlimit(e, ep, tp)
  	return tp == ep
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, e:GetHandler():GetFieldID())
  	end
  end
  function s.indtg(e, c)
  	return c:IsAttackPos() and c:GetFlagEffectLabel(id) == e:GetHandler():GetFieldID()
  end
  
  
source_text: Stardust
  Once per turn, if a "Stardust" Synchro Monster you control is Tributed to activate its own effect (except during the Damage Step): You can target that monster; Special Summon it. Your opponent cannot activate cards or effects in response to this effect's activation. Monsters Special Summoned by this effect cannot be destroyed by battle while in Attack Position.
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:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_RELEASE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.activate)
  	c:RegisterEffect(e2)
  	--indes
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e3:SetTarget(s.indtg)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  end
  function s.filter(c, e, tp, re)
  	return c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_SYNCHRO)
  		and c:IsReason(REASON_COST)
  		and c == re:GetHandler()
  		and c:IsCanBeEffectTarget(e)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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 eg:IsExists(s.filter, 1, nil, e, tp, re) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  	end
  	local tg
  	if #eg == 1 then
  		tg = eg:Clone()
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		tg = eg:FilterSelect(tp, s.filter, 1, 1, nil, e, tp, re)
  	end
  	Duel.SetTargetCard(tg)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, tg, 1, 0, 0)
  	Duel.SetChainLimit(s.chlimit)
  end
  function s.chlimit(e, ep, tp)
  	return tp == ep
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, e:GetHandler():GetFieldID())
  	end
  end
  function s.indtg(e, c)
  	return c:IsAttackPos() and c:GetFlagEffectLabel(id) == e:GetHandler():GetFieldID()
  end
  
  