name: Traptrix
card_text: 2 Level 4 monsters
  Unaffected by Trap effects while it has material. "Traptrix" monsters you control, except "Traptrix Rafflesia", cannot be destroyed by battle or card effects. Your opponent cannot target "Traptrix" monsters you control, except "Traptrix Rafflesia", with card effects. Once per turn (Quick Effect): You can detach 1 material from this card and send 1 "Hole" Normal Trap that meets its activation conditions from your Deck to the GY; this effect becomes that Trap Card's effect when that card is activated.
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)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2)
  	c:EnableReviveLimit()
  	--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:SetCondition(s.imcon)
  	e1:SetValue(s.efilter)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.imtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--cannot be target
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e4:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e4:SetValue(aux.tgoval)
  	c:RegisterEffect(e4)
  	--copy trap
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetType(EFFECT_TYPE_QUICK_O)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCode(EVENT_FREE_CHAIN)
  	e5:SetHintTiming(0x3c0)
  	e5:SetCountLimit(1)
  	e5:SetCost(s.cost)
  	e5:SetTarget(s.target)
  	e5:SetOperation(s.operation)
  	c:RegisterEffect(e5)
  end
  function s.imcon(e)
  	return e:GetHandler():GetOverlayCount() > 0
  end
  function s.efilter(e, te)
  	return te:IsActiveType(TYPE_TRAP)
  end
  function s.imtg(e, c)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsCode(id)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_1, 0x89) and c:IsAbleToGraveAsCost() and c:CheckActivateEffect(false, true, false) ~= nil
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  
  
source_text: Traptrix
  2 Level 4 monsters
  Unaffected by Trap effects while it has material. "Traptrix" monsters you control, except "Traptrix Rafflesia", cannot be destroyed by battle or card effects. Your opponent cannot target "Traptrix" monsters you control, except "Traptrix Rafflesia", with card effects. Once per turn (Quick Effect): You can detach 1 material from this card and send 1 "Hole" Normal Trap that meets its activation conditions from your Deck to the GY; this effect becomes that Trap Card's effect when that card is activated.
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)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2)
  	c:EnableReviveLimit()
  	--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:SetCondition(s.imcon)
  	e1:SetValue(s.efilter)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.imtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--cannot be target
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e4:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e4:SetValue(aux.tgoval)
  	c:RegisterEffect(e4)
  	--copy trap
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetType(EFFECT_TYPE_QUICK_O)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCode(EVENT_FREE_CHAIN)
  	e5:SetHintTiming(0x3c0)
  	e5:SetCountLimit(1)
  	e5:SetCost(s.cost)
  	e5:SetTarget(s.target)
  	e5:SetOperation(s.operation)
  	c:RegisterEffect(e5)
  end
  function s.imcon(e)
  	return e:GetHandler():GetOverlayCount() > 0
  end
  function s.efilter(e, te)
  	return te:IsActiveType(TYPE_TRAP)
  end
  function s.imtg(e, c)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsCode(id)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.filter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_1, 0x89) and c:IsAbleToGraveAsCost() and c:CheckActivateEffect(false, true, false) ~= nil
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  
  