name: Timebreaker
card_text: Pendulum Scale = 2
  [ Pendulum Effect ]
  Each turn, the first Pendulum Monster(s) you control that would be destroyed by an opponent's card effect, is not destroyed.
  ----------------------------------------
  [ Monster Effect ]
  When this card is Pendulum Summoned from the hand (and no other cards are Pendulum Summoned at the same time): You can make this card's ATK become double its original ATK. Once per turn: You can target 1 monster on the field; banish both it and this card from the field until your next Standby Phase.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(s.indval)
  	c:RegisterEffect(e2)
  	--double
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCondition(s.atkcon)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  	--Banish
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_REMOVE)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetTarget(s.rmtg)
  	e4:SetOperation(s.rmop)
  	c:RegisterEffect(e4)
  end
  function s.indtg(e, c)
  	return c:IsType(TYPE_PENDULUM)
  end
  function s.indval(e, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - e:GetHandlerPlayer()
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return eg:GetCount() == 1 and eg:GetFirst() == c and c:IsSummonType(SUMMON_TYPE_PENDULUM) and c:IsPreviousLocation(LOCATION_HAND)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(c:GetBaseAttack() * 2)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and Duel.IsExistingTarget(Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, e:GetHandler())
  	g:AddCard(e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 2, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not c:IsRelateToEffect(e) or not tc:IsRelateToEffect(e) then
  		return
  	end
  	local g = Group.FromCards(c, tc)
  	if Duel.Remove(g, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		if c:GetOriginalCode() ~= id then
  			og:RemoveCard(c)
  		end
  		local oc = og:GetFirst()
  		while oc do
  			oc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 0, 1)
  			oc = og:GetNext()
  		end
  		og:KeepAlive()
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  		e1:SetReset(RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN)
  		e1:SetCountLimit(1)
  		e1:SetLabelObject(og)
  		e1:SetCondition(s.retcon)
  		e1:SetOperation(s.retop)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.retfilter(c)
  	return c:GetFlagEffect(id) ~= 0
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local sg = g:Filter(s.retfilter, nil)
  	if sg:GetCount() > 1 and sg:GetClassCount(Card.GetPreviousControler) == 1 then
  		local ft = Duel.GetLocationCount(sg:GetFirst():GetPreviousControler(), LOCATION_MZONE)
  		if ft == 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  			local tc = sg:Select(tp, 1, 1, nil):GetFirst()
  			Duel.ReturnToField(tc)
  			sg:RemoveCard(tc)
  		end
  	end
  	local tc = sg:GetFirst()
  	while tc do
  		Duel.ReturnToField(tc)
  		tc = sg:GetNext()
  	end
  end
  
  
source_text: Timebreaker
  Pendulum Scale = 2
  [ Pendulum Effect ]
  Each turn, the first Pendulum Monster(s) you control that would be destroyed by an opponent's card effect, is not destroyed.
  ----------------------------------------
  [ Monster Effect ]
  When this card is Pendulum Summoned from the hand (and no other cards are Pendulum Summoned at the same time): You can make this card's ATK become double its original ATK. Once per turn: You can target 1 monster on the field; banish both it and this card from the field until your next Standby Phase.
target_text: -- Timebreaker
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  	e2:SetRange(LOCATION_PZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(s.indval)
  	c:RegisterEffect(e2)
  	--double
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCondition(s.atkcon)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  	--Banish
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_REMOVE)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetTarget(s.rmtg)
  	e4:SetOperation(s.rmop)
  	c:RegisterEffect(e4)
  end
  function s.indtg(e, c)
  	return c:IsType(TYPE_PENDULUM)
  end
  function s.indval(e, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - e:GetHandlerPlayer()
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return eg:GetCount() == 1 and eg:GetFirst() == c and c:IsSummonType(SUMMON_TYPE_PENDULUM) and c:IsPreviousLocation(LOCATION_HAND)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(c:GetBaseAttack() * 2)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and Duel.IsExistingTarget(Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, e:GetHandler())
  	g:AddCard(e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 2, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not c:IsRelateToEffect(e) or not tc:IsRelateToEffect(e) then
  		return
  	end
  	local g = Group.FromCards(c, tc)
  	if Duel.Remove(g, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		if c:GetOriginalCode() ~= id then
  			og:RemoveCard(c)
  		end
  		local oc = og:GetFirst()
  		while oc do
  			oc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 0, 1)
  			oc = og:GetNext()
  		end
  		og:KeepAlive()
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  		e1:SetReset(RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN)
  		e1:SetCountLimit(1)
  		e1:SetLabelObject(og)
  		e1:SetCondition(s.retcon)
  		e1:SetOperation(s.retop)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.retfilter(c)
  	return c:GetFlagEffect(id) ~= 0
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local sg = g:Filter(s.retfilter, nil)
  	if sg:GetCount() > 1 and sg:GetClassCount(Card.GetPreviousControler) == 1 then
  		local ft = Duel.GetLocationCount(sg:GetFirst():GetPreviousControler(), LOCATION_MZONE)
  		if ft == 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  			local tc = sg:Select(tp, 1, 1, nil):GetFirst()
  			Duel.ReturnToField(tc)
  			sg:RemoveCard(tc)
  		end
  	end
  	local tc = sg:GetFirst()
  	while tc do
  		Duel.ReturnToField(tc)
  		tc = sg:GetNext()
  	end
  end
  
  