name: Lucent,
card_text: If this card is discarded to the GY by card effect: Special Summon this card, then, if this card was discarded from your hand to your GY by an opponent's card effect, you can Special Summon 1 Fiend monster from your Deck to either field.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	e:SetLabel(e:GetHandler():GetPreviousControler())
  	return e:GetHandler():IsPreviousLocation(LOCATION_HAND) and bit.band(r, 0x4040) == 0x4040
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	if rp == 1 - tp and tp == e:GetLabel() then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON | CATEGORY_DECKDES)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	end
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_FIEND)
  		and (
  			(Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false))
  			or (Duel.GetLocationCount(1 - tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp))
  		)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if not e:GetHandler():IsRelateToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(e:GetHandler(), 0, tp, tp, false, false, POS_FACEUP) == 0 then
  		return
  	end
  	if rp == 1 - tp and tp == e:GetLabel() and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, e, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		local tc = g:GetFirst()
  		if tc then
  			local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and tc:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  			local b2 = Duel.GetLocationCount(1 - tp, LOCATION_MZONE) > 0 and tc:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  			local op = 0
  			if b1 and b2 then
  				op = Duel.SelectOption(tp, aux.Stringid(id, 2), aux.Stringid(id, 3))
  			elseif b1 then
  				op = Duel.SelectOption(tp, aux.Stringid(id, 2))
  			elseif b2 then
  				op = Duel.SelectOption(tp, aux.Stringid(id, 3)) + 1
  			else
  				return
  			end
  			if op == 0 then
  				Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  			else
  				Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP)
  			end
  		end
  	end
  end
  
  
source_text: Lucent,
  If this card is discarded to the GY by card effect: Special Summon this card, then, if this card was discarded from your hand to your GY by an opponent's card effect, you can Special Summon 1 Fiend monster from your Deck to either field.
target_text: -- Lucent,
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	e:SetLabel(e:GetHandler():GetPreviousControler())
  	return e:GetHandler():IsPreviousLocation(LOCATION_HAND) and bit.band(r, 0x4040) == 0x4040
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	if rp == 1 - tp and tp == e:GetLabel() then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON | CATEGORY_DECKDES)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	end
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_FIEND)
  		and (
  			(Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false))
  			or (Duel.GetLocationCount(1 - tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp))
  		)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if not e:GetHandler():IsRelateToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(e:GetHandler(), 0, tp, tp, false, false, POS_FACEUP) == 0 then
  		return
  	end
  	if rp == 1 - tp and tp == e:GetLabel() and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, e, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		local tc = g:GetFirst()
  		if tc then
  			local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and tc:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  			local b2 = Duel.GetLocationCount(1 - tp, LOCATION_MZONE) > 0 and tc:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  			local op = 0
  			if b1 and b2 then
  				op = Duel.SelectOption(tp, aux.Stringid(id, 2), aux.Stringid(id, 3))
  			elseif b1 then
  				op = Duel.SelectOption(tp, aux.Stringid(id, 2))
  			elseif b2 then
  				op = Duel.SelectOption(tp, aux.Stringid(id, 3)) + 1
  			else
  				return
  			end
  			if op == 0 then
  				Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  			else
  				Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP)
  			end
  		end
  	end
  end
  
  