name: Jack-o-Bolan
card_text: You can discard 1 Zombie monster; Special Summon this card from your hand. During your opponent's Main Phase (Quick Effect): You can target 1 Zombie monster in either GY; Special Summon that monster (but banish it when it leaves the field), then banish this face-up card until the End Phase. You can only use each effect of "Jack-o-Bolan" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon1
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost1)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--spsummon2
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_REMOVE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.spfilter1(c)
  	return c:IsRace(RACE_ZOMBIE) and c:IsDiscardable()
  end
  function s.spcost1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter1, tp, LOCATION_HAND, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter1, tp, LOCATION_HAND, 0, 1, 1, c)
  	Duel.SendtoGrave(g, REASON_COST + REASON_DISCARD)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.spfilter2(c, e, tp)
  	return c:IsRace(RACE_ZOMBIE) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp and (Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.spfilter2(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter2, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, e, tp) and c:IsAbleToRemove()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter2, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, c, 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		tc:RegisterEffect(e1, true)
  		if c:IsFaceup() and c:IsRelateToEffect(e) and c:IsAbleToRemove() then
  			Duel.BreakEffect()
  			if Duel.Remove(c, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 and c:GetOriginalCode() == id then
  				local e2 = Effect.CreateEffect(c)
  				e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  				e2:SetCode(EVENT_PHASE + PHASE_END)
  				e2:SetReset(RESET_PHASE + PHASE_END)
  				e2:SetLabelObject(tc)
  				e2:SetCountLimit(1)
  				e2:SetOperation(s.retop)
  				Duel.RegisterEffect(e2, tp)
  			end
  		end
  	end
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ReturnToField(e:GetHandler())
  end
  
  
source_text: Jack-o-Bolan
  You can discard 1 Zombie monster; Special Summon this card from your hand. During your opponent's Main Phase (Quick Effect): You can target 1 Zombie monster in either GY; Special Summon that monster (but banish it when it leaves the field), then banish this face-up card until the End Phase. You can only use each effect of "Jack-o-Bolan" once per turn.
target_text: -- Jack-o-Bolan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon1
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost1)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--spsummon2
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_REMOVE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.spfilter1(c)
  	return c:IsRace(RACE_ZOMBIE) and c:IsDiscardable()
  end
  function s.spcost1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter1, tp, LOCATION_HAND, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter1, tp, LOCATION_HAND, 0, 1, 1, c)
  	Duel.SendtoGrave(g, REASON_COST + REASON_DISCARD)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.spfilter2(c, e, tp)
  	return c:IsRace(RACE_ZOMBIE) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp and (Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.spfilter2(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter2, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, e, tp) and c:IsAbleToRemove()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter2, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, c, 1, 0, 0)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		tc:RegisterEffect(e1, true)
  		if c:IsFaceup() and c:IsRelateToEffect(e) and c:IsAbleToRemove() then
  			Duel.BreakEffect()
  			if Duel.Remove(c, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 and c:GetOriginalCode() == id then
  				local e2 = Effect.CreateEffect(c)
  				e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  				e2:SetCode(EVENT_PHASE + PHASE_END)
  				e2:SetReset(RESET_PHASE + PHASE_END)
  				e2:SetLabelObject(tc)
  				e2:SetCountLimit(1)
  				e2:SetOperation(s.retop)
  				Duel.RegisterEffect(e2, tp)
  			end
  		end
  	end
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ReturnToField(e:GetHandler())
  end
  
  