name: Esper
card_text: When this removed from play card is Special Summoned, remove from play the top card of your Deck, face-down. When this card is sent from the field to the GY, add that removed card to your hand.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--remove
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.rmcon)
  	e1:SetTarget(s.rmtg)
  	e1:SetOperation(s.rmop)
  	c:RegisterEffect(e1)
  	--add to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_REMOVED)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetDecktopGroup(tp, 1)
  	local tc = g:GetFirst()
  	if not tc or not tc:IsAbleToRemove() then
  		return
  	end
  	Duel.DisableShuffleCheck()
  	Duel.Remove(tc, POS_FACEDOWN, REASON_EFFECT)
  	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  	if c:IsLocation(LOCATION_MZONE) then
  		c:RegisterFlagEffect(id, RESET_EVENT + 0x680000, 0, 1)
  	end
  	e:SetLabelObject(tc)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject():GetLabelObject()
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD) and e:GetHandler():GetFlagEffect(id) ~= 0 and tc and tc:GetFlagEffect(id) ~= 0
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local tc = e:GetLabelObject():GetLabelObject()
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, tc, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject():GetLabelObject()
  	if tc and tc:GetFlagEffect(id) ~= 0 then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Esper
  When this removed from play card is Special Summoned, remove from play the top card of your Deck, face-down. When this card is sent from the field to the GY, add that removed card to your hand.
target_text: -- Esper
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--remove
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.rmcon)
  	e1:SetTarget(s.rmtg)
  	e1:SetOperation(s.rmop)
  	c:RegisterEffect(e1)
  	--add to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_REMOVED)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetDecktopGroup(tp, 1)
  	local tc = g:GetFirst()
  	if not tc or not tc:IsAbleToRemove() then
  		return
  	end
  	Duel.DisableShuffleCheck()
  	Duel.Remove(tc, POS_FACEDOWN, REASON_EFFECT)
  	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  	if c:IsLocation(LOCATION_MZONE) then
  		c:RegisterFlagEffect(id, RESET_EVENT + 0x680000, 0, 1)
  	end
  	e:SetLabelObject(tc)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject():GetLabelObject()
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD) and e:GetHandler():GetFlagEffect(id) ~= 0 and tc and tc:GetFlagEffect(id) ~= 0
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local tc = e:GetLabelObject():GetLabelObject()
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, tc, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject():GetLabelObject()
  	if tc and tc:GetFlagEffect(id) ~= 0 then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  