name: Wightlord
card_text: This card's name becomes "Skull Servant" while in the GY. You can only use each of the following effects of "Wightlord" once per turn. If you have "Skull Servant" or "King of the Skull Servants" in your GY: You can send this card from your hand or field to the GY; send cards from the top of your Deck to the GY, up to the number of "Skull Servant" and "King of the Skull Servants" in your GY. You can banish this card from your GY, then target 1 "Skull Servant" or "King of the Skull Servants" in your GY; Special Summon it.
external_ids: local CARD_ID_0 = 36021814 --King of the Skull Servants
  local CARD_ID_1 = 32274490 --Skull Servant
  
lua: local CARD_ID_0 = 36021814 --King of the Skull Servants
  local CARD_ID_1 = 32274490 --Skull Servant
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_1, LOCATION_GRAVE)
  	--to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND + LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.tgcon)
  	e1:SetCost(s.tgcost)
  	e1:SetTarget(s.tgtg)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  end
  function s.tgcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(c, REASON_COST)
  end
  function s.tgfilter(c)
  	return c:IsCode(CARD_ID_1, CARD_ID_0)
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 0 and Duel.IsPlayerCanDiscardDeck(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local max = math.min(Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0), Duel.GetMatchingGroupCount(s.tgfilter, tp, LOCATION_GRAVE, 0, nil))
  	if max == 0 then
  		return
  	end
  	local t = {}
  	for i = 1, max do
  		t[i] = max - i + 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local announce = Duel.AnnounceNumber(tp, table.unpack(t))
  	Duel.DiscardDeck(tp, announce, REASON_EFFECT)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_1, CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(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)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler(), 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)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Wightlord
  This card's name becomes "Skull Servant" while in the GY. You can only use each of the following effects of "Wightlord" once per turn. If you have "Skull Servant" or "King of the Skull Servants" in your GY: You can send this card from your hand or field to the GY; send cards from the top of your Deck to the GY, up to the number of "Skull Servant" and "King of the Skull Servants" in your GY. You can banish this card from your GY, then target 1 "Skull Servant" or "King of the Skull Servants" in your GY; Special Summon it.
target_text: -- Wightlord
  local CARD_ID_0 = 36021814 --King of the Skull Servants
  local CARD_ID_1 = 32274490 --Skull Servant
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_1, LOCATION_GRAVE)
  	--to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND + LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.tgcon)
  	e1:SetCost(s.tgcost)
  	e1:SetTarget(s.tgtg)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  end
  function s.tgcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(c, REASON_COST)
  end
  function s.tgfilter(c)
  	return c:IsCode(CARD_ID_1, CARD_ID_0)
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 0 and Duel.IsPlayerCanDiscardDeck(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local max = math.min(Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0), Duel.GetMatchingGroupCount(s.tgfilter, tp, LOCATION_GRAVE, 0, nil))
  	if max == 0 then
  		return
  	end
  	local t = {}
  	for i = 1, max do
  		t[i] = max - i + 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local announce = Duel.AnnounceNumber(tp, table.unpack(t))
  	Duel.DiscardDeck(tp, announce, REASON_EFFECT)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_1, CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(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)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler(), 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)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  