name: Hieratic
card_text: Once per opponent's turn: You can send 1 "Hieratic" monster from your Deck to your GY. Once per turn, during your turn: You can target 1 of your banished "Hieratic" monsters; return that target to the GY. If this face-up card on the field is sent to the GY: Target 1 "Hieratic" monster in your GY; Special Summon that target.
external_ids: local SETCARD_ID_0 = 0x69 --Hieratic
  
lua: local SETCARD_ID_0 = 0x69 --Hieratic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOGRAVE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.condition1)
  	e2:SetTarget(s.target1)
  	e2:SetOperation(s.activate1)
  	c:RegisterEffect(e2)
  	--return grave
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.condition2)
  	e3:SetTarget(s.target2)
  	e3:SetOperation(s.activate2)
  	c:RegisterEffect(e3)
  	--spsummmon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.condition1(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsTurnPlayer(1 - tp)
  end
  function s.filter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToGrave()
  end
  function s.target1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_EFFECT)
  end
  function s.condition2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsTurnPlayer(tp)
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.target2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.filter2(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter2, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 3))
  	local g = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  end
  function s.activate2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToChain() then
  		Duel.SendtoGrave(tc, REASON_EFFECT + REASON_RETURN)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Hieratic
  Once per opponent's turn: You can send 1 "Hieratic" monster from your Deck to your GY. Once per turn, during your turn: You can target 1 of your banished "Hieratic" monsters; return that target to the GY. If this face-up card on the field is sent to the GY: Target 1 "Hieratic" monster in your GY; Special Summon that target.
target_text: -- Hieratic
  local SETCARD_ID_0 = 0x69 --Hieratic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOGRAVE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.condition1)
  	e2:SetTarget(s.target1)
  	e2:SetOperation(s.activate1)
  	c:RegisterEffect(e2)
  	--return grave
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.condition2)
  	e3:SetTarget(s.target2)
  	e3:SetOperation(s.activate2)
  	c:RegisterEffect(e3)
  	--spsummmon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.condition1(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsTurnPlayer(1 - tp)
  end
  function s.filter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToGrave()
  end
  function s.target1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_EFFECT)
  end
  function s.condition2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsTurnPlayer(tp)
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.target2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.filter2(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter2, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 3))
  	local g = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  end
  function s.activate2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToChain() then
  		Duel.SendtoGrave(tc, REASON_EFFECT + REASON_RETURN)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  