name: Qebehsenuef,
card_text: If you control "King's Sarcophagus", you can Special Summon this card (from your GY). You can only Special Summon "Qebehsenuef, Protection of Horus" once per turn this way. If another card(s) you control leaves the field by an opponent's card effect, while this card is in your Monster Zone (except during the Damage Step): You can activate this effect; this turn, your opponent's monsters cannot target "Horus" monsters for attacks, also your opponent cannot target "Horus" monsters on the field with card effects. You can only use this effect of "Qebehsenuef, Protection of Horus" once per turn.
external_ids: local CARD_ID_1 = 16528181 --King's Sarcophagus
  local SETCARD_ID_0 = 0x19d --Horus
  
lua: local CARD_ID_1 = 16528181 --King's Sarcophagus
  local SETCARD_ID_0 = 0x19d --Horus
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_GRAVE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.sprcon)
  	c:RegisterEffect(e1)
  	--Leave Field
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOGRAVE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.descon)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.sprfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1)
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	if c:IsHasEffect(EFFECT_NECRO_VALLEY) then
  		return false
  	end
  	local tp = c:GetControler()
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.sprfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp) and c:GetReasonPlayer() == 1 - tp and c:IsReason(REASON_EFFECT)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp) and not eg:IsContains(e:GetHandler())
  end
  function s.atlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e1:SetTargetRange(0, LOCATION_MZONE)
  	e1:SetValue(s.atlimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(s.atlimit)
  	e2:SetValue(aux.tgoval)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  
  
source_text: Qebehsenuef,
  If you control "King's Sarcophagus", you can Special Summon this card (from your GY). You can only Special Summon "Qebehsenuef, Protection of Horus" once per turn this way. If another card(s) you control leaves the field by an opponent's card effect, while this card is in your Monster Zone (except during the Damage Step): You can activate this effect; this turn, your opponent's monsters cannot target "Horus" monsters for attacks, also your opponent cannot target "Horus" monsters on the field with card effects. You can only use this effect of "Qebehsenuef, Protection of Horus" once per turn.
target_text: -- Qebehsenuef,
  local CARD_ID_1 = 16528181 --King's Sarcophagus
  local SETCARD_ID_0 = 0x19d --Horus
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_GRAVE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.sprcon)
  	c:RegisterEffect(e1)
  	--Leave Field
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOGRAVE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.descon)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.sprfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1)
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	if c:IsHasEffect(EFFECT_NECRO_VALLEY) then
  		return false
  	end
  	local tp = c:GetControler()
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.sprfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp) and c:GetReasonPlayer() == 1 - tp and c:IsReason(REASON_EFFECT)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp) and not eg:IsContains(e:GetHandler())
  end
  function s.atlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e1:SetTargetRange(0, LOCATION_MZONE)
  	e1:SetValue(s.atlimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(s.atlimit)
  	e2:SetValue(aux.tgoval)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  
  