Primineral
You can Set this card from your hand to your Spell & Trap Zone as a Spell. During the End Phase, if this card is in the GY because it was destroyed by an opponent's card effect this turn while it was Set on your field: You can Special Summon this card, then you can add 1 monster from your GY to your hand, except "Primineral Mandstrong". You can only use this effect of "Primineral Mandstrong" once per turn.
local s, id, o = GetID()
function s.initial_effect(c)
	--set
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetCode(EFFECT_MONSTER_SSET)
	e1:SetValue(TYPE_SPELL)
	c:RegisterEffect(e1)
	--spsummon
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCondition(s.regcon)
	e2:SetOperation(s.regop)
	c:RegisterEffect(e2)
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 0))
	e3:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND + CATEGORY_GRAVE_ACTION)
	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
	e3:SetCode(EVENT_PHASE + PHASE_END)
	e3:SetRange(LOCATION_GRAVE)
	e3:SetCountLimit(1, id)
	e3:SetCondition(s.spcon)
	e3:SetTarget(s.sptg)
	e3:SetOperation(s.spop)
	c:RegisterEffect(e3)
end
function s.regcon(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	return c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEDOWN) and c:IsReason(REASON_DESTROY) and c:IsReason(REASON_EFFECT) and c:IsPreviousControler(tp) and rp == 1 - tp
end
function s.regop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetFlagEffect(id) > 0
end
function s.sptg(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.cfilter(c)
	return c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and not c:IsCode(id)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if
		c:IsRelateToEffect(e)
		and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0
		and Duel.IsExistingMatchingCard(aux.NecroValleyFilter(s.cfilter), tp, LOCATION_GRAVE, 0, 1, nil)
		and Duel.SelectYesNo(tp, aux.Stringid(id, 1))
	then
		Duel.BreakEffect()
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.cfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil)
		Duel.SendtoHand(g, nil, REASON_EFFECT)
		Duel.ConfirmCards(1 - tp, g)
	end
end


Primineral
You can Set this card from your hand to your Spell & Trap Zone as a Spell. During the End Phase, if this card is in the GY because it was destroyed by an opponent's card effect this turn while it was Set on your field: You can Special Summon this card, then you can add 1 monster from your GY to your hand, except "Primineral Mandstrong". You can only use this effect of "Primineral Mandstrong" once per turn.
-- Primineral
local s, id, o = GetID()
function s.initial_effect(c)
	--set
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetCode(EFFECT_MONSTER_SSET)
	e1:SetValue(TYPE_SPELL)
	c:RegisterEffect(e1)
	--spsummon
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCondition(s.regcon)
	e2:SetOperation(s.regop)
	c:RegisterEffect(e2)
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 0))
	e3:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND + CATEGORY_GRAVE_ACTION)
	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
	e3:SetCode(EVENT_PHASE + PHASE_END)
	e3:SetRange(LOCATION_GRAVE)
	e3:SetCountLimit(1, id)
	e3:SetCondition(s.spcon)
	e3:SetTarget(s.sptg)
	e3:SetOperation(s.spop)
	c:RegisterEffect(e3)
end
function s.regcon(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	return c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEDOWN) and c:IsReason(REASON_DESTROY) and c:IsReason(REASON_EFFECT) and c:IsPreviousControler(tp) and rp == 1 - tp
end
function s.regop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return e:GetHandler():GetFlagEffect(id) > 0
end
function s.sptg(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.cfilter(c)
	return c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and not c:IsCode(id)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if
		c:IsRelateToEffect(e)
		and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0
		and Duel.IsExistingMatchingCard(aux.NecroValleyFilter(s.cfilter), tp, LOCATION_GRAVE, 0, 1, nil)
		and Duel.SelectYesNo(tp, aux.Stringid(id, 1))
	then
		Duel.BreakEffect()
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.cfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil)
		Duel.SendtoHand(g, nil, REASON_EFFECT)
		Duel.ConfirmCards(1 - tp, g)
	end
end

