name: Borrel
card_text: Activate this card by targeting 1 "Rokket" monster in your GY; Special Summon it and equip it with this card, but banish it when this card leaves the field. If this card is sent to the GY because the equipped monster is destroyed: You can draw 1 card. You can only use each effect of "Borrel Regenerator" once per turn.
external_ids: local SETCARD_ID_0 = 0x102 --Rokket
  
lua: local SETCARD_ID_0 = 0x102 --Rokket
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_LEAVE_FIELD_P)
  	e2:SetOperation(s.checkop)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetOperation(s.rmop)
  	e3:SetLabelObject(e2)
  	c:RegisterEffect(e3)
  	--draw
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_DRAW)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetProperty(EFFECT_FLAG_DELAY)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetCountLimit(1, id + 1)
  	e4:SetCondition(s.drcon)
  	e4:SetTarget(s.drtg)
  	e4:SetOperation(s.drop)
  	c:RegisterEffect(e4)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	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 Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  		Duel.Equip(tp, c, tc)
  		--Add Equip limit
  		local e1 = Effect.CreateEffect(tc)
  		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)
  		c:RegisterEffect(e1)
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsDisabled() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	if c:IsReason(REASON_DESTROY) and tc and tc:IsLocation(LOCATION_MZONE) then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	return ec and c:IsReason(REASON_LOST_TARGET) and ec:IsReason(REASON_DESTROY)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  
  
source_text: Borrel
  Activate this card by targeting 1 "Rokket" monster in your GY; Special Summon it and equip it with this card, but banish it when this card leaves the field. If this card is sent to the GY because the equipped monster is destroyed: You can draw 1 card. You can only use each effect of "Borrel Regenerator" once per turn.
target_text: -- Borrel
  local SETCARD_ID_0 = 0x102 --Rokket
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_LEAVE_FIELD_P)
  	e2:SetOperation(s.checkop)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetOperation(s.rmop)
  	e3:SetLabelObject(e2)
  	c:RegisterEffect(e3)
  	--draw
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_DRAW)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetProperty(EFFECT_FLAG_DELAY)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetCountLimit(1, id + 1)
  	e4:SetCondition(s.drcon)
  	e4:SetTarget(s.drtg)
  	e4:SetOperation(s.drop)
  	c:RegisterEffect(e4)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	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 Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  		Duel.Equip(tp, c, tc)
  		--Add Equip limit
  		local e1 = Effect.CreateEffect(tc)
  		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)
  		c:RegisterEffect(e1)
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsDisabled() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	if c:IsReason(REASON_DESTROY) and tc and tc:IsLocation(LOCATION_MZONE) then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ec = c:GetPreviousEquipTarget()
  	return ec and c:IsReason(REASON_LOST_TARGET) and ec:IsReason(REASON_DESTROY)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  
  