name: Metal
card_text: Increase this card's Level by 4 during your opponent's turn only. You can only use each of the following effects of "Metal Illusionist" once per turn. If this card is Normal or Special Summoned: You can Set 1 "Metalmorph" Trap from your Deck, then if "Max Metalmorph" is in your GY, you can draw 1 card. You can declare 1 other Monster Type; this card becomes that Type, until the end of your opponent's turn.
external_ids: local CARD_ID_0 = 89812483 --Max Metalmorph
  local SETCARD_ID_0 = 0x1ba --Metalmorph
  
lua: local CARD_ID_0 = 89812483 --Max Metalmorph
  local SETCARD_ID_0 = 0x1ba --Metalmorph
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.settg)
  	e1:SetOperation(s.setop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--level up
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_UPDATE_LEVEL)
  	e3:SetCondition(s.lvcon)
  	e3:SetValue(4)
  	c:RegisterEffect(e3)
  	--change race
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, id + o)
  	e4:SetTarget(s.racetg)
  	e4:SetOperation(s.raceop)
  	c:RegisterEffect(e4)
  end
  function s.setfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TRAP) and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if
  		tc
  		and Duel.SSet(tp, tc) ~= 0
  		and Duel.IsExistingMatchingCard(Card.IsCode, tp, LOCATION_GRAVE, 0, 1, nil, CARD_ID_0)
  		and Duel.IsPlayerCanDraw(tp, 1)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  function s.lvcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= e:GetHandler():GetControler()
  end
  function s.racetg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RACE)
  	local race = Duel.AnnounceRace(tp, 1, RACE_ALL & ~e:GetHandler():GetRace())
  	e:SetLabel(race)
  end
  function s.raceop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local race = e:GetLabel()
  	if c:IsRelateToEffect(e) and c:IsFaceup() and bit.band(c:GetRace(), race) == 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_RACE)
  		e1:SetValue(race)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
  		c:RegisterEffect(e1)
  	end
  end
  
  
source_text: Metal
  Increase this card's Level by 4 during your opponent's turn only. You can only use each of the following effects of "Metal Illusionist" once per turn. If this card is Normal or Special Summoned: You can Set 1 "Metalmorph" Trap from your Deck, then if "Max Metalmorph" is in your GY, you can draw 1 card. You can declare 1 other Monster Type; this card becomes that Type, until the end of your opponent's turn.
target_text: -- Metal
  local CARD_ID_0 = 89812483 --Max Metalmorph
  local SETCARD_ID_0 = 0x1ba --Metalmorph
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.settg)
  	e1:SetOperation(s.setop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--level up
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_UPDATE_LEVEL)
  	e3:SetCondition(s.lvcon)
  	e3:SetValue(4)
  	c:RegisterEffect(e3)
  	--change race
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, id + o)
  	e4:SetTarget(s.racetg)
  	e4:SetOperation(s.raceop)
  	c:RegisterEffect(e4)
  end
  function s.setfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TRAP) and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if
  		tc
  		and Duel.SSet(tp, tc) ~= 0
  		and Duel.IsExistingMatchingCard(Card.IsCode, tp, LOCATION_GRAVE, 0, 1, nil, CARD_ID_0)
  		and Duel.IsPlayerCanDraw(tp, 1)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  function s.lvcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= e:GetHandler():GetControler()
  end
  function s.racetg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RACE)
  	local race = Duel.AnnounceRace(tp, 1, RACE_ALL & ~e:GetHandler():GetRace())
  	e:SetLabel(race)
  end
  function s.raceop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local race = e:GetLabel()
  	if c:IsRelateToEffect(e) and c:IsFaceup() and bit.band(c:GetRace(), race) == 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_RACE)
  		e1:SetValue(race)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
  		c:RegisterEffect(e1)
  	end
  end
  
  