name: Traptrix
card_text: Unaffected by the effects of "Hole" Normal Traps. When this card is Normal Summoned: You can target 1 "Traptrix" monster in your GY; Special Summon that target in Defense Position. When this card is Special Summoned: You can target 1 "Hole" Normal Trap in your GY; Set that target, but banish it during the End Phase of your next turn if it is still on the field. You can only use this effect of "Traptrix Dionaea" once per turn.
external_ids: local SETCARD_ID_0 = 0x108a --Traptrix
  local SETCARD_ID_1 = 0x4c --Trap
  
lua: local SETCARD_ID_0 = 0x108a --Traptrix
  local SETCARD_ID_1 = 0x4c --Trap
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--immune
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_IMMUNE_EFFECT)
  	e1:SetValue(s.efilter)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.settg)
  	e3:SetOperation(s.setop)
  	c:RegisterEffect(e3)
  end
  function s.efilter(e, te)
  	local c = te:GetHandler()
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_1, 0x89)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  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_DEFENSE)
  	end
  end
  function s.setfilter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_1, 0x89) and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.setfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.setfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectTarget(tp, s.setfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SSet(tp, tc) ~= 0 then
  		local fid = e:GetHandler():GetFieldID()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetCountLimit(1)
  		if Duel.GetTurnPlayer() == tp then
  			e1:SetLabel(Duel.GetTurnCount())
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN, 2)
  		else
  			e1:SetLabel(0)
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN)
  		end
  		e1:SetLabelObject(tc)
  		e1:SetValue(fid)
  		e1:SetCondition(s.rmcon)
  		e1:SetOperation(s.rmop)
  		Duel.RegisterEffect(e1, tp)
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  	end
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnCount() ~= e:GetLabel() and Duel.GetTurnPlayer() == tp
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	if tc:GetFlagEffectLabel(id) == e:GetValue() then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  
source_text: Traptrix
  Unaffected by the effects of "Hole" Normal Traps. When this card is Normal Summoned: You can target 1 "Traptrix" monster in your GY; Special Summon that target in Defense Position. When this card is Special Summoned: You can target 1 "Hole" Normal Trap in your GY; Set that target, but banish it during the End Phase of your next turn if it is still on the field. You can only use this effect of "Traptrix Dionaea" once per turn.
target_text: -- Traptrix
  local SETCARD_ID_0 = 0x108a --Traptrix
  local SETCARD_ID_1 = 0x4c --Trap
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--immune
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_IMMUNE_EFFECT)
  	e1:SetValue(s.efilter)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.settg)
  	e3:SetOperation(s.setop)
  	c:RegisterEffect(e3)
  end
  function s.efilter(e, te)
  	local c = te:GetHandler()
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_1, 0x89)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  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_DEFENSE)
  	end
  end
  function s.setfilter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_1, 0x89) and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.setfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.setfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectTarget(tp, s.setfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SSet(tp, tc) ~= 0 then
  		local fid = e:GetHandler():GetFieldID()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetCountLimit(1)
  		if Duel.GetTurnPlayer() == tp then
  			e1:SetLabel(Duel.GetTurnCount())
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN, 2)
  		else
  			e1:SetLabel(0)
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN)
  		end
  		e1:SetLabelObject(tc)
  		e1:SetValue(fid)
  		e1:SetCondition(s.rmcon)
  		e1:SetOperation(s.rmop)
  		Duel.RegisterEffect(e1, tp)
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  	end
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnCount() ~= e:GetLabel() and Duel.GetTurnPlayer() == tp
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	if tc:GetFlagEffectLabel(id) == e:GetValue() then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  