name: Artifact
card_text: 2 monsters with different names
  When an effect of another card on the field is activated (Quick Effect): You can Set 1 "Artifact" monster from your hand or Deck to your Spell & Trap Zone as a Spell, but destroy it during your opponent's next End Phase. During your opponent's turn, if this Link Summoned card is destroyed: You can Special Summon 1 "Artifact" monster from your GY in Defense Position. You can only use each effect of "Artifact Dagda" once per turn.
external_ids: local SETCARD_ID_0 = 0x97 --Artifact
  
lua: local SETCARD_ID_0 = 0x97 --Artifact
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.stcon)
  	e1:SetTarget(s.sttg)
  	e1:SetOperation(s.stop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.stcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_LOCATION), LOCATION_ONFIELD) ~= 0 and re:GetHandler() ~= e:GetHandler()
  end
  function s.stfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsSSetable()
  end
  function s.sttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.stfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.stop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.stfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		local ct = Duel.SSet(tp, g)
  		if ct ~= 0 then
  			local tc = g:GetFirst()
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetCountLimit(1)
  			e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  			e1:SetLabelObject(tc)
  			e1:SetCondition(s.descon)
  			e1:SetOperation(s.desop)
  			if Duel.GetTurnPlayer() == 1 - tp and Duel.GetCurrentPhase() == PHASE_END then
  				e1:SetReset(RESET_PHASE + PHASE_END + RESET_OPPO_TURN, 2)
  				e1:SetValue(Duel.GetTurnCount())
  				tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END + RESET_OPPO_TURN, 0, 2)
  			else
  				e1:SetReset(RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
  				e1:SetValue(0)
  				tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END + RESET_OPPO_TURN, 0, 1)
  			end
  			Duel.RegisterEffect(e1, tp)
  		end
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetTurnPlayer() ~= 1 - tp or Duel.GetTurnCount() == e:GetValue() then
  		return false
  	end
  	return e:GetLabelObject():GetFlagEffect(id) ~= 0
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetLabelObject(), REASON_EFFECT)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return Duel.GetTurnPlayer() == 1 - tp and c:IsSummonType(SUMMON_TYPE_LINK) and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  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_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: Artifact
  2 monsters with different names
  When an effect of another card on the field is activated (Quick Effect): You can Set 1 "Artifact" monster from your hand or Deck to your Spell & Trap Zone as a Spell, but destroy it during your opponent's next End Phase. During your opponent's turn, if this Link Summoned card is destroyed: You can Special Summon 1 "Artifact" monster from your GY in Defense Position. You can only use each effect of "Artifact Dagda" once per turn.
target_text: -- Artifact
  local SETCARD_ID_0 = 0x97 --Artifact
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.stcon)
  	e1:SetTarget(s.sttg)
  	e1:SetOperation(s.stop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.stcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_LOCATION), LOCATION_ONFIELD) ~= 0 and re:GetHandler() ~= e:GetHandler()
  end
  function s.stfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsSSetable()
  end
  function s.sttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.stfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.stop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.stfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		local ct = Duel.SSet(tp, g)
  		if ct ~= 0 then
  			local tc = g:GetFirst()
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetCountLimit(1)
  			e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  			e1:SetLabelObject(tc)
  			e1:SetCondition(s.descon)
  			e1:SetOperation(s.desop)
  			if Duel.GetTurnPlayer() == 1 - tp and Duel.GetCurrentPhase() == PHASE_END then
  				e1:SetReset(RESET_PHASE + PHASE_END + RESET_OPPO_TURN, 2)
  				e1:SetValue(Duel.GetTurnCount())
  				tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END + RESET_OPPO_TURN, 0, 2)
  			else
  				e1:SetReset(RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
  				e1:SetValue(0)
  				tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END + RESET_OPPO_TURN, 0, 1)
  			end
  			Duel.RegisterEffect(e1, tp)
  		end
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetTurnPlayer() ~= 1 - tp or Duel.GetTurnCount() == e:GetValue() then
  		return false
  	end
  	return e:GetLabelObject():GetFlagEffect(id) ~= 0
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetLabelObject(), REASON_EFFECT)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return Duel.GetTurnPlayer() == 1 - tp and c:IsSummonType(SUMMON_TYPE_LINK) and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  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_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  
  