name: Disenchanter
card_text: Once per turn: You can target 1 face-up Spell on the field; remove 1 Spell Counter from anywhere on the field, and if you do, return that target to the hand.
external_ids: local COUNTER_ID_0 = 0x1 --Spell
  
lua: local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsType(TYPE_SPELL) and c:IsFaceup() and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 1, REASON_EFFECT) and Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 1, REASON_EFFECT) then
  		Duel.RemoveCounter(tp, 1, 1, COUNTER_ID_0, 1, REASON_EFFECT)
  		local tc = Duel.GetFirstTarget()
  		if tc:IsRelateToEffect(e) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Disenchanter
  Once per turn: You can target 1 face-up Spell on the field; remove 1 Spell Counter from anywhere on the field, and if you do, return that target to the hand.
target_text: -- Disenchanter
  local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsType(TYPE_SPELL) and c:IsFaceup() and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 1, REASON_EFFECT) and Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 1, REASON_EFFECT) then
  		Duel.RemoveCounter(tp, 1, 1, COUNTER_ID_0, 1, REASON_EFFECT)
  		local tc = Duel.GetFirstTarget()
  		if tc:IsRelateToEffect(e) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		end
  	end
  end
  
  