Generate a YGOPro Lua script for the following Yu-Gi-Oh card effect:
Excavate the top 5 cards of your opponent's Deck (or as many as possible), choose 1 excavated card, and declare a number in multiples of 100 (min. 100, max. 3000). Your opponent can choose to gain LP equal to the declared number. If they gained LP, you lose that amount of LP, and if you do, add that chosen card to your hand, also place the rest on top of the Deck in the same order. If they did not, place the excavated cards on top of the Deck in the same order.
--初買い
--Hatsugai
--scripted by pyrQ
local s,id=GetID()
function s.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id,0))
	e1:SetCategory(CATEGORY_RECOVER+CATEGORY_TOHAND+CATEGORY_SEARCH)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER_E)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
end
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetFieldGroupCount(tp,0,LOCATION_DECK)>=5 end
end
local declare_lp_table={}
for i=1,30 do
	declare_lp_table[i]=i*100
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
	Duel.ConfirmDecktop(1-tp,5)
	local g=Duel.GetDecktopGroup(1-tp,5)
	if #g==0 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
	local sc=g:Select(tp,1,1,nil):GetFirst()
	Duel.ConfirmCards(1-tp,sc)
	local ac=Duel.AnnounceNumber(tp,declare_lp_table)
	if sc:IsAbleToHand() and Duel.SelectYesNo(1-tp,aux.Stringid(id,1))
		and Duel.Recover(1-tp,ac,REASON_EFFECT)>0 then
		Duel.SetLP(tp,Duel.GetLP(tp)-ac)
		Duel.DisableShuffleCheck(true)
		Duel.SendtoHand(sc,tp,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,sc)
		Duel.ShuffleHand(tp)
	end
end