name: Artifact
card_text: You can Set this card from your hand to your Spell & Trap Zone as a Spell Card. During your opponent's turn, if this Set card in the Spell & Trap Zone is destroyed and sent to your Graveyard: Special Summon it. During either player's turn, when a card or effect is activated that would destroy a Spell/Trap Card(s) you control, while this card is in your hand: You can return 1 Set Spell/Trap Card you control to the hand; Special Summon this card.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MONSTER_SSET)
  	e1:SetValue(TYPE_SPELL)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_HAND)
  	e3:SetCondition(s.spcon2)
  	e3:SetCost(s.spcost)
  	e3:SetTarget(s.sptg2)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_SZONE) and c:IsPreviousPosition(POS_FACEDOWN) and c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and Duel.GetTurnPlayer() ~= tp
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  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, false, false, POS_FACEUP)
  end
  function s.cfilter(c, tp)
  	return c:IsOnField() and c:IsControler(tp) and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local ex, tg, tc = Duel.GetOperationInfo(ev, CATEGORY_DESTROY)
  	return ex and tg ~= nil and tc + tg:FilterCount(s.cfilter, nil, tp) - tg:GetCount() > 0
  end
  function s.filter(c)
  	return c:IsFacedown() and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHandAsCost()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_SZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_SZONE, 0, 1, 1, nil)
  	Duel.SendtoHand(g, nil, REASON_COST)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  
  
source_text: Artifact
  You can Set this card from your hand to your Spell & Trap Zone as a Spell Card. During your opponent's turn, if this Set card in the Spell & Trap Zone is destroyed and sent to your Graveyard: Special Summon it. During either player's turn, when a card or effect is activated that would destroy a Spell/Trap Card(s) you control, while this card is in your hand: You can return 1 Set Spell/Trap Card you control to the hand; Special Summon this card.
target_text: -- Artifact
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MONSTER_SSET)
  	e1:SetValue(TYPE_SPELL)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_HAND)
  	e3:SetCondition(s.spcon2)
  	e3:SetCost(s.spcost)
  	e3:SetTarget(s.sptg2)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_SZONE) and c:IsPreviousPosition(POS_FACEDOWN) and c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and Duel.GetTurnPlayer() ~= tp
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  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, false, false, POS_FACEUP)
  end
  function s.cfilter(c, tp)
  	return c:IsOnField() and c:IsControler(tp) and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local ex, tg, tc = Duel.GetOperationInfo(ev, CATEGORY_DESTROY)
  	return ex and tg ~= nil and tc + tg:FilterCount(s.cfilter, nil, tp) - tg:GetCount() > 0
  end
  function s.filter(c)
  	return c:IsFacedown() and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHandAsCost()
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_SZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_SZONE, 0, 1, 1, nil)
  	Duel.SendtoHand(g, nil, REASON_COST)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  
  