name: Magnet
card_text: If you control a "Magnet Warrior" monster whose original Level is 4 or lower: Special Summon 1 Level 4 or lower "Magnet Warrior" monster from your Deck with a different name than the cards you control, also for the rest of this turn after this card resolves, "Magnet Warrior" and "Magna Warrior" monsters you control cannot be destroyed by battle or your opponent's card effects. You can only activate 1 "Magnet Induction" per turn.
external_ids: local SETCARD_ID_0 = 0x2066 --Magnet
  
lua: local SETCARD_ID_0 = 0x2066 --Magnet
  local s, id, o = GetID()
  function s.initial_effect(c)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.cpfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetOriginalLevel() <= 4
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cpfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.cfilter2(c, code)
  	return c:IsFaceup() and c:IsCode(code)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsLevelBelow(4)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and not Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_ONFIELD, 0, 1, nil, c:GetCode())
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		--change damage
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetTargetRange(LOCATION_MZONE, 0)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		e1:SetTarget(s.indtg)
  		e1:SetValue(1)
  		Duel.RegisterEffect(e1, tp)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  		e2:SetValue(aux.indoval)
  		Duel.RegisterEffect(e2, tp)
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.indtg(e, c)
  	return c:IsType(TYPE_MONSTER) and (c:IsSetCard(SETCARD_ID_0) or c:IsSetCard(0xe9)) and c:IsFaceup()
  end
  
  
source_text: Magnet
  If you control a "Magnet Warrior" monster whose original Level is 4 or lower: Special Summon 1 Level 4 or lower "Magnet Warrior" monster from your Deck with a different name than the cards you control, also for the rest of this turn after this card resolves, "Magnet Warrior" and "Magna Warrior" monsters you control cannot be destroyed by battle or your opponent's card effects. You can only activate 1 "Magnet Induction" per turn.
target_text: -- Magnet
  local SETCARD_ID_0 = 0x2066 --Magnet
  local s, id, o = GetID()
  function s.initial_effect(c)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.cpfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetOriginalLevel() <= 4
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cpfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.cfilter2(c, code)
  	return c:IsFaceup() and c:IsCode(code)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsLevelBelow(4)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and not Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_ONFIELD, 0, 1, nil, c:GetCode())
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		--change damage
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetTargetRange(LOCATION_MZONE, 0)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		e1:SetTarget(s.indtg)
  		e1:SetValue(1)
  		Duel.RegisterEffect(e1, tp)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  		e2:SetValue(aux.indoval)
  		Duel.RegisterEffect(e2, tp)
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.indtg(e, c)
  	return c:IsType(TYPE_MONSTER) and (c:IsSetCard(SETCARD_ID_0) or c:IsSetCard(0xe9)) and c:IsFaceup()
  end
  
  