Defender,
If this card is Normal Summoned: Place 1 Spell Counter on it (max. 1). Once per turn, if a Spellcaster monster(s) on the field would be destroyed, you can remove 1 Spell Counter from your field for each of those monsters instead.
local COUNTER_ID_0 = 0x1 --Spell

local COUNTER_ID_0 = 0x1 --Spell
local s, id, o = GetID()
function s.initial_effect(c)
	c:EnableCounterPermit(0x1)
	c:SetCounterLimit(0x1, 1)
	--summon success
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_COUNTER)
	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetTarget(s.addct)
	e1:SetOperation(s.addc)
	c:RegisterEffect(e1)
	--destroy replace
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_DESTROY_REPLACE)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1)
	e2:SetTarget(s.destg)
	e2:SetValue(s.value)
	e2:SetOperation(s.desop)
	c:RegisterEffect(e2)
end
function s.addct(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 1, 0, 0x1)
end
function s.addc(e, tp, eg, ep, ev, re, r, rp)
	if e:GetHandler():IsRelateToEffect(e) then
		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
	end
end
function s.dfilter(c)
	return c:IsLocation(LOCATION_MZONE) and c:IsFaceup() and c:IsRace(RACE_SPELLCASTER) and c:IsReason(REASON_EFFECT + REASON_BATTLE) and not c:IsReason(REASON_REPLACE)
end
function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		local count = eg:FilterCount(s.dfilter, nil)
		e:SetLabel(count)
		return count > 0 and Duel.IsCanRemoveCounter(tp, 1, 0, COUNTER_ID_0, count, REASON_COST)
	end
	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
end
function s.value(e, c)
	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsRace(RACE_SPELLCASTER)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local count = e:GetLabel()
	Duel.RemoveCounter(tp, 1, 0, COUNTER_ID_0, count, REASON_COST)
end


Defender,
If this card is Normal Summoned: Place 1 Spell Counter on it (max. 1). Once per turn, if a Spellcaster monster(s) on the field would be destroyed, you can remove 1 Spell Counter from your field for each of those monsters instead.
-- Defender,
local COUNTER_ID_0 = 0x1 --Spell
local s, id, o = GetID()
function s.initial_effect(c)
	c:EnableCounterPermit(0x1)
	c:SetCounterLimit(0x1, 1)
	--summon success
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetCategory(CATEGORY_COUNTER)
	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetTarget(s.addct)
	e1:SetOperation(s.addc)
	c:RegisterEffect(e1)
	--destroy replace
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_DESTROY_REPLACE)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1)
	e2:SetTarget(s.destg)
	e2:SetValue(s.value)
	e2:SetOperation(s.desop)
	c:RegisterEffect(e2)
end
function s.addct(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 1, 0, 0x1)
end
function s.addc(e, tp, eg, ep, ev, re, r, rp)
	if e:GetHandler():IsRelateToEffect(e) then
		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
	end
end
function s.dfilter(c)
	return c:IsLocation(LOCATION_MZONE) and c:IsFaceup() and c:IsRace(RACE_SPELLCASTER) and c:IsReason(REASON_EFFECT + REASON_BATTLE) and not c:IsReason(REASON_REPLACE)
end
function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		local count = eg:FilterCount(s.dfilter, nil)
		e:SetLabel(count)
		return count > 0 and Duel.IsCanRemoveCounter(tp, 1, 0, COUNTER_ID_0, count, REASON_COST)
	end
	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
end
function s.value(e, c)
	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsRace(RACE_SPELLCASTER)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local count = e:GetLabel()
	Duel.RemoveCounter(tp, 1, 0, COUNTER_ID_0, count, REASON_COST)
end

