name: Blackbeard,
card_text: 2 monsters including a "Plunder Patroll" monster
  (Quick Effect): You can target 1 Effect Monster you control; Special Summon 1 "Plunder Patroll" monster from your Extra Deck with the same Attribute as a monster your opponent controls or is in their GY, and if you do, equip that target to it, then draw 1 card. You can only use this effect of "Blackbeard, the Plunder Patroll Captain" once per turn.
external_ids: local SETCARD_ID_0 = 0x13f --Plunder
  
lua: local SETCARD_ID_0 = 0x13f --Plunder
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_EQUIP + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.lcheck(g)
  	return g:IsExists(Card.IsLinkSetCard, 1, nil, 0x13f)
  end
  function s.cfilter(c, e, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c:GetAttribute())
  end
  function s.spfilter(c, e, tp, attr)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAttribute(attr) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_EFFECT)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.tgfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  			and Duel.IsExistingTarget(s.tgfilter, tp, LOCATION_MZONE, 0, 1, nil)
  			and Duel.IsExistingMatchingCard(s.cfilter, tp, 0, LOCATION_MZONE + LOCATION_GRAVE, 1, nil, e, tp)
  			and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.tgfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  end
  function s.cfilter2(c)
  	return c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tgc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.cfilter2, tp, 0, LOCATION_MZONE + LOCATION_GRAVE, nil)
  	local tc = g:GetFirst()
  	local attr = 0
  	while tc do
  		attr = attr | tc:GetAttribute()
  		tc = g:GetNext()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, attr)
  	local sc = sg:GetFirst()
  	if sc and Duel.SpecialSummon(sc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 and sc:IsFaceup() and tgc:IsRelateToEffect(e) and tgc:IsControler(tp) and tgc:IsFaceup() and tgc:IsType(TYPE_EFFECT) then
  		if not Duel.Equip(tp, tgc, sc, false) then
  			return
  		end
  		--equip limit
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetLabelObject(sc)
  		e1:SetValue(s.eqlimit)
  		tgc:RegisterEffect(e1)
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  
  
source_text: Blackbeard,
  2 monsters including a "Plunder Patroll" monster
  (Quick Effect): You can target 1 Effect Monster you control; Special Summon 1 "Plunder Patroll" monster from your Extra Deck with the same Attribute as a monster your opponent controls or is in their GY, and if you do, equip that target to it, then draw 1 card. You can only use this effect of "Blackbeard, the Plunder Patroll Captain" once per turn.
target_text: -- Blackbeard,
  local SETCARD_ID_0 = 0x13f --Plunder
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_EQUIP + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.lcheck(g)
  	return g:IsExists(Card.IsLinkSetCard, 1, nil, 0x13f)
  end
  function s.cfilter(c, e, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c:GetAttribute())
  end
  function s.spfilter(c, e, tp, attr)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAttribute(attr) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_EFFECT)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.tgfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  			and Duel.IsExistingTarget(s.tgfilter, tp, LOCATION_MZONE, 0, 1, nil)
  			and Duel.IsExistingMatchingCard(s.cfilter, tp, 0, LOCATION_MZONE + LOCATION_GRAVE, 1, nil, e, tp)
  			and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.tgfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  end
  function s.cfilter2(c)
  	return c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tgc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.cfilter2, tp, 0, LOCATION_MZONE + LOCATION_GRAVE, nil)
  	local tc = g:GetFirst()
  	local attr = 0
  	while tc do
  		attr = attr | tc:GetAttribute()
  		tc = g:GetNext()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, attr)
  	local sc = sg:GetFirst()
  	if sc and Duel.SpecialSummon(sc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 and sc:IsFaceup() and tgc:IsRelateToEffect(e) and tgc:IsControler(tp) and tgc:IsFaceup() and tgc:IsType(TYPE_EFFECT) then
  		if not Duel.Equip(tp, tgc, sc, false) then
  			return
  		end
  		--equip limit
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetLabelObject(sc)
  		e1:SetValue(s.eqlimit)
  		tgc:RegisterEffect(e1)
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  
  