name: SPYRAL
card_text: You can target 1 "SPYRAL" monster you control; equip this monster from your hand or field to that target. While this card is equipped to a monster by this effect, the equipped monster cannot be destroyed by battle or card effects, also your opponent cannot target it with card effects. Once per turn, if this card is equipped to a monster by this effect: You can send 1 other card you control to the Graveyard; the equipped monster can attack directly this turn.
external_ids: local SETCARD_ID_0 = 0xee --SPYRAL
  
lua: local SETCARD_ID_0 = 0xee --SPYRAL
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_HAND + LOCATION_MZONE)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  end
  function s.eqfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_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.eqfilter(chkc) and chkc ~= e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.eqfilter, tp, LOCATION_MZONE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.eqfilter, tp, LOCATION_MZONE, 0, 1, 1, e:GetHandler())
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	if c:IsLocation(LOCATION_MZONE) and c:IsFacedown() then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 or tc:IsControler(1 - tp) or tc:IsFacedown() or not tc:IsRelateToEffect(e) then
  		Duel.SendtoGrave(c, REASON_EFFECT)
  		return
  	end
  	Duel.Equip(tp, c, tc)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_EQUIP_LIMIT)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  	e1:SetValue(s.eqlimit)
  	e1:SetLabelObject(tc)
  	c:RegisterEffect(e1)
  	--destroy sub
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_EQUIP)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--cannot be targeted
  	local e4 = e2:Clone()
  	e4:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e4:SetValue(aux.tgoval)
  	c:RegisterEffect(e4)
  	--direct attack
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCountLimit(1)
  	e5:SetCondition(s.dircon)
  	e5:SetCost(s.dircost)
  	e5:SetOperation(s.dirop)
  	e5:SetReset(RESET_EVENT + RESETS_STANDARD)
  	c:RegisterEffect(e5)
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  function s.dircon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsAbleToEnterBP()
  end
  function s.cfilter(c, ec)
  	return c:IsAbleToGraveAsCost() and c ~= ec
  end
  function s.dircost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local ec = c:GetEquipTarget()
  	if chk == 0 then
  		return ec and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, c, ec)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_ONFIELD, 0, 1, 1, c, ec)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.dirop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_EQUIP)
  	e1:SetCode(EFFECT_DIRECT_ATTACK)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	c:RegisterEffect(e1)
  end
  
  
source_text: SPYRAL
  You can target 1 "SPYRAL" monster you control; equip this monster from your hand or field to that target. While this card is equipped to a monster by this effect, the equipped monster cannot be destroyed by battle or card effects, also your opponent cannot target it with card effects. Once per turn, if this card is equipped to a monster by this effect: You can send 1 other card you control to the Graveyard; the equipped monster can attack directly this turn.
target_text: -- SPYRAL
  local SETCARD_ID_0 = 0xee --SPYRAL
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_HAND + LOCATION_MZONE)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  end
  function s.eqfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_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.eqfilter(chkc) and chkc ~= e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.eqfilter, tp, LOCATION_MZONE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.eqfilter, tp, LOCATION_MZONE, 0, 1, 1, e:GetHandler())
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	if c:IsLocation(LOCATION_MZONE) and c:IsFacedown() then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 or tc:IsControler(1 - tp) or tc:IsFacedown() or not tc:IsRelateToEffect(e) then
  		Duel.SendtoGrave(c, REASON_EFFECT)
  		return
  	end
  	Duel.Equip(tp, c, tc)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_EQUIP_LIMIT)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  	e1:SetValue(s.eqlimit)
  	e1:SetLabelObject(tc)
  	c:RegisterEffect(e1)
  	--destroy sub
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_EQUIP)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--cannot be targeted
  	local e4 = e2:Clone()
  	e4:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e4:SetValue(aux.tgoval)
  	c:RegisterEffect(e4)
  	--direct attack
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCountLimit(1)
  	e5:SetCondition(s.dircon)
  	e5:SetCost(s.dircost)
  	e5:SetOperation(s.dirop)
  	e5:SetReset(RESET_EVENT + RESETS_STANDARD)
  	c:RegisterEffect(e5)
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  function s.dircon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsAbleToEnterBP()
  end
  function s.cfilter(c, ec)
  	return c:IsAbleToGraveAsCost() and c ~= ec
  end
  function s.dircost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local ec = c:GetEquipTarget()
  	if chk == 0 then
  		return ec and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, c, ec)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_ONFIELD, 0, 1, 1, c, ec)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.dirop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_EQUIP)
  	e1:SetCode(EFFECT_DIRECT_ATTACK)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	c:RegisterEffect(e1)
  end
  
  