name: Crystal
card_text: Target up to 2 "Crystal Beast" monsters in your GY; place those targets face-up in your Spell & Trap Zone as Continuous Spells.
external_ids: local SETCARD_ID_0 = 0x1034 --Crystal
  
lua: local SETCARD_ID_0 = 0x1034 --Crystal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and not c:IsForbidden()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		if not Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil) then
  			return false
  		end
  		if e:GetHandler():IsLocation(LOCATION_HAND) then
  			return Duel.GetLocationCount(tp, LOCATION_SZONE) > 1
  		else
  			return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  		end
  	end
  	local ft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  	if ft > 2 then
  		ft = 2
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, ft, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, g:GetCount(), 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  	if ft <= 0 then
  		return
  	end
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if sg:GetCount() > 0 then
  		if sg:GetCount() > ft then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  			local rg = sg:Select(tp, ft, ft, nil)
  			sg = rg
  		end
  		local tc = sg:GetFirst()
  		while tc do
  			Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			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)
  			tc:RegisterEffect(e1)
  			tc = sg:GetNext()
  		end
  	end
  end
  
  
source_text: Crystal
  Target up to 2 "Crystal Beast" monsters in your GY; place those targets face-up in your Spell & Trap Zone as Continuous Spells.
target_text: -- Crystal
  local SETCARD_ID_0 = 0x1034 --Crystal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and not c:IsForbidden()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		if not Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil) then
  			return false
  		end
  		if e:GetHandler():IsLocation(LOCATION_HAND) then
  			return Duel.GetLocationCount(tp, LOCATION_SZONE) > 1
  		else
  			return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  		end
  	end
  	local ft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  	if ft > 2 then
  		ft = 2
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, ft, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, g:GetCount(), 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  	if ft <= 0 then
  		return
  	end
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(Card.IsRelateToEffect, nil, e)
  	if sg:GetCount() > 0 then
  		if sg:GetCount() > ft then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  			local rg = sg:Select(tp, ft, ft, nil)
  			sg = rg
  		end
  		local tc = sg:GetFirst()
  		while tc do
  			Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			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)
  			tc:RegisterEffect(e1)
  			tc = sg:GetNext()
  		end
  	end
  end
  
  