name: Metallizing
card_text: Once per turn, you can either: Target 1 face-up monster you control; equip this card to that target, OR: Unequip this card and Special Summon it in face-up Attack Position. While equipped by this effect, the equipped monster cannot be targeted or destroyed by your opponent's monster effects. (A monster can only be equipped with 1 Union Monster at a time. If the equipped monster would be destroyed by battle, destroy this card instead.)
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--unequip
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(aux.IsUnionState)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--equip effect
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_EQUIP)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetCondition(aux.IsUnionState)
  	e3:SetValue(s.efilter1)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_EQUIP)
  	e4:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e4:SetCondition(aux.IsUnionState)
  	e4:SetValue(s.efilter2)
  	c:RegisterEffect(e4)
  	--destroy sub
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_EQUIP)
  	e5:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e5:SetCode(EFFECT_DESTROY_SUBSTITUTE)
  	e5:SetCondition(aux.IsUnionState)
  	e5:SetValue(s.repval)
  	c:RegisterEffect(e5)
  	--eqlimit
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetCode(EFFECT_UNION_LIMIT)
  	e6:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e6:SetValue(1)
  	c:RegisterEffect(e6)
  end
  s.old_union = true
  function s.repval(e, re, r, rp)
  	return bit.band(r, REASON_BATTLE) ~= 0
  end
  function s.filter(c)
  	return c:IsFaceup() and c:GetUnionCount() == 0
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) == 0 and Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + 0x7e0000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	if not tc:IsRelateToEffect(e) or not s.filter(tc) then
  		Duel.SendtoGrave(c, REASON_EFFECT)
  		return
  	end
  	if not Duel.Equip(tp, c, tc, false) then
  		return
  	end
  	aux.SetUnionState(c)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) == 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, true, false, POS_FACEUP_ATTACK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + 0x7e0000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(c, 0, tp, tp, true, false, POS_FACEUP_ATTACK)
  end
  function s.efilter1(e, re, rp)
  	return rp == 1 - e:GetHandlerPlayer() and re:IsActiveType(TYPE_MONSTER)
  end
  function s.efilter2(e, te)
  	return te:GetOwnerPlayer() ~= e:GetHandlerPlayer() and te:IsActiveType(TYPE_MONSTER)
  end
  
  
source_text: Metallizing
  Once per turn, you can either: Target 1 face-up monster you control; equip this card to that target, OR: Unequip this card and Special Summon it in face-up Attack Position. While equipped by this effect, the equipped monster cannot be targeted or destroyed by your opponent's monster effects. (A monster can only be equipped with 1 Union Monster at a time. If the equipped monster would be destroyed by battle, destroy this card instead.)
target_text: -- Metallizing
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--unequip
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(aux.IsUnionState)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--equip effect
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_EQUIP)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetCondition(aux.IsUnionState)
  	e3:SetValue(s.efilter1)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_EQUIP)
  	e4:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e4:SetCondition(aux.IsUnionState)
  	e4:SetValue(s.efilter2)
  	c:RegisterEffect(e4)
  	--destroy sub
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_EQUIP)
  	e5:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e5:SetCode(EFFECT_DESTROY_SUBSTITUTE)
  	e5:SetCondition(aux.IsUnionState)
  	e5:SetValue(s.repval)
  	c:RegisterEffect(e5)
  	--eqlimit
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetCode(EFFECT_UNION_LIMIT)
  	e6:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e6:SetValue(1)
  	c:RegisterEffect(e6)
  end
  s.old_union = true
  function s.repval(e, re, r, rp)
  	return bit.band(r, REASON_BATTLE) ~= 0
  end
  function s.filter(c)
  	return c:IsFaceup() and c:GetUnionCount() == 0
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) == 0 and Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + 0x7e0000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	if not tc:IsRelateToEffect(e) or not s.filter(tc) then
  		Duel.SendtoGrave(c, REASON_EFFECT)
  		return
  	end
  	if not Duel.Equip(tp, c, tc, false) then
  		return
  	end
  	aux.SetUnionState(c)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) == 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, true, false, POS_FACEUP_ATTACK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + 0x7e0000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.SpecialSummon(c, 0, tp, tp, true, false, POS_FACEUP_ATTACK)
  end
  function s.efilter1(e, re, rp)
  	return rp == 1 - e:GetHandlerPlayer() and re:IsActiveType(TYPE_MONSTER)
  end
  function s.efilter2(e, te)
  	return te:GetOwnerPlayer() ~= e:GetHandlerPlayer() and te:IsActiveType(TYPE_MONSTER)
  end
  
  