name: Ribbon
card_text: During the End Phase, if the equipped monster was destroyed by battle and sent to the Graveyard this turn: Special Summon it from the Graveyard to your side of the field.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Equip limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_EQUIP_LIMIT)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetValue(s.eqlimit)
  	c:RegisterEffect(e2)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCondition(s.regcon)
  	e3:SetOperation(s.regop)
  	c:RegisterEffect(e3)
  end
  function s.eqlimit(e, c)
  	return not c:IsHasEffect(EFFECT_CANNOT_SPECIAL_SUMMON)
  end
  function s.filter(c)
  	return c:IsFaceup() and not c:IsHasEffect(EFFECT_CANNOT_SPECIAL_SUMMON)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	return c:IsReason(REASON_LOST_TARGET) and ec:IsReason(REASON_BATTLE) and ec:IsLocation(LOCATION_GRAVE)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetRange(LOCATION_GRAVE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	e1:SetLabelObject(ec)
  	e1:SetReset(RESET_EVENT + 0x16c0000 + RESET_PHASE + PHASE_END)
  	e:GetHandler():RegisterEffect(e1)
  	ec:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ec = e:GetHandler():GetPreviousEquipTarget()
  	if chk == 0 then
  		return ec:GetFlagEffect(id) ~= 0
  	end
  	Duel.SetTargetCard(ec)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, ec, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Ribbon
  During the End Phase, if the equipped monster was destroyed by battle and sent to the Graveyard this turn: Special Summon it from the Graveyard to your side of the field.
target_text: -- Ribbon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Equip limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_EQUIP_LIMIT)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetValue(s.eqlimit)
  	c:RegisterEffect(e2)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCondition(s.regcon)
  	e3:SetOperation(s.regop)
  	c:RegisterEffect(e3)
  end
  function s.eqlimit(e, c)
  	return not c:IsHasEffect(EFFECT_CANNOT_SPECIAL_SUMMON)
  end
  function s.filter(c)
  	return c:IsFaceup() and not c:IsHasEffect(EFFECT_CANNOT_SPECIAL_SUMMON)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	return c:IsReason(REASON_LOST_TARGET) and ec:IsReason(REASON_BATTLE) and ec:IsLocation(LOCATION_GRAVE)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetRange(LOCATION_GRAVE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	e1:SetLabelObject(ec)
  	e1:SetReset(RESET_EVENT + 0x16c0000 + RESET_PHASE + PHASE_END)
  	e:GetHandler():RegisterEffect(e1)
  	ec:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ec = e:GetHandler():GetPreviousEquipTarget()
  	if chk == 0 then
  		return ec:GetFlagEffect(id) ~= 0
  	end
  	Duel.SetTargetCard(ec)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, ec, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  