name: Glacial
card_text: When a monster declares an attack: You can negate the attack, and if you do, Special Summon 1 Level 4 or lower WATER monster from your hand, except "Glacial Beast Blizzard Wolf". At the start of your opponent's Battle Phase, if this card is in your GY and you control no monsters: You can Special Summon this card in Attack Position, but banish it when it leaves the field. You can only use each effect of "Glacial Beast Blizzard Wolf" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--disable attack
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttribute(ATTRIBUTE_WATER) and c:IsLevelBelow(4) and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.atktg(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_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateAttack() then
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local tc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp):GetFirst()
  		if tc then
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer() and Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_ATTACK) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e1, true)
  	end
  end
  
  
source_text: Glacial
  When a monster declares an attack: You can negate the attack, and if you do, Special Summon 1 Level 4 or lower WATER monster from your hand, except "Glacial Beast Blizzard Wolf". At the start of your opponent's Battle Phase, if this card is in your GY and you control no monsters: You can Special Summon this card in Attack Position, but banish it when it leaves the field. You can only use each effect of "Glacial Beast Blizzard Wolf" once per turn.
target_text: -- Glacial
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--disable attack
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttribute(ATTRIBUTE_WATER) and c:IsLevelBelow(4) and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.atktg(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_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateAttack() then
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local tc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp):GetFirst()
  		if tc then
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer() and Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_ATTACK) > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e1, true)
  	end
  end
  
  