name: Sacred
card_text: During your Main Phase: You can excavate the top 3 cards of your Deck, and if you do, you can add 1 excavated Machine monster whose ATK equals its own DEF to your hand, also banish the remaining cards face-down. You can only use this effect of "Sacred Scrolls of the Gizmek Legend" once per turn. Each time a Machine monster(s) whose ATK equals its own DEF is Normal or Special Summoned, place 1 counter on this card. While this card has 10 or more counters, neither player can activate the effects of monsters on the field whose ATK does not equal their own DEF.
external_ids: local COUNTER_ID_0 = 0x5d --Counter(Gizmek
  
lua: local COUNTER_ID_0 = 0x5d --Counter(Gizmek
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5d, LOCATION_FZONE)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_REMOVE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.countercon)
  	e3:SetOperation(s.counterop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_SUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--act limit
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e5:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e5:SetRange(LOCATION_FZONE)
  	e5:SetTargetRange(1, 1)
  	e5:SetCondition(s.actlimitcon)
  	e5:SetValue(s.actlimit)
  	c:RegisterEffect(e5)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) >= 3 and Duel.IsPlayerCanRemove(tp)
  	end
  end
  function s.thfilter(c)
  	return aux.AtkEqualsDef(c) and c:IsRace(RACE_MACHINE) and c:IsAbleToHand()
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanRemove(tp) then
  		return
  	end
  	if Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) < 3 then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 3)
  	local g = Duel.GetDecktopGroup(tp, 3)
  	if g:GetCount() > 0 then
  		Duel.DisableShuffleCheck()
  		if g:IsExists(s.thfilter, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local sg = g:FilterSelect(tp, s.thfilter, 1, 1, nil)
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  			Duel.ShuffleHand(tp)
  			g:Sub(sg)
  		end
  		Duel.Remove(g, POS_FACEDOWN, REASON_EFFECT + REASON_REVEAL)
  	end
  end
  function s.cfilter(c)
  	return aux.AtkEqualsDef(c) and c:IsRace(RACE_MACHINE) and c:IsFaceup()
  end
  function s.countercon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil)
  end
  function s.counterop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.actlimitcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) >= 10
  end
  function s.actlimit(e, re, tp)
  	local loc = re:GetActivateLocation()
  	local rc = re:GetHandler()
  	return loc == LOCATION_MZONE and re:IsActiveType(TYPE_MONSTER) and rc:IsDefenseAbove(0) and not rc:IsDefense(rc:GetAttack())
  end
  
  
source_text: Sacred
  During your Main Phase: You can excavate the top 3 cards of your Deck, and if you do, you can add 1 excavated Machine monster whose ATK equals its own DEF to your hand, also banish the remaining cards face-down. You can only use this effect of "Sacred Scrolls of the Gizmek Legend" once per turn. Each time a Machine monster(s) whose ATK equals its own DEF is Normal or Special Summoned, place 1 counter on this card. While this card has 10 or more counters, neither player can activate the effects of monsters on the field whose ATK does not equal their own DEF.
target_text: -- Sacred
  local COUNTER_ID_0 = 0x5d --Counter(Gizmek
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5d, LOCATION_FZONE)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_REMOVE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.countercon)
  	e3:SetOperation(s.counterop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_SUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--act limit
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e5:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e5:SetRange(LOCATION_FZONE)
  	e5:SetTargetRange(1, 1)
  	e5:SetCondition(s.actlimitcon)
  	e5:SetValue(s.actlimit)
  	c:RegisterEffect(e5)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) >= 3 and Duel.IsPlayerCanRemove(tp)
  	end
  end
  function s.thfilter(c)
  	return aux.AtkEqualsDef(c) and c:IsRace(RACE_MACHINE) and c:IsAbleToHand()
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanRemove(tp) then
  		return
  	end
  	if Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) < 3 then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 3)
  	local g = Duel.GetDecktopGroup(tp, 3)
  	if g:GetCount() > 0 then
  		Duel.DisableShuffleCheck()
  		if g:IsExists(s.thfilter, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local sg = g:FilterSelect(tp, s.thfilter, 1, 1, nil)
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  			Duel.ShuffleHand(tp)
  			g:Sub(sg)
  		end
  		Duel.Remove(g, POS_FACEDOWN, REASON_EFFECT + REASON_REVEAL)
  	end
  end
  function s.cfilter(c)
  	return aux.AtkEqualsDef(c) and c:IsRace(RACE_MACHINE) and c:IsFaceup()
  end
  function s.countercon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil)
  end
  function s.counterop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.actlimitcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) >= 10
  end
  function s.actlimit(e, re, tp)
  	local loc = re:GetActivateLocation()
  	local rc = re:GetHandler()
  	return loc == LOCATION_MZONE and re:IsActiveType(TYPE_MONSTER) and rc:IsDefenseAbove(0) and not rc:IsDefense(rc:GetAttack())
  end
  
  