name: Magical
card_text: During either player's turn, you can activate "Magical Musket" Spell/Trap Cards from your hand. If a Spell/Trap Card is activated in this card's column: You can add 1 "Magical Musket" card from your GY to your hand, but not a card with the same name as that activated card. You can only use this effect of "Magical Musketeer Doc" once per turn.
external_ids: local SETCARD_ID_0 = 0x108 --Magical
  
lua: local SETCARD_ID_0 = 0x108 --Magical
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate from hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e1:SetTargetRange(LOCATION_HAND, 0)
  	e1:SetValue(32841045)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	c:RegisterEffect(e2)
  	--tohand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE) and e:GetHandler():GetColumnGroup():IsContains(re:GetHandler())
  end
  function s.thfilter(c, rc)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(rc:GetCode()) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local rc = re:GetHandler()
  	if chk == 0 then
  		return rc and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil, rc)
  	end
  	e:SetLabelObject(rc)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e:GetLabelObject())
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Magical
  During either player's turn, you can activate "Magical Musket" Spell/Trap Cards from your hand. If a Spell/Trap Card is activated in this card's column: You can add 1 "Magical Musket" card from your GY to your hand, but not a card with the same name as that activated card. You can only use this effect of "Magical Musketeer Doc" once per turn.
target_text: -- Magical
  local SETCARD_ID_0 = 0x108 --Magical
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate from hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e1:SetTargetRange(LOCATION_HAND, 0)
  	e1:SetValue(32841045)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	c:RegisterEffect(e2)
  	--tohand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE) and e:GetHandler():GetColumnGroup():IsContains(re:GetHandler())
  end
  function s.thfilter(c, rc)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(rc:GetCode()) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local rc = re:GetHandler()
  	if chk == 0 then
  		return rc and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil, rc)
  	end
  	e:SetLabelObject(rc)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e:GetLabelObject())
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  