Lazion,
Cannot be Special Summoned from the Deck. If you control no monsters, you can Normal Summon this card without Tributing. Cannot be destroyed by battle or card effects. You take no battle damage from attacks involving this card. At the end of the Battle Phase, if this card battled: Shuffle all cards from your opponent's GY into the Deck. Once per turn, if your opponent draws a card: Inflict 1000 damage to your opponent. Once per turn, during your Standby Phase: Shuffle this card into the Deck.
local s, id, o = GetID()
function s.initial_effect(c)
	--cannot special summon
	local e1 = Effect.CreateEffect(c)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE + EFFECT_FLAG_SINGLE_RANGE)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetRange(LOCATION_DECK)
	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
	c:RegisterEffect(e1)
	--summon
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_SUMMON_PROC)
	e2:SetCondition(s.ntcon)
	c:RegisterEffect(e2)
	--indes
	local e3 = Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_SINGLE)
	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e3:SetRange(LOCATION_MZONE)
	e3:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e3:SetValue(1)
	c:RegisterEffect(e3)
	local e4 = e3:Clone()
	e4:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
	c:RegisterEffect(e4)
	local e5 = e3:Clone()
	e5:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
	c:RegisterEffect(e5)
	--to deck
	local e6 = Effect.CreateEffect(c)
	e6:SetDescription(aux.Stringid(id, 1))
	e6:SetCategory(CATEGORY_TODECK)
	e6:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e6:SetCode(EVENT_PHASE + PHASE_BATTLE)
	e6:SetCountLimit(1)
	e6:SetRange(LOCATION_MZONE)
	e6:SetCondition(s.tdcon)
	e6:SetTarget(s.tdtg)
	e6:SetOperation(s.tdop)
	c:RegisterEffect(e6)
	--damage
	local e7 = Effect.CreateEffect(c)
	e7:SetDescription(aux.Stringid(id, 2))
	e7:SetCategory(CATEGORY_DAMAGE)
	e7:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e7:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e7:SetCode(EVENT_DRAW)
	e7:SetCountLimit(1)
	e7:SetRange(LOCATION_MZONE)
	e7:SetCondition(s.damcon)
	e7:SetTarget(s.damtg)
	e7:SetOperation(s.damop)
	c:RegisterEffect(e7)
	--to deck
	local e8 = Effect.CreateEffect(c)
	e8:SetDescription(aux.Stringid(id, 3))
	e8:SetCategory(CATEGORY_TODECK)
	e8:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e8:SetCode(EVENT_PHASE + PHASE_STANDBY)
	e8:SetCountLimit(1)
	e8:SetRange(LOCATION_MZONE)
	e8:SetCondition(s.rtdcon)
	e8:SetTarget(s.rtdtg)
	e8:SetOperation(s.rtdop)
	c:RegisterEffect(e8)
end
function s.ntcon(e, c, minc)
	if c == nil then
		return true
	end
	return minc == 0 and c:IsLevelAbove(5) and Duel.GetFieldGroupCount(c:GetControler(), LOCATION_MZONE, 0) == 0 and Duel.GetLocationCount(c:GetControler(), LOCATION_MZONE) > 0
end
function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetBattledGroupCount() > 0
end
function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, nil)
	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
end
function s.tdop(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, nil)
	if aux.NecroValleyNegateCheck(g) then
		return
	end
	if g:GetCount() > 0 then
		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
	end
end
function s.damcon(e, tp, eg, ep, ev, re, r, rp)
	return ep ~= tp
end
function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetTargetPlayer(1 - tp)
	Duel.SetTargetParam(1000)
	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, 1000)
end
function s.damop(e, tp, eg, ep, ev, re, r, rp)
	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
	Duel.Damage(p, d, REASON_EFFECT)
end
function s.rtdcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetTurnPlayer() == tp
end
function s.rtdtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_TODECK, e:GetHandler(), 1, 0, 0)
end
function s.rtdop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) then
		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
	end
end


Lazion,
Cannot be Special Summoned from the Deck. If you control no monsters, you can Normal Summon this card without Tributing. Cannot be destroyed by battle or card effects. You take no battle damage from attacks involving this card. At the end of the Battle Phase, if this card battled: Shuffle all cards from your opponent's GY into the Deck. Once per turn, if your opponent draws a card: Inflict 1000 damage to your opponent. Once per turn, during your Standby Phase: Shuffle this card into the Deck.
-- Lazion,
local s, id, o = GetID()
function s.initial_effect(c)
	--cannot special summon
	local e1 = Effect.CreateEffect(c)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE + EFFECT_FLAG_SINGLE_RANGE)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetRange(LOCATION_DECK)
	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
	c:RegisterEffect(e1)
	--summon
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_SUMMON_PROC)
	e2:SetCondition(s.ntcon)
	c:RegisterEffect(e2)
	--indes
	local e3 = Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_SINGLE)
	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e3:SetRange(LOCATION_MZONE)
	e3:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e3:SetValue(1)
	c:RegisterEffect(e3)
	local e4 = e3:Clone()
	e4:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
	c:RegisterEffect(e4)
	local e5 = e3:Clone()
	e5:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
	c:RegisterEffect(e5)
	--to deck
	local e6 = Effect.CreateEffect(c)
	e6:SetDescription(aux.Stringid(id, 1))
	e6:SetCategory(CATEGORY_TODECK)
	e6:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e6:SetCode(EVENT_PHASE + PHASE_BATTLE)
	e6:SetCountLimit(1)
	e6:SetRange(LOCATION_MZONE)
	e6:SetCondition(s.tdcon)
	e6:SetTarget(s.tdtg)
	e6:SetOperation(s.tdop)
	c:RegisterEffect(e6)
	--damage
	local e7 = Effect.CreateEffect(c)
	e7:SetDescription(aux.Stringid(id, 2))
	e7:SetCategory(CATEGORY_DAMAGE)
	e7:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e7:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e7:SetCode(EVENT_DRAW)
	e7:SetCountLimit(1)
	e7:SetRange(LOCATION_MZONE)
	e7:SetCondition(s.damcon)
	e7:SetTarget(s.damtg)
	e7:SetOperation(s.damop)
	c:RegisterEffect(e7)
	--to deck
	local e8 = Effect.CreateEffect(c)
	e8:SetDescription(aux.Stringid(id, 3))
	e8:SetCategory(CATEGORY_TODECK)
	e8:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e8:SetCode(EVENT_PHASE + PHASE_STANDBY)
	e8:SetCountLimit(1)
	e8:SetRange(LOCATION_MZONE)
	e8:SetCondition(s.rtdcon)
	e8:SetTarget(s.rtdtg)
	e8:SetOperation(s.rtdop)
	c:RegisterEffect(e8)
end
function s.ntcon(e, c, minc)
	if c == nil then
		return true
	end
	return minc == 0 and c:IsLevelAbove(5) and Duel.GetFieldGroupCount(c:GetControler(), LOCATION_MZONE, 0) == 0 and Duel.GetLocationCount(c:GetControler(), LOCATION_MZONE) > 0
end
function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetBattledGroupCount() > 0
end
function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, nil)
	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
end
function s.tdop(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, nil)
	if aux.NecroValleyNegateCheck(g) then
		return
	end
	if g:GetCount() > 0 then
		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
	end
end
function s.damcon(e, tp, eg, ep, ev, re, r, rp)
	return ep ~= tp
end
function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetTargetPlayer(1 - tp)
	Duel.SetTargetParam(1000)
	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, 1000)
end
function s.damop(e, tp, eg, ep, ev, re, r, rp)
	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
	Duel.Damage(p, d, REASON_EFFECT)
end
function s.rtdcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetTurnPlayer() == tp
end
function s.rtdtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_TODECK, e:GetHandler(), 1, 0, 0)
end
function s.rtdop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) then
		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
	end
end

