Advanced
If "Advanced Dark" is not in a Field Zone, send this monster to the GY. If this face-up card is destroyed in a Monster Zone, you can place it face-up in your Spell & Trap Zone as a Continuous Spell, instead of sending it to the GY. While this card is treated as a Continuous Spell: You can Special Summon this card, then you can Special Summon as many "Advanced Crystal Beast" Monster Cards as possible from your Spell & Trap Zones. You can only use this effect of "Advanced Crystal Beast Ruby Carbuncle" once per turn.
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local CARD_ID_1 = 12644061 --Advanced Dark
local SETCARD_ID_0 = 0x5034 --Advanced

local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local CARD_ID_1 = 12644061 --Advanced Dark
local SETCARD_ID_0 = 0x5034 --Advanced
local s, id, o = GetID()
function s.initial_effect(c)
	aux.AddCodeList(c, CARD_ID_1)
	Duel.EnableGlobalFlag(GLOBALFLAG_SELF_TOGRAVE)
	--self to grave
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetCode(EFFECT_SELF_TOGRAVE)
	e1:SetRange(LOCATION_MZONE)
	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e1:SetCondition(s.tgcon)
	c:RegisterEffect(e1)
	--send replace
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_TO_GRAVE_REDIRECT_CB)
	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
	e2:SetCondition(s.repcon)
	e2:SetOperation(s.repop)
	c:RegisterEffect(e2)
	--spsummon
	local e3 = Effect.CreateEffect(c)
	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e3:SetType(EFFECT_TYPE_IGNITION)
	e3:SetRange(LOCATION_SZONE)
	e3:SetCountLimit(1, id)
	e3:SetCondition(s.spcon)
	e3:SetTarget(s.sptg)
	e3:SetOperation(s.spop)
	c:RegisterEffect(e3)
end
function s.tgcon(e)
	return not Duel.IsEnvironment(CARD_ID_1)
end
function s.repcon(e)
	local c = e:GetHandler()
	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsReason(REASON_DESTROY)
end
function s.repop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local e1 = Effect.CreateEffect(c)
	e1:SetCode(EFFECT_CHANGE_TYPE)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
	e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
	c:RegisterEffect(e1)
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetType() == TYPE_SPELL + TYPE_CONTINUOUS
end
function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
end
function s.filter(c, e, sp)
	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, sp, false, false)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) then
		if Duel.SpecialSummonStep(c, 0, tp, tp, false, false, POS_FACEUP) then
			local ct = Duel.GetLocationCount(tp, LOCATION_MZONE)
			if ct <= 0 then
				Duel.SpecialSummonComplete()
				return
			end
			if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
				ct = 1
			end
			local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_SZONE, 0, nil, e, tp)
			local gc = g:GetCount()
			if gc > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
				Duel.DisableSelfDestroyCheck()
				Duel.SpecialSummonComplete()
				Duel.BreakEffect()
				if gc <= ct then
					Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
				else
					Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
					local sg = g:Select(tp, ct, ct, nil)
					Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
				end
				Duel.DisableSelfDestroyCheck(false)
			else
				Duel.SpecialSummonComplete()
			end
		else
			Duel.SpecialSummonComplete()
		end
	end
end


Advanced
If "Advanced Dark" is not in a Field Zone, send this monster to the GY. If this face-up card is destroyed in a Monster Zone, you can place it face-up in your Spell & Trap Zone as a Continuous Spell, instead of sending it to the GY. While this card is treated as a Continuous Spell: You can Special Summon this card, then you can Special Summon as many "Advanced Crystal Beast" Monster Cards as possible from your Spell & Trap Zones. You can only use this effect of "Advanced Crystal Beast Ruby Carbuncle" once per turn.
-- Advanced
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local CARD_ID_1 = 12644061 --Advanced Dark
local SETCARD_ID_0 = 0x5034 --Advanced
local s, id, o = GetID()
function s.initial_effect(c)
	aux.AddCodeList(c, CARD_ID_1)
	Duel.EnableGlobalFlag(GLOBALFLAG_SELF_TOGRAVE)
	--self to grave
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetCode(EFFECT_SELF_TOGRAVE)
	e1:SetRange(LOCATION_MZONE)
	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e1:SetCondition(s.tgcon)
	c:RegisterEffect(e1)
	--send replace
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_TO_GRAVE_REDIRECT_CB)
	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
	e2:SetCondition(s.repcon)
	e2:SetOperation(s.repop)
	c:RegisterEffect(e2)
	--spsummon
	local e3 = Effect.CreateEffect(c)
	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e3:SetType(EFFECT_TYPE_IGNITION)
	e3:SetRange(LOCATION_SZONE)
	e3:SetCountLimit(1, id)
	e3:SetCondition(s.spcon)
	e3:SetTarget(s.sptg)
	e3:SetOperation(s.spop)
	c:RegisterEffect(e3)
end
function s.tgcon(e)
	return not Duel.IsEnvironment(CARD_ID_1)
end
function s.repcon(e)
	local c = e:GetHandler()
	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsReason(REASON_DESTROY)
end
function s.repop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local e1 = Effect.CreateEffect(c)
	e1:SetCode(EFFECT_CHANGE_TYPE)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
	e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
	c:RegisterEffect(e1)
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetType() == TYPE_SPELL + TYPE_CONTINUOUS
end
function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
end
function s.filter(c, e, sp)
	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, sp, false, false)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) then
		if Duel.SpecialSummonStep(c, 0, tp, tp, false, false, POS_FACEUP) then
			local ct = Duel.GetLocationCount(tp, LOCATION_MZONE)
			if ct <= 0 then
				Duel.SpecialSummonComplete()
				return
			end
			if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
				ct = 1
			end
			local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_SZONE, 0, nil, e, tp)
			local gc = g:GetCount()
			if gc > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
				Duel.DisableSelfDestroyCheck()
				Duel.SpecialSummonComplete()
				Duel.BreakEffect()
				if gc <= ct then
					Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
				else
					Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
					local sg = g:Select(tp, ct, ct, nil)
					Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
				end
				Duel.DisableSelfDestroyCheck(false)
			else
				Duel.SpecialSummonComplete()
			end
		else
			Duel.SpecialSummonComplete()
		end
	end
end

