name: Screams
card_text: If a Fusion Monster was sent to your GY this turn: Special Summon 1 of your Fusion Monsters that is banished or in your GY. During the End Phase, if this card is in the GY because it was sent there to activate the effect of "Fallen of Albaz" this turn: You can Set this card. You can only use this effect of "Screams of the Branded" once per turn.
external_ids: local CARD_ID_0 = 68468459 --Fallen of Albaz
  
lua: local CARD_ID_0 = 68468459 --Fallen of Albaz
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCondition(s.conditon)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetHintTiming(TIMING_END_PHASE)
  	e3:SetCondition(s.setcon)
  	e3:SetTarget(s.settg)
  	e3:SetOperation(s.setop)
  	c:RegisterEffect(e3)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.GlobalEffect()
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetCondition(s.checkcon)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsType, 1, nil, TYPE_FUSION)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local g = eg:Filter(Card.IsType, nil, TYPE_FUSION)
  	local tc = g:GetFirst()
  	while tc do
  		if Duel.GetFlagEffect(tc:GetControler(), id) == 0 then
  			Duel.RegisterFlagEffect(tc:GetControler(), id, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		if Duel.GetFlagEffect(0, id) > 0 and Duel.GetFlagEffect(1, id) > 0 then
  			break
  		end
  		tc = g:GetNext()
  	end
  end
  function s.conditon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) > 0
  end
  function s.spfilter(c, e, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsType(TYPE_FUSION) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  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, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local code1, code2 = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_CODE, CHAININFO_TRIGGERING_CODE2)
  	return e:GetHandler():IsReason(REASON_COST) and re and re:IsActivated() and (code1 == CARD_ID_0 or code2 == CARD_ID_0)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0 and Duel.GetCurrentPhase() & PHASE_END ~= 0
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  
source_text: Screams
  If a Fusion Monster was sent to your GY this turn: Special Summon 1 of your Fusion Monsters that is banished or in your GY. During the End Phase, if this card is in the GY because it was sent there to activate the effect of "Fallen of Albaz" this turn: You can Set this card. You can only use this effect of "Screams of the Branded" once per turn.
target_text: -- Screams
  local CARD_ID_0 = 68468459 --Fallen of Albaz
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCondition(s.conditon)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetHintTiming(TIMING_END_PHASE)
  	e3:SetCondition(s.setcon)
  	e3:SetTarget(s.settg)
  	e3:SetOperation(s.setop)
  	c:RegisterEffect(e3)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.GlobalEffect()
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetCondition(s.checkcon)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsType, 1, nil, TYPE_FUSION)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local g = eg:Filter(Card.IsType, nil, TYPE_FUSION)
  	local tc = g:GetFirst()
  	while tc do
  		if Duel.GetFlagEffect(tc:GetControler(), id) == 0 then
  			Duel.RegisterFlagEffect(tc:GetControler(), id, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		if Duel.GetFlagEffect(0, id) > 0 and Duel.GetFlagEffect(1, id) > 0 then
  			break
  		end
  		tc = g:GetNext()
  	end
  end
  function s.conditon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) > 0
  end
  function s.spfilter(c, e, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsType(TYPE_FUSION) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  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, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local code1, code2 = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_CODE, CHAININFO_TRIGGERING_CODE2)
  	return e:GetHandler():IsReason(REASON_COST) and re and re:IsActivated() and (code1 == CARD_ID_0 or code2 == CARD_ID_0)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0 and Duel.GetCurrentPhase() & PHASE_END ~= 0
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  