name: Timegazer
card_text: Pendulum Scale = 8
  [ Pendulum Effect ]
  You must control no monsters to activate this card. If a Pendulum Monster you control battles, your opponent cannot activate Trap Cards until the end of the Damage Step. Unless you have a "Magician" card or "Odd-Eyes" card in your other Pendulum Zone, this card's Pendulum Scale becomes 4.
  ----------------------------------------
  [ Monster Effect ]
  Each turn, the first card(s) in your Pendulum Zone that would be destroyed by an opponent's card effect, is not destroyed.
external_ids: local SETCARD_ID_0 = 0x98 --Magician
  
lua: local SETCARD_ID_0 = 0x98 --Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c, false)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(1160)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.condition)
  	c:RegisterEffect(e1)
  	--actlimit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetTargetRange(0, 1)
  	e2:SetValue(s.aclimit)
  	e2:SetCondition(s.actcon)
  	c:RegisterEffect(e2)
  	--scale
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_CHANGE_LSCALE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetRange(LOCATION_PZONE)
  	e4:SetCondition(s.slcon)
  	e4:SetValue(4)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_CHANGE_RSCALE)
  	c:RegisterEffect(e5)
  	--indes
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD)
  	e6:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetTargetRange(LOCATION_PZONE, 0)
  	e6:SetCountLimit(1)
  	e6:SetTarget(aux.TRUE)
  	e6:SetValue(s.indval)
  	c:RegisterEffect(e6)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0
  end
  function s.actcon(e)
  	local tp = e:GetHandlerPlayer()
  	local tc = Duel.GetAttacker()
  	if not tc then
  		return false
  	end
  	if tc:IsControler(1 - tp) then
  		tc = Duel.GetAttackTarget()
  	end
  	return tc and tc:IsControler(tp) and tc:IsType(TYPE_PENDULUM)
  end
  function s.aclimit(e, re, tp)
  	return re:IsActiveType(TYPE_TRAP) and re:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  function s.slfilter(c)
  	return c:IsSetCard(SETCARD_ID_0, 0x99)
  end
  function s.slcon(e)
  	return not Duel.IsExistingMatchingCard(s.slfilter, e:GetHandlerPlayer(), LOCATION_PZONE, 0, 1, e:GetHandler())
  end
  function s.indval(e, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - e:GetHandlerPlayer()
  end
  
  
source_text: Timegazer
  Pendulum Scale = 8
  [ Pendulum Effect ]
  You must control no monsters to activate this card. If a Pendulum Monster you control battles, your opponent cannot activate Trap Cards until the end of the Damage Step. Unless you have a "Magician" card or "Odd-Eyes" card in your other Pendulum Zone, this card's Pendulum Scale becomes 4.
  ----------------------------------------
  [ Monster Effect ]
  Each turn, the first card(s) in your Pendulum Zone that would be destroyed by an opponent's card effect, is not destroyed.
target_text: -- Timegazer
  local SETCARD_ID_0 = 0x98 --Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c, false)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(1160)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.condition)
  	c:RegisterEffect(e1)
  	--actlimit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetTargetRange(0, 1)
  	e2:SetValue(s.aclimit)
  	e2:SetCondition(s.actcon)
  	c:RegisterEffect(e2)
  	--scale
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_CHANGE_LSCALE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetRange(LOCATION_PZONE)
  	e4:SetCondition(s.slcon)
  	e4:SetValue(4)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_CHANGE_RSCALE)
  	c:RegisterEffect(e5)
  	--indes
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD)
  	e6:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetTargetRange(LOCATION_PZONE, 0)
  	e6:SetCountLimit(1)
  	e6:SetTarget(aux.TRUE)
  	e6:SetValue(s.indval)
  	c:RegisterEffect(e6)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0
  end
  function s.actcon(e)
  	local tp = e:GetHandlerPlayer()
  	local tc = Duel.GetAttacker()
  	if not tc then
  		return false
  	end
  	if tc:IsControler(1 - tp) then
  		tc = Duel.GetAttackTarget()
  	end
  	return tc and tc:IsControler(tp) and tc:IsType(TYPE_PENDULUM)
  end
  function s.aclimit(e, re, tp)
  	return re:IsActiveType(TYPE_TRAP) and re:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  function s.slfilter(c)
  	return c:IsSetCard(SETCARD_ID_0, 0x99)
  end
  function s.slcon(e)
  	return not Duel.IsExistingMatchingCard(s.slfilter, e:GetHandlerPlayer(), LOCATION_PZONE, 0, 1, e:GetHandler())
  end
  function s.indval(e, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - e:GetHandlerPlayer()
  end
  
  