name: Apoqliphort
card_text: Cannot be Special Summoned. Requires 3 "Qli" Tributes to Normal Summon/Set. If this card is Normal Summoned/Set, it is unaffected by Spell/Trap effects and by activated effects from any monster whose original Level/Rank is lower than this card's current Level. Once per turn: You can target 1 monster your opponent controls; take control of it until the End Phase.
external_ids: local SETCARD_ID_0 = 0xaa --Qli
  
lua: local SETCARD_ID_0 = 0xaa --Qli
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--tribute limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TRIBUTE_LIMIT)
  	e2:SetValue(s.tlimit)
  	c:RegisterEffect(e2)
  	--summon with 3 tribute
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e3:SetCode(EFFECT_LIMIT_SUMMON_PROC)
  	e3:SetCondition(s.ttcon)
  	e3:SetOperation(s.ttop)
  	e3:SetValue(SUMMON_TYPE_ADVANCE)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_LIMIT_SET_PROC)
  	c:RegisterEffect(e4)
  	--immune
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetProperty(EFFECT_FLAG_SINGLE_RANGE + EFFECT_FLAG_UNCOPYABLE)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCode(EFFECT_IMMUNE_EFFECT)
  	e5:SetCondition(s.immcon)
  	e5:SetValue(s.efilter)
  	c:RegisterEffect(e5)
  	--control
  	local e6 = Effect.CreateEffect(c)
  	e6:SetCategory(CATEGORY_CONTROL)
  	e6:SetType(EFFECT_TYPE_IGNITION)
  	e6:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetCountLimit(1)
  	e6:SetTarget(s.cttg)
  	e6:SetOperation(s.ctop)
  	c:RegisterEffect(e6)
  end
  function s.tlimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.ttcon(e, c, minc)
  	if c == nil then
  		return true
  	end
  	return minc <= 3 and Duel.CheckTribute(c, 3)
  end
  function s.ttop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = Duel.SelectTribute(tp, c, 3, 3)
  	c:SetMaterial(g)
  	Duel.Release(g, REASON_SUMMON + REASON_MATERIAL)
  end
  function s.immcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_NORMAL)
  end
  function s.efilter(e, te)
  	if te:IsActiveType(TYPE_SPELL + TYPE_TRAP) then
  		return true
  	else
  		return aux.qlifilter(e, te)
  	end
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsControlerCanBeChanged()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp, PHASE_END, 1)
  	end
  end
  
  
source_text: Apoqliphort
  Cannot be Special Summoned. Requires 3 "Qli" Tributes to Normal Summon/Set. If this card is Normal Summoned/Set, it is unaffected by Spell/Trap effects and by activated effects from any monster whose original Level/Rank is lower than this card's current Level. Once per turn: You can target 1 monster your opponent controls; take control of it until the End Phase.
target_text: -- Apoqliphort
  local SETCARD_ID_0 = 0xaa --Qli
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--tribute limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TRIBUTE_LIMIT)
  	e2:SetValue(s.tlimit)
  	c:RegisterEffect(e2)
  	--summon with 3 tribute
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e3:SetCode(EFFECT_LIMIT_SUMMON_PROC)
  	e3:SetCondition(s.ttcon)
  	e3:SetOperation(s.ttop)
  	e3:SetValue(SUMMON_TYPE_ADVANCE)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_LIMIT_SET_PROC)
  	c:RegisterEffect(e4)
  	--immune
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetProperty(EFFECT_FLAG_SINGLE_RANGE + EFFECT_FLAG_UNCOPYABLE)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCode(EFFECT_IMMUNE_EFFECT)
  	e5:SetCondition(s.immcon)
  	e5:SetValue(s.efilter)
  	c:RegisterEffect(e5)
  	--control
  	local e6 = Effect.CreateEffect(c)
  	e6:SetCategory(CATEGORY_CONTROL)
  	e6:SetType(EFFECT_TYPE_IGNITION)
  	e6:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetCountLimit(1)
  	e6:SetTarget(s.cttg)
  	e6:SetOperation(s.ctop)
  	c:RegisterEffect(e6)
  end
  function s.tlimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.ttcon(e, c, minc)
  	if c == nil then
  		return true
  	end
  	return minc <= 3 and Duel.CheckTribute(c, 3)
  end
  function s.ttop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = Duel.SelectTribute(tp, c, 3, 3)
  	c:SetMaterial(g)
  	Duel.Release(g, REASON_SUMMON + REASON_MATERIAL)
  end
  function s.immcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_NORMAL)
  end
  function s.efilter(e, te)
  	if te:IsActiveType(TYPE_SPELL + TYPE_TRAP) then
  		return true
  	else
  		return aux.qlifilter(e, te)
  	end
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsControlerCanBeChanged()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp, PHASE_END, 1)
  	end
  end
  
  